@@ -184,6 +184,15 @@ def test_authorize(self):
184
184
assert resp ['code' ] in self .provider .authz_state .authorization_codes
185
185
assert resp ['state' ] == self .authn_request_args ['state' ]
186
186
187
+ def test_authorize_with_custom_sub (self , monkeypatch ):
188
+ sub = 'test_sub1'
189
+ monkeypatch .setitem (self .provider .userinfo ._db [TEST_USER_ID ], 'sub' , sub )
190
+ auth_req = AuthorizationRequest ().from_dict (self .authn_request_args )
191
+ resp = self .provider .authorize (auth_req , TEST_USER_ID )
192
+ assert resp ['code' ] in self .provider .authz_state .authorization_codes
193
+ assert resp ['state' ] == self .authn_request_args ['state' ]
194
+ assert self .provider .authz_state .authorization_codes [resp ['code' ]]['sub' ] == sub
195
+
187
196
@patch ('time.time' , MOCK_TIME )
188
197
@pytest .mark .parametrize ('extra_claims' , [
189
198
{'foo' : 'bar' },
@@ -427,6 +436,15 @@ def test_handle_userinfo(self):
427
436
assert response .to_dict () == self .provider .userinfo [TEST_USER_ID ]
428
437
assert self .provider .authz_state .get_user_id_for_subject_identifier (response_sub ) == TEST_USER_ID
429
438
439
+ def test_handle_userinfo_with_custom_sub (self , monkeypatch ):
440
+ sub = 'test_sub1'
441
+ monkeypatch .setitem (self .provider .userinfo ._db [TEST_USER_ID ], 'sub' , sub )
442
+ claims_request = ClaimsRequest (userinfo = Claims (email = None ))
443
+ access_token = self .create_access_token ({'scope' : 'openid profile' , 'claims' : claims_request })
444
+ response = self .provider .handle_userinfo_request (urlencode ({'access_token' : access_token }))
445
+
446
+ assert response ['sub' ] == sub
447
+
430
448
def test_handle_userinfo_rejects_request_missing_access_token (self ):
431
449
with pytest .raises (BearerTokenError ) as exc :
432
450
self .provider .handle_userinfo_request ()
0 commit comments