Skip to content
Workforce IdentityMarkdown

Sign in a TV or command-line tool

Let a device with no usable browser sign a user in by showing a short code they enter on their phone or computer.

APIRFC 8628

A smart TV, a kiosk, a command-line tool or an agent started from a terminal has no browser to sign in with. It shows a short code instead; the user signs in where it is easy, on their phone or laptop, and the device gets tokens for them. The device never sees their password.

Before you start:

  • Who can do it: a realm administrator, in a group that holds RealmOwner (Delegated administration). RealmViewer can read the settings but not change them.
  • Where: today this is done through the API; Call the API shows how to get $CVYUH_SESSION.
  • First: nothing. The page users enter the code on, https://foobar.cvyuh.com/device, is already there.
  1. Offer the device grant in the realm. Read the realm’s grant list first:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

    Then send that list back with the device grant added:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "grantTypes": ["…existing grant types",
    "urn:ietf:params:oauth:grant-type:device_code"] }'
  2. Register the device app. A device that can’t keep a secret is public:

    Terminal window
    curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=living-room-tv' \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "status": "active",
    "clientName": "Living Room TV",
    "tokenEndpointAuthMethod": "none",
    "grantTypes": ["urn:ietf:params:oauth:grant-type:device_code", "refresh_token"],
    "scopes": ["openid", "profile", "offline_access", "media:play"],
    "defaultScopes": ["openid", "media:play"],
    "allowedResources": ["https://media.example.com/api"],
    "defaultAudience": "https://media.example.com/api"
    }'
  1. The device shows: Go to https://foobar.cvyuh.com/device and enter BCDF-GHJK, or a QR code that opens the page with the code filled in.
  2. On their phone, they open the page, sign in if needed, and type the code. Case, dashes and spaces don’t matter.
  3. The page names the device’s app and what it asks for. They click Allow or Deny.
  4. The device moves on, signed in. It then appears among the user’s apps on Authorized Apps, where they can revoke it.

It posts to https://foobar.cvyuh.com/oauth2/device_authorization and receives a device_code, a user_code, the page address (verification_uri), the same address with the code filled in (verification_uri_complete, for a QR code) and a polling interval (five seconds by default). It then polls https://foobar.cvyuh.com/oauth2/token with grant_type=urn:ietf:params:oauth:grant-type:device_code and its device_code:

AnswerMeaning
authorization_pendingNot answered yet. Wait interval seconds and poll again
slow_downPolled too soon. Add five seconds to the interval and wait the whole new interval; a poll inside it is told slow_down again, and the interval grows by five seconds more
access_deniedThe user clicked Deny
expired_tokenTen minutes passed. Start over
tokensThe user allowed it

Unless the user allowed offline access, the device’s access ends with the session they allowed it from.

Start a sign-in from the device, enter its code at https://foobar.cvyuh.com/device and click Allow. The device’s next poll returns tokens, and the app shows on your Authorized Apps page.

The device’s tokens are on the user’s trail as a TOKEN_ISSUED record with grantType urn:ietf:params:oauth:grant-type:device_code. Find it in Audit → Authentication in the dashboard.

SymptomCauseFix
The device is told unauthorized_clientThe realm or the client lacks the device grantDo steps 1 and 2
The code page says the code isn’t validIt was mistyped, or ten minutes passedStart again on the device for a new code
The code page stops accepting codes for a whileToo many wrong codes from that browser or addressWait, then type the code carefully; see Device authorization
The device keeps getting slow_downIt polls faster than intervalWait the whole interval, five seconds longer each time
The device loses access when the user signs outIt holds online accessAsk for offline_access if it must keep working

The user revokes the device on Authorized Apps. To stop every device sign-in, read the realm’s grantTypes and send them back without urn:ietf:params:oauth:grant-type:device_code.