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

# デバイス認可

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

## エンドポイント

`POST /oauth/device/code`

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

## リクエスト例

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

### レスポンス値

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

### 注記

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

### トークンリクエストの例

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

### レスポンス

#### 200

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

```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"
}
```

### エラーレスポンス

```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." }
```

### 詳細

* [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)

## Body パラメーター

**client\_id** `string` *required*

アプリケーションの ID。

**scope** `string`

認可をリクエストするスコープ。

**audience** `string`

アクセスする対象 API の一意の識別子。

**resource** `string`

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

## レスポンススキーマ

\{}

application/json

**device\_code** `string`

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

**user\_code** `string`

ユーザーが `verification_uri` で入力する必要があるコードです。

**verification\_uri** `string`

デバイスを認可するためにユーザーがアクセスする必要がある URL です。

**verification\_uri\_complete** `string`

`user_code` を含む、ユーザーがアクセスする必要がある完全な URL です。

**expires\_in** `integer`

`device_code` と `user_code` の有効期間 (秒) です。

**interval** `integer`

アプリがトークンをポーリングする間隔 (秒) です。

## 応答メッセージ

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