> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-docs-event-stream-action-templates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# デバイスを認可する

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

`POST /oauth/device/code`

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

## 要求例

```
POST https://${account.namespace}/oauth/device/code
Content-Type: application/x-www-form-urlencoded

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

### 応答値

| 値                           | 説明                               |
| --------------------------- | -------------------------------- |
| `device_code`               | デバイスの一意のコード。                     |
| `user_code`                 | デバイスを認可するためにユーザーが入力しなければならないコード。 |
| `verification_uri`          | デバイスを認可するためにユーザーがアクセスすべきURL。     |
| `verification_uri_complete` | 簡単にアクセスできるようユーザーコードを含む完全なURL。    |
| `expires_in`                | デバイスおよびユーザーコードの有効期間の秒数。          |
| `interval`                  | トークンを要求するポーリング間隔の秒数。             |

### 備考

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

### トークン要求の例

```
POST https://${account.namespace}/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

要求が成功するとアクセストークンを返します。

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

### エラー応答

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

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

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

### 詳しく学ぶ

* [デバイス認可フロー](https://auth0.com/docs/ja-jp/get-started/authentication-and-authorization-flow/device-authorization-flow)
* [デバイス認可フローを使用してAPIを呼び出す](https://auth0.com/docs/ja-jp/get-started/authentication-and-authorization-flow/device-authorization-flow/call-your-api-using-the-device-authorization-flow)
* [Management Dashboardを使用してデバイスコード付与を設定する](https://auth0.com/docs/ja-jp/get-started/applications/update-grant-types)

## Parameters

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

<ParamField body="scope" type="string">
  認可を要求するスコープです。
</ParamField>

<ParamField body="audience" type="string">
  アクセスしたいターゲットAPIの一意の識別子です。
</ParamField>

## Response

| Status | Description          |
| ------ | -------------------- |
| 200    | デバイスおよびユーザーコードを返します。 |
