Skip to content

Commit 302c686

Browse files
committed
Clarify that request.claims is the *requested* claims.
1 parent 3cb3759 commit 302c686

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

docs/oidc.rst

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ scopes in your ``settings.py``::
143143
# ... any other settings you want
144144
}
145145

146-
.. info::
146+
.. note::
147147
If you want to enable ``RS256`` at a later date, you can do so - just add
148148
the private key as described above.
149149

@@ -267,8 +267,10 @@ The second form gets no request object, and should return a dictionary
267267
mapping a claim name to a callable, accepting a request and producing
268268
the claim data::
269269
class CustomOAuth2Validator(OAuth2Validator):
270-
# Set `oidc_claim_scope = None` to ignore scopes that limit which claims to return,
271-
# otherwise the OIDC standard scopes are used.
270+
# Extend the standard scopes to add a new "permissions" scope
271+
# which returns a "permissions" claim:
272+
oidc_claim_scope = OAuth2Validator.oidc_claim_scope
273+
oidc_claim_scope.update({"permissions": "permissions"})
272274

273275
def get_additional_claims(self):
274276
return {
@@ -277,6 +279,7 @@ the claim data::
277279
"name": lambda request: ' '.join([request.user.first_name, request.user.last_name]),
278280
"preferred_username": lambda request: request.user.username,
279281
"email": lambda request: request.user.email,
282+
"permissions": lambda request: list(request.user.get_group_permissions()),
280283
}
281284

282285

@@ -313,30 +316,21 @@ The following example adds instructions to return the ``foo`` claim when the ``b
313316

314317
Set ``oidc_claim_scope = None`` to return all claims irrespective of the granted scopes.
315318

316-
You have to make sure you've added addtional claims via ``get_aditional_claims``
319+
You have to make sure you've added addtional claims via ``get_additional_claims``
317320
and defined the ``OAUTH2_PROVIDER["SCOPES"]`` in your settings in order for this functionality to work.
318321

319-
320-
Using the OIDC "claims" request parameter to determine which claims are returned
321-
--------------------------------------------------------------------------------
322-
323-
Besides using standard OIDC scopes, you can use OIDC's
324-
`5.5 Requesting Claims using the "claims" Request Parameter`_ feature.
325-
326-
TODO - confirm that this works and document so and whether it interferes with the scope stuff.
327-
328-
329322
.. note::
330323
This ``request`` object is not a ``django.http.Request`` object, but an
331324
``oauthlib.common.Request`` object. This has a number of attributes that
332325
you can use to decide what claims to put in to the ID token:
333326

334327
* ``request.scopes`` - the list of granted scopes.
335-
* ``request.claims`` - a dictionary of the claims.
336-
* ``request.user`` - the django user object.
328+
* ``request.claims`` - the requested claims per OIDC's `5.5 Requesting Claims using the "claims" Request Parameter`_
329+
* ``request.user`` - the `Django User`_ object.
337330

338331
.. _5.4 Requesting Claims using Scope Values: https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims
339332
.. _5.5 Requesting Claims using the "claims" Request Parameter: https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter
333+
.. _Django User: https://docs.djangoproject.com/en/stable/ref/contrib/auth/#user-model
340334

341335
What claims you decide to put in to the token is up to you to determine based
342336
upon what the scopes and / or claims means to your provider.

0 commit comments

Comments
 (0)