0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-12 03:37:13 +08:00
discourse/lib/tasks
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
..
add_topic_to_quotes.rake
admin.rake DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
annotate.rake DEV: Load all bundled plugins when running annotate:clean (#39978) 2026-05-13 17:19:15 +01:00
annotate_rb.rake
api.rake
api_docs.rake
assets.rake PERF: Pre-compress WASM assets (#40682) 2026-06-09 15:20:00 +01:00
autospec.rake
avatars.rake
backfill.thor
categories.rake
cdn.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
compatibility.rake
db.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
db_structure.rake DEV: Check & resolve sequence issues during db:check_structure_dump (#40118) 2026-05-18 15:23:41 +01:00
destroy.rake
dev.rake DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
docker.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
documentation.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
emails.rake DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
export.rake
groups.rake
hashtags.rake
i18n.rake
images.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
import.rake FIX: Update renamed anonymous auto group (#40664) 2026-06-09 06:19:48 +00:00
incoming_emails.rake
javascript.rake FEATURE: Add category-level assignment permissions (#40412) 2026-06-08 09:59:40 -05:00
list_email_templates_strings.rake
log.rake
maxminddb.rake DEV: remove unused maxmind_thread variable (#37436) 2026-02-02 18:50:04 +11:00
migrate_advanced_search_banner_to_welcome_banner.rake
migrate_discourse_gifs_to_core.rake DEV: update GIFs migration script (#40741) 2026-06-10 22:46:26 +04:00
plugin.rake DEV: Silence expected error/debug output in core specs (#39247) 2026-04-14 11:04:10 +02:00
populate.rake FEATURE: Add top countries and top referrers cards to the admin dashboard (#40215) 2026-05-22 12:59:16 +08:00
populate.thor DEV: Fix assigned but unused variable Prism warnings (#39436) 2026-04-22 12:42:14 +02:00
posts.rake DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00
profile.rake
qunit.rake
redis.rake
release.rake DEV: Fixup release task logic (#39612) 2026-05-13 10:59:41 +01:00
release_note.rake
reviewables.rake DEV: fix a large amount of typos (#37428) 2026-02-02 16:31:58 +11:00
revisions.rake
rspec.rake
s3.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
scheduler.rake
search.rake
site.rake FEATURE: extract text from document uploads for LLM prompts (#39634) 2026-05-05 08:16:23 +10:00
site_settings.rake FIX: type: objects uploads should be stored as IDs (#40178) 2026-05-21 13:45:27 -03:00
smoke_test.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
svg_icons.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
svg_sprites.rake
tags.rake
themes.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
topic_localizations.rake DEV: Add rake task to backfill localization excerpts which were empty (#36901) 2025-12-30 17:04:36 +08:00
topics.rake
turbo.rake
typepad.thor DEV: Enable Style/RedundantParentheses rubocop rule (#40095) 2026-05-19 15:48:09 +02:00
uploads.rake DEV: Enable Rails/FilePath rubocop rule (#40097) 2026-05-19 19:07:54 +02:00
user_api_key.rake FEATURE: User API key device authorization flow (#40189) 2026-06-10 16:09:44 -04:00
users.rake DEV: Enable Style/RedundantBegin rubocop rule (#40096) 2026-05-19 18:44:54 +02:00