fix(oauth): Support public clients for device flow per RFC 8628 §5.6#106169
Merged
fix(oauth): Support public clients for device flow per RFC 8628 §5.6#106169
Conversation
aea7b91 to
617ac41
Compare
The OAuth 2.0 Device Authorization Grant (RFC 8628) is designed for headless clients like CLIs, native apps, and IoT devices that cannot securely store credentials. Per RFC 8628 §5.6 (Non-Confidential Clients): > Device clients are generally incapable of maintaining the > confidentiality of their credentials, as users in possession of > the device can reverse-engineer it and extract the credentials. > Therefore, unless additional measures are taken, they should be > treated as public clients. And per RFC 8628 §3.4 (Device Access Token Request): > client_id: REQUIRED if the client is not authenticating with the > authorization server as described in Section 3.2.1. of [RFC6749]. The previous implementation required client_secret for ALL grant types, including device_code. This broke the fundamental design of the device flow, which is meant for public clients that authenticate with only client_id. Changes: - Move grant_type validation before credential check - For device_code grant: only require client_id (public client mode) - If client_secret is provided: still validate it (confidential client) - Other grant types: unchanged (still require client_id + client_secret) This allows CLIs to authenticate without embedding secrets while still supporting confidential clients that choose to provide credentials.
1464771 to
72a582f
Compare
BYK
approved these changes
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the OAuth 2.0 Device Authorization Grant implementation to properly support public clients as required by RFC 8628.
Problem
The current token endpoint requires
client_secretfor ALL grant types, includingdevice_code. This breaks the fundamental design of the device flow, which is explicitly designed for public clients (CLIs, native apps, IoT devices) that cannot securely store secrets.What the RFC Says
RFC 8628 §5.6 - Non-Confidential Clients:
RFC 8628 §3.4 - Device Access Token Request:
RFC 6749 §2.1 - Client Types:
Solution
grant_typevalidation before credential check (needed to determine auth requirements)device_codegrant: only requireclient_id(public client mode per RFC 8628 §5.6)client_secretis provided: still validate it (supports confidential clients that choose to authenticate)authorization_code,refresh_token): unchanged, still requireclient_id+client_secretChanges
src/sentry/web/frontend/oauth_token.pytests/sentry/web/frontend/test_oauth_token.pyNew Tests
test_public_client_success- Public client can exchange approved device codetest_public_client_invalid_client_id- Invalid client_id rejected with 401test_public_client_missing_client_id- Missing client_id rejected with 401test_public_client_authorization_pending- Polling works for public clientstest_confidential_client_wrong_secret_rejected- Wrong secret still rejected when providedSecurity Considerations
This change is RFC-compliant and does not reduce security:
device_codeis bound to theapplicationat creation time, so a public client can only poll for tokens for its own applicationclient_secret, we validate itRelated