Skip to main content

Device authorization reference

This section provides detailed technical information about the OAuth 2.0 Device Authorization Grant flow used by the CLI.

Overview

The device flow lets a CLI request authorization while the user completes login in a browser on a secondary device. Nscale follows RFC 8628.

Technical details

Session storage

Device sessions are stored in a secure, server-side key-value store. Sessions are never exposed to the client and are automatically expired.

Timing

User codes

User codes are 8 characters in format XXXX-YYYY and use an ambiguity-reduced character set to minimize input errors.

API endpoints

1. Device authorization request

POST /api/oauth2/device Initiates the device authorization flow. Request:
Response:

2. Token endpoint (polling)

POST /api/oauth2/token The CLI polls this endpoint until authorization completes. Request:
Responses: Success response:

3. Token refresh

POST /api/oauth2/token Refresh an expired access token. Request:

Token storage recommendations

Store tokens securely using platform-appropriate mechanisms: Example with keytar:

Security considerations

Device code phishing

Attackers can socially engineer users into authorizing malicious device codes. Mitigations include:
  • Short session TTL (10 minutes) limits attack window.
  • User sees a consent screen with requested scopes.
  • Users can deny suspicious requests.
  • Device flow can be disabled if not required.

Brute force code guessing

Mitigations include high-entropy user codes, short TTLs, and consistent error responses to prevent enumeration.

Token leakage

Mitigations include single-use tokens, short pickup windows (60 seconds), and secure server-side session storage.

Polling rate abuse

Mitigations include server-side rate limiting and the slow_down error when polling too fast.

RFC 8628 compliance

Our implementation follows RFC 8628 (OAuth 2.0 Device Authorization Grant):

References