Skip to content

Commit 3cb3759

Browse files
committed
Fix validate_bearer_token to set correct request.scopes.
1 parent b170d72 commit 3cb3759

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

docs/oidc.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ TODO - confirm that this works and document so and whether it interferes with th
331331
``oauthlib.common.Request`` object. This has a number of attributes that
332332
you can use to decide what claims to put in to the ID token:
333333

334-
* ``request.scopes`` - is `NOT the list of granted scopes <https://github.com/oauthlib/oauthlib/issues/799>`_. For that, use:
335-
* ``request.access_token.scopes`` - the list of granted scopes.
334+
* ``request.scopes`` - the list of granted scopes.
336335
* ``request.claims`` - a dictionary of the claims.
337336
* ``request.user`` - the django user object.
338337

oauth2_provider/oauth2_validators.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def validate_bearer_token(self, token, scopes, request):
425425
if access_token and access_token.is_valid(scopes):
426426
request.client = access_token.application
427427
request.user = access_token.user
428-
request.scopes = scopes
428+
request.scopes = list(access_token.scopes)
429429

430430
# this is needed by django rest framework
431431
request.access_token = access_token
@@ -787,13 +787,10 @@ def get_oidc_claims(self, token, token_handler, request):
787787
data = self.get_claim_dict(request)
788788
claims = {}
789789

790+
# TODO if request.claims then return only the claims requested, but limited by granted scopes.
791+
790792
for k, v in data.items():
791-
if not self.oidc_claim_scope or (
792-
token
793-
and hasattr(token, "scopes")
794-
and k in self.oidc_claim_scope
795-
and self.oidc_claim_scope[k] in token.scopes
796-
):
793+
if not self.oidc_claim_scope or self.oidc_claim_scope.get(k) in request.scopes:
797794
claims[k] = v(request) if callable(v) else v
798795
return claims
799796

0 commit comments

Comments
 (0)