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

# Device login

> Sign people in on a TV or a command-line tool with the OAuth 2.0 device authorization grant (RFC 8628).

Some apps can't show Aiveth's sign-in page: a TV app, a kiosk, or a command-line tool. With device login, the device shows a short code, and the person allows it on their phone or computer at Aiveth's `/device` page. The device then gets tokens, the same as any other app.

Aiveth implements the OAuth 2.0 Device Authorization Grant (RFC 8628).

> [!NOTE]
>
> Device login needs the Pro plan or above.

## Turn it on for an app

Device login is off for every app until an admin turns it on. Device codes are a known phishing path (an attacker sends someone their own code), so turn it on only for apps that need it.

**1. Open the app**

In the console, open **Apps** and select the app.

**2. Turn on device login**

Under **Device login**, select **Turn on**.

A machine app can never use device login.

## The flow

**1. The device asks for codes**

```bash theme={null}
curl -X POST https://accounts.aiveth.com/oauth/device_authorization \
  -d client_id=YOUR_CLIENT_ID \
  -d scope="openid email profile"
```

A server app also sends its secret (Basic or `client_secret` in the form). `scope` must include `openid`; if you leave it out, Aiveth uses `openid`.

```json theme={null}
{
  "device_code": "Q2x5c3...",
  "user_code": "BCDF-GHJK",
  "verification_uri": "https://accounts.aiveth.com/device",
  "verification_uri_complete": "https://accounts.aiveth.com/device?user_code=BCDF-GHJK",
  "expires_in": 300,
  "interval": 5
}
```

**2. The device shows the code**

Show the `user_code` and the `verification_uri`, or a QR code of `verification_uri_complete`. Keep the `device_code` secret.

**3. The person allows it**

The person opens `/device`, signs in if needed, and enters the code. Aiveth shows a confirmation that names the app and the organization and asks whether they started this on their own device. They choose to allow it or not.

**4. The device polls for tokens**

Every `interval` seconds, the device asks the token endpoint:

```bash theme={null}
curl -X POST https://accounts.aiveth.com/oauth/token \
  -d grant_type=urn:ietf:params:oauth:grant-type:device_code \
  -d device_code=THE_DEVICE_CODE \
  -d client_id=YOUR_CLIENT_ID
```

Once the person allows it, the answer has the access token, ID token and, with `offline_access`, a refresh token. See [Tokens and claims](https://docs.aiveth.com/apps/tokens-and-claims.md).

## Polling answers

While it waits, the token endpoint answers `400` with one of these `error` values:

| Error | What to do |
| - | - |
| `authorization_pending` | The person hasn't answered yet. Wait `interval` seconds and ask again. |
| `slow_down` | You asked too soon. The interval grows by 5 seconds for the rest of this request. Use the new interval. |
| `access_denied` | The person didn't allow it. Stop. |
| `expired_token` | The code is unknown, used or past its 5 minutes. Start again. |
| `unauthorized_client` | Device login is off for this app. |

The answer is given once. After the device receives its tokens, or a refusal, the device code no longer works.

## Codes and limits

* **User code:** 8 letters from 20 consonants (no vowels, no digits), shown as `XXXX-XXXX`. Case and dashes are ignored when typed.
* **Device code:** 256 random bits. Aiveth keeps only its hash, and it works once.
* **Lifetime:** 5 minutes. Polling interval: 5 seconds to start.
* **Typing codes:** a person can try only a few codes in a short time, from one person and one network.
* **Starting requests:** at most 30 a minute from one network address, and 300 a minute for one app. Past that, `/oauth/device_authorization` answers `429` with `slow_down`.
* **Organization:** a person can allow only codes of their own organization's apps.

Your organization's sign-in check (under **Developers**) runs for device sign-ins too.

## Related

* [Login with Aiveth](https://docs.aiveth.com/apps/login-with-aiveth.md)
* [OpenID Connect endpoints](https://docs.aiveth.com/api-reference/oidc-endpoints.md)
* [Attack protection](https://docs.aiveth.com/sign-in/attack-protection.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.