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

# Authorize Device

> Obtain a device code to start the Device Authorization Flow for input-constrained devices.

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

## Endpoint

`POST /oauth/device/code`

This flow is designed for input-constrained devices to access an API. Use this endpoint to obtain a device code that allows the user to authorize the device.

## Request Example

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

### Response Values

| Value                       | Description                                               |
| :-------------------------- | :-------------------------------------------------------- |
| `device_code`               | The unique code for the device.                           |
| `user_code`                 | The code the user must input to authorize the device.     |
| `verification_uri`          | The URL the user should visit to authorize the device.    |
| `verification_uri_complete` | The complete URL including the user code for easy access. |
| `expires_in`                | The lifetime of the device and user codes in seconds.     |
| `interval`                  | The polling interval in seconds to request a token.       |

### Remarks

* Include `offline_access` in the `scope` to obtain a Refresh Token.
* Use the returned device code to request an access token from the token endpoint.

### Token Request Example

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

### Responses

#### 200

A successful request returns an access token.

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

### Error Responses

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

### Learn More

* [Device Authorization Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow)
* [Call API using the Device Authorization Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow/call-your-api-using-the-device-authorization-flow)
* [Setting up a Device Code Grant using the Management Dashboard](https://auth0.com/docs/get-started/applications/update-grant-types)

## Body Parameters

<ParamField body="client_id" type="string" required>
  Your application's ID.
</ParamField>

<ParamField body="scope" type="string">
  The scopes for which you want to request authorization.
</ParamField>

<ParamField body="audience" type="string">
  The unique identifier of the target API you want to access.
</ParamField>

<ParamField body="resource" type="string">
  The identifier of the target API (resource server) you want to access. Must match an API Identifier registered in your Auth0 tenant. Used as an alternative to `audience` when the tenant's [Resource Parameter Compatibility Profile](https://auth0.com/docs/get-started/tenant-settings#settings-advanced) is set to `compatibility`.
</ParamField>

## Response Schema

<ResponseSchema>
  <ResponseField name="device_code" type="string">
    The unique code for the device. When the user goes to the `verification_uri` in their browser-based device, this code is bound to their session.
  </ResponseField>

  <ResponseField name="user_code" type="string">
    The code that the user must input at the `verification_uri`.
  </ResponseField>

  <ResponseField name="verification_uri" type="string">
    The URL the user must visit to authorize the device.
  </ResponseField>

  <ResponseField name="verification_uri_complete" type="string">
    The complete URL the user must visit, including the `user_code`.
  </ResponseField>

  <ResponseField name="expires_in" type="integer">
    The lifetime in seconds of the `device_code` and `user_code`.
  </ResponseField>

  <ResponseField name="interval" type="integer">
    The interval in seconds at which the app should poll for a token.
  </ResponseField>
</ResponseSchema>

## Response Messages

| Status | Description                    |
| ------ | ------------------------------ |
| 200    | Returns device and user codes. |
