Skip to content

Commit 1f85553

Browse files
committed
OpenID: Update get_additional_claims docs
1 parent 789add8 commit 1f85553

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ Peter Karman
6868
Vinay Karanam
6969
Eduardo Oliveira
7070
Andrea Greco
71+
Dominik George

docs/oidc.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,22 @@ required claims, eg ``iss``, ``aud``, ``exp``, ``iat``, ``auth_time`` etc),
245245
and the ``sub`` claim will use the primary key of the user as the value.
246246
You'll probably want to customize this and add additional claims or change
247247
what is sent for the ``sub`` claim. To do so, you will need to add a method to
248-
our custom validator.
248+
our custom validator. It should return a dictionary mapping a claim name to
249+
either the claim data, or a callable that will be called with the request to
250+
produce the claim data.
249251
Standard claim ``sub`` is included by default, for remove it override ``get_claim_list``::
250252
class CustomOAuth2Validator(OAuth2Validator):
251-
def get_additional_claims(self):
253+
def get_additional_claims(self, request):
252254
def get_user_email(request):
253-
return request.user.get_full_name()
255+
return request.user.get_user_email()
254256

257+
claims = {}
255258
# Element name, callback to obtain data
256-
claims_list = [ ("email", get_sub_cod),
257-
("username", get_user_email) ]
258-
return claims_list
259+
claims["email"] = get_user_email
260+
# Element name, plain data returned
261+
claims["username"] = request.user.get_full_name()
262+
263+
return claims
259264

260265
.. note::
261266
This ``request`` object is not a ``django.http.Request`` object, but an

0 commit comments

Comments
 (0)