Skip to content

Commit 27821a8

Browse files
authored
#1066: Revert #967 which incorrectly breaks API. (#1068)
* #1066: Revert #967 which incorrectly breaks API.
1 parent 250120d commit 27821a8

File tree

6 files changed

+22
-56
lines changed

6 files changed

+22
-56
lines changed

‎AUTHORS‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,5 @@ pySilver
6565
Łukasz Skarżyński
6666
Shaheed Haque
6767
Peter Karman
68-
Andrea Greco
6968
Vinay Karanam
7069
Eduardo Oliveira

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222

2323
### Fixed
2424
*#1012 Return status for introspecting a nonexistent token from 401 to the correct value of 200 per [RFC 7662](https://datatracker.ietf.org/doc/html/rfc7662#section-2.2).
25+
*#1068 Revert #967 which incorrectly changed an API. See #1066.
2526

2627
## [1.6.1] 2021-12-23
2728

‎docs/oidc.rst‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,16 @@ 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.
249-
Standard claim ``sub`` is included by default, for remove it override ``get_claim_list``::
248+
our custom validator::
249+
250250
class CustomOAuth2Validator(OAuth2Validator):
251-
def get_additional_claims(self):
252-
def get_user_email(request):
253-
return request.user.get_full_name()
254-
255-
# Element name, callback to obtain data
256-
claims_list = [ ("email", get_sub_cod),
257-
("username", get_user_email) ]
258-
return claims_list
251+
252+
def get_additional_claims(self, request):
253+
return{
254+
"sub": request.user.email,
255+
"first_name": request.user.first_name,
256+
"last_name": request.user.last_name,
257+
}
259258

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

‎oauth2_provider/oauth2_validators.py‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -740,24 +740,15 @@ def _save_id_token(self, jti, request, expires, *args, **kwargs):
740740
defget_jwt_bearer_token(self, token, token_handler, request):
741741
returnself.get_id_token(token, token_handler, request)
742742

743-
defget_claim_list(self):
744-
defget_sub_code(request):
745-
returnstr(request.user.id)
746-
747-
list= [("sub", get_sub_code)]
743+
defget_oidc_claims(self, token, token_handler, request):
744+
# Required OIDC claims
745+
claims={
746+
"sub": str(request.user.id),
747+
}
748748

749749
# https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
750-
add=self.get_additional_claims()
751-
list.extend(add)
752-
753-
returnlist
750+
claims.update(**self.get_additional_claims(request))
754751

755-
defget_oidc_claims(self, token, token_handler, request):
756-
data=self.get_claim_list()
757-
claims={}
758-
759-
fork, callindata:
760-
claims[k] =call(request)
761752
returnclaims
762753

763754
defget_id_token_dictionary(self, token, token_handler, request):
@@ -910,5 +901,5 @@ def get_userinfo_claims(self, request):
910901
"""
911902
returnself.get_oidc_claims(None, None, request)
912903

913-
defget_additional_claims(self):
914-
return[]
904+
defget_additional_claims(self, request):
905+
return{}

‎oauth2_provider/views/oidc.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ def get(self, request, *args, **kwargs):
4545
signing_algorithms= [Application.HS256_ALGORITHM]
4646
ifoauth2_settings.OIDC_RSA_PRIVATE_KEY:
4747
signing_algorithms= [Application.RS256_ALGORITHM, Application.HS256_ALGORITHM]
48-
49-
validator_class=oauth2_settings.OAUTH2_VALIDATOR_CLASS
50-
validator=validator_class()
51-
oidc_claims= []
52-
forel, _invalidator.get_claim_list():
53-
oidc_claims.append(el)
54-
5548
data={
5649
"issuer": issuer_url,
5750
"authorization_endpoint": authorization_endpoint,
@@ -64,7 +57,6 @@ def get(self, request, *args, **kwargs):
6457
"token_endpoint_auth_methods_supported": (
6558
oauth2_settings.OIDC_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED
6659
),
67-
"claims_supported": oidc_claims,
6860
}
6961
response=JsonResponse(data)
7062
response["Access-Control-Allow-Origin"] ="*"

‎tests/test_oidc_views.py‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def test_get_connect_discovery_info(self):
2929
"subject_types_supported": ["public"],
3030
"id_token_signing_alg_values_supported": ["RS256", "HS256"],
3131
"token_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic"],
32-
"claims_supported": ["sub"],
3332
}
3433
response=self.client.get(reverse("oauth2_provider:oidc-connect-discovery-info"))
3534
self.assertEqual(response.status_code, 200)
@@ -56,7 +55,6 @@ def test_get_connect_discovery_info_without_issuer_url(self):
5655
"subject_types_supported": ["public"],
5756
"id_token_signing_alg_values_supported": ["RS256", "HS256"],
5857
"token_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic"],
59-
"claims_supported": ["sub"],
6058
}
6159
response=self.client.get(reverse("oauth2_provider:oidc-connect-discovery-info"))
6260
self.assertEqual(response.status_code, 200)
@@ -148,21 +146,11 @@ def test_userinfo_endpoint_bad_token(oidc_tokens, client):
148146
assertrsp.status_code==401
149147

150148

151-
EXAMPLE_EMAIL="[email protected]"
152-
153-
154-
defclaim_user_email(request):
155-
returnEXAMPLE_EMAIL
156-
157-
158149
@pytest.mark.django_db
159150
deftest_userinfo_endpoint_custom_claims(oidc_tokens, client, oauth2_settings):
160151
classCustomValidator(OAuth2Validator):
161-
defget_additional_claims(self):
162-
return [
163-
("username", claim_user_email),
164-
("email", claim_user_email),
165-
]
152+
defget_additional_claims(self, request):
153+
return{"state": "very nice"}
166154

167155
oidc_tokens.oauth2_settings.OAUTH2_VALIDATOR_CLASS=CustomValidator
168156
auth_header="Bearer %s"%oidc_tokens.access_token
@@ -173,9 +161,5 @@ def get_additional_claims(self):
173161
data=rsp.json()
174162
assert"sub"indata
175163
assertdata["sub"] ==str(oidc_tokens.user.pk)
176-
177-
assert"username"indata
178-
assertdata["username"] ==EXAMPLE_EMAIL
179-
180-
assert"email"indata
181-
assertdata["email"] ==EXAMPLE_EMAIL
164+
assert"state"indata
165+
assertdata["state"] =="very nice"

0 commit comments

Comments
(0)