Skip to content

Commit

Permalink
fix oauthlib#755: ensure save_token is called for hybrid code flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kazkansouh authored and achraf-mer committed Oct 21, 2021
1 parent 30df86d commit 8406b51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
Expand Up @@ -272,6 +272,8 @@ def create_authorization_response(self, request, token_handler):
grant = self.create_authorization_code(request)
for modifier in self._code_modifiers:
grant = modifier(grant, token_handler, request)
if 'access_token' in grant:
self.request_validator.save_token(grant, request)
log.debug('Saving grant %r for %r.', grant, request)
self.request_validator.save_authorization_code(
request.client_id, grant, request)
Expand Down
15 changes: 15 additions & 0 deletions tests/oauth2/rfc6749/grant_types/test_authorization_code.py
Expand Up @@ -324,3 +324,18 @@ def test_correct_code_challenge_method_s256(self):
authorization_code.code_challenge_method_s256("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk",
"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM")
)

def test_code_modifier_called(self):
bearer = BearerToken(self.mock_validator)
code_modifier = mock.MagicMock(wraps=lambda grant, *a: grant)
self.auth.register_code_modifier(code_modifier)
self.auth.create_authorization_response(self.request, bearer)
code_modifier.assert_called_once()

def test_hybrid_token_save(self):
bearer = BearerToken(self.mock_validator)
self.auth.register_code_modifier(
lambda grant, *a: dict(list(grant.items()) + [('access_token', 1)])
)
self.auth.create_authorization_response(self.request, bearer)
self.mock_validator.save_token.assert_called_once()

0 comments on commit 8406b51

Please sign in to comment.