Device Authorization

The device authorization flow enables CLI tools and desktop applications to authenticate without requiring users to enter credentials directly in the application.

Overview#

This flow is ideal for:

  • Command-line tools
  • Desktop applications
  • Smart TV apps
  • IoT devices
  • Any environment without a browser

Flow Diagram#

┌─────────┐ ┌─────────────┐ │ CLI │ │ Bootspring │ │ App │ │ API │ └────┬────┘ └──────┬──────┘ │ │ │ 1. POST /auth/device/code │ │ ─────────────────────────────────────────────► │ │ │ │ 2. Returns device_code, user_code │ │ ◄───────────────────────────────────────────── │ │ │ │ 3. Display user_code to user │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ User visits bootspring.dev/device │ │ │ │ and enters code: ABCD-1234 │ │ │ └─────────────────────────────────────────┘ │ │ │ │ 4. Poll POST /auth/device/token │ │ ─────────────────────────────────────────────► │ │ │ │ 5. Returns access_token (when authorized) │ │ ◄───────────────────────────────────────────── │ │ │

Step 1: Request Device Code#

Request#

Loading code block...

Parameters#

ParameterTypeRequiredDescription
client_idstringYesYour application identifier
scopestringNoSpace-separated list of scopes

Response#

Loading code block...

Response Fields#

FieldDescription
device_codeCode used to poll for authorization
user_codeCode the user enters on the website
verification_uriURL where user authorizes the device
verification_uri_completeURL with code pre-filled
expires_inSeconds until codes expire (default: 900)
intervalMinimum seconds between poll requests

Step 2: Display to User#

Present the user with clear instructions:

═══════════════════════════════════════════ Bootspring Device Authorization ═══════════════════════════════════════════ To sign in, visit: https://bootspring.dev/device And enter code: ABCD-1234 Or scan this QR code: [QR CODE] Waiting for authorization... ═══════════════════════════════════════════

Best Practices#

  • Display the code prominently
  • Show a QR code for verification_uri_complete when possible
  • Indicate that the app is waiting
  • Show a countdown for expiration

Step 3: Poll for Token#

Poll the token endpoint at the specified interval.

Request#

Loading code block...

Pending Response#

Loading code block...

Success Response#

Loading code block...

Error Responses#

ErrorDescriptionAction
authorization_pendingUser hasn't authorized yetContinue polling
slow_downPolling too fastIncrease interval by 5 seconds
expired_tokenDevice code expiredRestart from step 1
access_deniedUser denied authorizationShow error to user

Implementation Example#

TypeScript#

Loading code block...

CLI Example#

Loading code block...

Token Storage#

Store tokens securely on the device:

macOS (Keychain)#

Loading code block...

Linux (Secret Service)#

Loading code block...

Windows (Credential Manager)#

Loading code block...

Token Refresh#

Refresh tokens before they expire:

Loading code block...

Response:

Loading code block...

Logout#

Revoke the device token:

Loading code block...

Security Considerations#

  1. Never store device_code - It's only used during authorization
  2. Store access_token securely - Use system keychain/credential manager
  3. Implement token refresh - Don't wait for expiration
  4. Handle revocation - Check for 401 responses and re-authenticate