Repository navigation
Description
Describe the bug
DeviceAuthorizationEndpoint.validate_device_authorization_request does not call validate_scopes or get_default_scopes() on the request validator, unlike every other authorization endpoint in oauthlib. This means:
- When a device omits
scope, the resolved default scopes are never stored in the response — thescopekey is absent from the dict returned bycreate_device_authorization_response. - When a device provides
scope, the requested scopes are never validated against the available scopes for the client.
The authorization code endpoint resolves this correctly via base.GrantTypeBase.validate_scopes() (rfc6749/grant_types/base.py, line 164), which falls back to get_default_scopes() when request.scopes is falsy and then calls validate_scopes() on the result. The device authorization endpoint has no equivalent call.
How to reproduce
from oauthlib.oauth2 import DeviceApplicationServer
from oauthlib.oauth2.rfc6749.request_validator import RequestValidator
class MyValidator(RequestValidator):
def validate_client_id(self, client_id, request, *args, **kwargs):
return True
def authenticate_client(self, request, *args, **kwargs):
return True
def get_default_scopes(self, client_id, request, *args, **kwargs):
# This should be called when no scope is provided
return ["read", "write"]
def validate_scopes(self, client_id, scopes, client, request, *args, **kwargs):
# This should be called to validate provided or default scopes
return True
server = DeviceApplicationServer(
MyValidator(),
verification_uri="https://example.com/device",
)
headers, body, status = server.create_device_authorization_response(
"https://example.com/device_authorization",
http_method="POST",
body="client_id=myclient", # no scope provided
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
import json
response = json.loads(body)
print(response.get("scope")) # None — get_default_scopes() was never calledExpected behavior
validate_device_authorization_request() should mirror the behavior of base.GrantTypeBase.validate_scopes():
- If scope is provided in the request, call
request_validator.validate_scopes()to confirm the requested scopes are permitted for the client. Return an invalid_scope error if not. - If scope is absent, call
request_validator.get_default_scopes()to resolve the defaults, then validate them. - Include the resolved scope in the dict returned by
create_device_authorization_response()so that callers can store it alongside the device_code and user_code without needing to call the validator a second time themselves.
RFC 8628 §3.1 says the scope parameter carries the same semantics as RFC 6749 §3.3, so the same validation contract should apply.
Additional context
Please provide any further context here.
-
Are you using OAuth1, OAuth2 or OIDC?
OAuth2, server-side (authorization server).
-
Are you writing client or server side code?
Discovered while working on django-oauth-toolkit. Without this oauthlib behaviour, DOT has to work around the gap by calling get_default_scopes() manually after create_device_authorization_response() returns, requiring an extra database query to look up the Application in order to construct a sufficiently populated oauthlib.common.Request to pass to the validator. See django-oauth-toolkit PR #1692 for the workaround and its security motivation (consent integrity violation / potential privilege escalation when DEFAULT_SCOPES changes between user consent and device polling).
Activity
auvipy commentedon May 12, 2026
thanks for the report. are you up for a contribution to fix this?
dopry commentedon May 21, 2026
I don't have the time at present. I'm struggling to give the DOT queue the attention it needs. If I ever get caught up there I can try.