> ## 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.

# デバイスの認可

> 入力手段が限られたデバイス向けに、デバイス認可フローを開始するためのデバイスコードを取得します。

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>

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

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

* リフレッシュトークンを取得するには、`scope` に `offline_access` を含めます。
* 返されたデバイスコードを使用して、トークンエンドポイントにアクセストークンをリクエストします。

<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>

* [デバイス認可フロー](https://auth0.com/docs/get-started/authentication-and-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 でデバイスコードグラントを設定する](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 識別子と一致する必要があります。テナントの [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">
    デバイスの一意のcodeです。ユーザーがブラウザベースのデバイスで `verification_uri` にアクセスすると、このcodeはそのセッションに紐付けられます。
  </ResponseField>

  <ResponseField name="user_code" type="string">
    ユーザーが `verification_uri` で入力する必要があるcodeです。
  </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   | デバイスコードとユーザーコードが返されます。 |
