pypi django-oauth-toolkit 3.4.2

4 hours ago

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 a scope key, which RFC 8628 section 3.2 does
    not define and the view passed on to DeviceCodeResponse; 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, which OAuth2Validator did not implement.
    It now looks the grant up by device_code and the authenticated client_id, reports
    authorization_pending, access_denied or expired_token (marking the grant expired) as
    TokenView did, 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 a scope
    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's scope and 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. TokenView leaves the poll to
      oauthlib and the hook, so an unknown
      device_code, or one issued to another client, is answered with invalid_grant (HTTP 400,
      RFC 6749 section 5.2) instead of HTTP 404 device_not_found, and a device cannot learn the
      state of another client's grant. The device authorization endpoint validates scope, so a
      scope the application may not use (or a whitespace-only one) is answered with invalid_scope,
      as the authorization endpoint already did, instead of being stored on the grant. The default
      OAUTH_PRE_TOKEN_VALIDATION validator no longer raises on an unknown device_code.
    • oauthlib 4.0.0 and earlier: TokenView keeps checking the grant itself, as before, and now
      also checks its deadline: a poll after the grant's expires gets expired_token (RFC 8628
      section 3.5) instead of authorization_pending, and an authorized grant can no longer be
      exchanged for tokens after its deadline (#1938).

Don't miss a new django-oauth-toolkit release

NewReleases is sending notifications on new releases.