> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# デバイス認可

> 入力に制約のあるデバイス向けの Device Authorization Flow を開始するためのデバイスコードを取得します。

export const ResponseSchema = ({statusCode, type = "{}", children}) => {
  const [open, setOpen] = useState(false);
  return <div className="border border-gray-100 dark:border-gray-800 rounded-lg mb-3 overflow-hidden">
      <div className={`flex items-center gap-2.5 px-4 py-2.5 cursor-pointer select-none ${open ? "bg-gray-50 dark:bg-gray-800" : ""}`} onClick={() => setOpen(!open)}>
        {statusCode && <span className="border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 font-mono text-xs px-1.5 py-0.5 rounded">
            {statusCode.startsWith("default") ? "default" : statusCode}
          </span>}
        <span className="text-gray-500 dark:text-gray-400 text-sm font-mono">
          {type}
        </span>
        <span className="text-gray-400 dark:text-gray-500 text-sm italic">
          application/json
        </span>
        <svg className={`ml-auto opacity-50 transition-transform duration-200 ${open ? "rotate-180" : ""}`} width="16" height="16" viewBox="0 0 16 16" fill="none">
          <path d="M4 6l4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </div>
      {open && <div className="px-4 pt-1 pb-3 border-t border-gray-100 dark:border-gray-800">
          {children}
        </div>}
    </div>;
};

<div id="endpoint">
  ## エンドポイント
</div>

`POST /oauth/device/code`

このフローは、入力手段が限られたデバイスからAPIにアクセスするためのものです。ユーザーがデバイスを認可できるようにするデバイスコードを取得するには、このエンドポイントを使用します。

<div id="request-example">
  ## リクエスト例
</div>

```http theme={null}
POST https://{yourDomain}/oauth/device/code
Content-Type: application/x-www-form-urlencoded

client_id=${account.clientId}&scope=SCOPE&audience=API_IDENTIFIER
```

<div id="response-values">
  ### レスポンス値
</div>

| Value                       | Description                               |
| :-------------------------- | :---------------------------------------- |
| `device_code`               | デバイスを識別する一意のコードです。                        |
| `user_code`                 | デバイスを認可するために、ユーザーが入力する必要があるコードです。         |
| `verification_uri`          | デバイスを認可するために、ユーザーがアクセスするURLです。            |
| `verification_uri_complete` | ユーザーコードを含む完全なURLで、簡単にアクセスできます。            |
| `expires_in`                | `device_code` と `user_code` の有効期間 (秒) です。 |
| `interval`                  | トークンをリクエストする際のポーリング間隔 (秒) です。             |

<div id="remarks">
  ### 注記
</div>

* Refresh Token を取得するには、`scope` に `offline_access` を含めます。
* 返された デバイスコード を使用して、token endpoint に アクセストークン をリクエストします。

<div id="token-request-example">
  ### トークンリクエストの例
</div>

```http theme={null}
POST https://{yourDomain}/oauth/token
Content-Type: application/x-www-form-urlencoded

client_id=${account.clientId}&device_code=YOUR_DEVICE_CODE&grant_type=urn:ietf:params:oauth:grant-type:device_code
```

<div id="responses">
  ### レスポンス
</div>

<div id="200">
  #### 200
</div>

リクエストが成功すると、アクセストークンが返されます。

```json theme={null}
HTTP/1.1 200 OK
Content-Type: application/json
{
   "access_token": "eyJz93a...k4laUWw",
   "id_token": "eyJ...0NE",
   "refresh_token": "eyJ...MoQ",
   "expires_in": 86400,
   "token_type": "Bearer"
}
```

<div id="error-responses">
  ### エラーレスポンス
</div>

```json theme={null}
HTTP/1.1 403 Forbidden
Content-Type: application/json
{ "error": "authorization_pending", "error_description": "User has yet to authorize device code." }
```

```json theme={null}
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
{ "error": "slow_down", "error_description": "You are polling faster than the specified interval of 5 seconds." }
```

```json theme={null}
HTTP/1.1 403 Forbidden
Content-Type: application/json
{ "error": "access_denied", "error_description": "User cancelled the confirmation prompt." }
```

<div id="learn-more">
  ### 詳細
</div>

* [Device Authorization Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow)
* [Device Authorization Flow を使用した API の呼び出し](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow/call-your-api-using-the-device-authorization-flow)
* [Management Dashboard での Device Code Grant の設定](https://auth0.com/docs/get-started/applications/update-grant-types)

<div id="body-parameters">
  ## Body パラメーター
</div>

<ParamField body="client_id" type="string" required>
  アプリケーションの ID。
</ParamField>

<ParamField body="scope" type="string">
  認可をリクエストするスコープ。
</ParamField>

<ParamField body="audience" type="string">
  アクセスする対象 API の一意の識別子。
</ParamField>

<ParamField body="resource" type="string">
  アクセスする対象 API (リソースサーバー) の識別子。Auth0 テナントに登録されている API Identifier と一致している必要があります。テナントの [Resource Parameter Compatibility Profile](https://auth0.com/docs/get-started/tenant-settings#settings-advanced) が `compatibility` に設定されている場合は、`audience` の代わりに使用されます。
</ParamField>

<div id="response-schema">
  ## レスポンススキーマ
</div>

<ResponseSchema>
  <ResponseField name="device_code" type="string">
    デバイスを識別する一意のコードです。ユーザーがブラウザを使用できるデバイスで `verification_uri` にアクセスすると、このコードがそのセッションに紐付けられます。
  </ResponseField>

  <ResponseField name="user_code" type="string">
    ユーザーが `verification_uri` で入力する必要があるコードです。
  </ResponseField>

  <ResponseField name="verification_uri" type="string">
    デバイスを認可するためにユーザーがアクセスする必要がある URL です。
  </ResponseField>

  <ResponseField name="verification_uri_complete" type="string">
    `user_code` を含む、ユーザーがアクセスする必要がある完全な URL です。
  </ResponseField>

  <ResponseField name="expires_in" type="integer">
    `device_code` と `user_code` の有効期間 (秒) です。
  </ResponseField>

  <ResponseField name="interval" type="integer">
    アプリがトークンをポーリングする間隔 (秒) です。
  </ResponseField>
</ResponseSchema>

<div id="response-messages">
  ## 応答メッセージ
</div>

| ステータス | 説明                    |
| ----- | --------------------- |
| 200   | デバイスコードとユーザーコードを返します。 |
