Repository navigation
This release makes the device authorization grant (RFC 8628) work with oauthlib 4.0.1, which
broke it: since oauthlib 4.0.1 was released on 2026-10-31, both the device authorization endpoint
and the token endpoint's device code polls have failed with HTTP 500. With oauthlib 4.0.1 and
later, some device flow errors change (an unknown device_code is now invalid_grant, and a scope
the application may not use is now invalid_scope), so if you use the device flow, read
"Upgrading to 3.4.2" in the Upgrading guide. Nothing changes for deployments that do not use
the device flow, and there are no migrations.
Fixed
- #1950 The device authorization grant (RFC 8628) works with oauthlib 4.0.1, which broke it in two
places. The device authorization endpoint answered every request with HTTP 500, because oauthlib
now adds the scopes it resolved to its response as ascopekey, which RFC 8628 section 3.2 does
not define and the view passed on toDeviceCodeResponse; the grant now stores that scope and the
device gets the same response as before. The token endpoint then failed the poll with HTTP 500,
because oauthlib now asks the validator for the device code's status through the new
validate_device_code(client_id, code, request)hook, whichOAuth2Validatordid not implement.
It now looks the grant up bydevice_codeand the authenticatedclient_id, reports
authorization_pending,access_deniedorexpired_token(marking the grant expired) as
TokenViewdid, and for an authorized grant sets the approving user and the stored scopes on the
request. The grant's scopes are what the user approved, so they also replace ascope
parameter sent with the poll (RFC 8628 section 3.4 defines none), and a grant approved without
scopes yields a token without scopes: oauthlib takes an empty scope set for an absent one and
falls back to the poll'sscopeand then the client's default scopes, so
OAuth2Validator.get_default_scopes()answers with the grant's own scopes while a device code
grant is redeemed (request.device_grant), on every oauthlib. What the device sees depends on
the installed oauthlib:- oauthlib 4.0.1 and later: the grant stores the scope oauthlib resolved (none when oauthlib
resolved none) instead of asking the scopes backend again.TokenViewleaves the poll to
oauthlib and the hook, so an unknown
device_code, or one issued to another client, is answered withinvalid_grant(HTTP 400,
RFC 6749 section 5.2) instead of HTTP 404device_not_found, and a device cannot learn the
state of another client's grant. The device authorization endpoint validatesscope, so a
scope the application may not use (or a whitespace-only one) is answered withinvalid_scope,
as the authorization endpoint already did, instead of being stored on the grant. The default
OAUTH_PRE_TOKEN_VALIDATIONvalidator no longer raises on an unknowndevice_code. - oauthlib 4.0.0 and earlier:
TokenViewkeeps checking the grant itself, as before, and now
also checks its deadline: a poll after the grant'sexpiresgetsexpired_token(RFC 8628
section 3.5) instead ofauthorization_pending, and an authorized grant can no longer be
exchanged for tokens after its deadline (#1938).
- oauthlib 4.0.1 and later: the grant stores the scope oauthlib resolved (none when oauthlib