fix(oauth): Support public clients for device flow per RFC 8628 §5.6 #106169
+203
−36
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