0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 12:09:27 +08:00
discourse/spec/lib/auth
Sam 5458a5f150
FEATURE: User API key device authorization flow (#40189)
Adds an OAuth-style device authorization flow for user API keys so
applications that can't open a browser (CLIs, headless tools, IoT
clients) can request a key by displaying a short user-facing code.

The client POSTs to `/user-api-key/device` to obtain a device code,
a user code, and a verification URL. The user visits the URL,
authenticates, confirms the application and scopes, and either
approves or denies the request. Meanwhile the client polls
`/user-api-key/device/poll` until it receives the encrypted key
payload, a denial, or expiry.

The flow is implemented as a `UserApiKey::DeviceAuth` namespace of
service objects (`CreateRequest`, `Authorize`, `Deny`, `Poll`,
`Store`, `Crypto`, `ApprovalTokenStore`, `GrantPresenter`). Pending
grants live in Redis with a short TTL and are rate limited per IP
and per user code. Encrypted payload generation is shared with the
existing redirect-based flow.

Also adds first-class expiration for user API keys:

- New `expires_at` column on `user_api_keys`.
- New `max_user_api_key_expiry_days` site setting (default 365).
- Clients can request a key lifetime via `expires_in_seconds`, which
  is surfaced to the user on the authorization screen and serialized
  back to the client.
- A `user_api_key` rake task for listing, inspecting, expiring, and
  revoking keys from the console.

---------

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
2026-06-10 16:09:44 -04:00
..
default_current_user_provider_spec.rb FEATURE: User API key device authorization flow (#40189) 2026-06-10 16:09:44 -04:00
discord_authenticator_spec.rb
discourse_id_authenticator_spec.rb FIX: enforce full_name_requirement on Discourse ID signups (#39831) 2026-05-07 15:17:47 -07:00
facebook_authenticator_spec.rb
github_authenticator_spec.rb
google_oauth2_authenticator_spec.rb DEV: Enable some minor rubocop rules (#40094) 2026-05-19 15:29:38 +02:00
linkedin_oidc_authenticator_spec.rb
managed_authenticator_spec.rb DEV: Fix linting and test for b1ea35bb30 (#34688) 2025-09-02 13:43:34 -04:00
result_spec.rb FEATURE: Support syncing User Field values from OAuth2 and OIDC (#40036) 2026-05-14 18:14:25 +01:00
twitter_authenticator_spec.rb FIX: Twitter login problem check not reporting accurately (#35593) 2025-10-24 09:42:58 -04:00