Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit fac61ff

Browse files
committed
This method is about getting all the tokens the token endpoint provides not just the access token.
1 parent 58f0ec4 commit fac61ff

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/oidcrp/rp_handler.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def get_client_authn_method(client, endpoint):
489489
else: # a list
490490
return am[0]
491491

492-
def get_access_token(self, state, client: Optional[Client] = None):
492+
def get_tokens(self, state, client: Optional[Client] = None):
493493
"""
494494
Use the 'accesstoken' service to get an access token from the OP/AS.
495495
@@ -499,7 +499,7 @@ def get_access_token(self, state, client: Optional[Client] = None):
499499
:return: A :py:class:`oidcmsg.oidc.AccessTokenResponse` or
500500
:py:class:`oidcmsg.oauth2.AuthorizationResponse`
501501
"""
502-
logger.debug(20 * "*" + " get_access_token " + 20 * "*")
502+
logger.debug(20 * "*" + " get_tokens " + 20 * "*")
503503

504504
if client is None:
505505
client = self.get_client_from_session_key(state)
@@ -699,8 +699,7 @@ def get_access_and_id_token(self, authorization_response=None,
699699
if not state:
700700
state = authorization_response['state']
701701

702-
authreq = _context.state.get_item(
703-
AuthorizationRequest, 'auth_request', state)
702+
authreq = _context.state.get_item(AuthorizationRequest, 'auth_request', state)
704703
_resp_type = set(authreq['response_type'])
705704

706705
access_token = None
@@ -712,11 +711,10 @@ def get_access_and_id_token(self, authorization_response=None,
712711
if _resp_type in [{'token'}, {'id_token', 'token'}, {'code', 'token'},
713712
{'code', 'id_token', 'token'}]:
714713
access_token = authorization_response["access_token"]
715-
if behaviour_args and behaviour_args.get("collect_id_token", False):
716-
if "id_token" not in _resp_type:
717-
logger.debug("Collect ID Token")
718-
# get the access token
719-
token_resp = self.get_access_token(state, client=client)
714+
if behaviour_args:
715+
if behaviour_args.get("collect_tokens", False):
716+
# get what you can from the token endpoint
717+
token_resp = self.get_tokens(state, client=client)
720718
if is_error_message(token_resp):
721719
return False, "Invalid response %s." % token_resp["error"]
722720
# Now which access_token should I use
@@ -726,7 +724,7 @@ def get_access_and_id_token(self, authorization_response=None,
726724

727725
elif _resp_type in [{'code'}, {'code', 'id_token'}]:
728726
# get the access token
729-
token_resp = self.get_access_token(state, client=client)
727+
token_resp = self.get_tokens(state, client=client)
730728
if is_error_message(token_resp):
731729
return False, "Invalid response %s." % token_resp["error"]
732730

tests/test_20_rp_handler_oidc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def test_get_client_authn_method(self):
425425
'token_endpoint')
426426
assert authn_method == 'client_secret_post'
427427

428-
def test_get_access_token(self):
428+
def test_get_tokens(self):
429429
res = self.rph.begin(issuer_id='github')
430430
_session = self.rph.get_session_information(res['state'])
431431
client = self.rph.issuer2rp[_session['iss']]
@@ -464,7 +464,7 @@ def test_get_access_token(self):
464464
resp = self.rph.finalize_auth(client, _session['iss'],
465465
auth_response.to_dict())
466466

467-
resp = self.rph.get_access_token(res['state'], client)
467+
resp = self.rph.get_tokens(res['state'], client)
468468
assert set(resp.keys()) == {'access_token', 'expires_in', 'id_token',
469469
'token_type', '__verified_id_token',
470470
'__expires_at'}

tests/test_40_rp_handler_persistent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_get_client_authn_method(self):
359359
'token_endpoint')
360360
assert authn_method == 'client_secret_post'
361361

362-
def test_get_access_token(self):
362+
def test_get_tokens(self):
363363
rph_1 = RPHandler(BASE_URL, client_configs=CLIENT_CONFIG,
364364
keyjar=CLI_KEY, module_dirs=['oidc'])
365365

@@ -401,7 +401,7 @@ def test_get_access_token(self):
401401
resp = rph_1.finalize_auth(client, _session['iss'],
402402
auth_response.to_dict())
403403

404-
resp = rph_1.get_access_token(res['state'], client)
404+
resp = rph_1.get_tokens(res['state'], client)
405405
assert set(resp.keys()) == {'access_token', 'expires_in', 'id_token',
406406
'token_type', '__verified_id_token',
407407
'__expires_at'}

0 commit comments

Comments
 (0)