Skip to content

Commit

Permalink
Merge pull request #656 from borislaviv/master
Browse files Browse the repository at this point in the history
Extract load_key construction to separate method
  • Loading branch information
lepture authored Jul 1, 2024
2 parents 12da188 + 341ce0e commit 174248e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions authlib/integrations/base_client/sync_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@ def parse_id_token(self, token, nonce, claims_options=None, leeway=120):
"""Return an instance of UserInfo from token's ``id_token``."""
if 'id_token' not in token:
return None

def load_key(header, _):
jwk_set = JsonWebKey.import_key_set(self.fetch_jwk_set())
try:
return jwk_set.find_by_kid(header.get('kid'))
except ValueError:
# re-try with new jwk set
jwk_set = JsonWebKey.import_key_set(self.fetch_jwk_set(force=True))
return jwk_set.find_by_kid(header.get('kid'))

load_key = self.create_load_key()

claims_params = dict(
nonce=nonce,
Expand Down Expand Up @@ -75,3 +68,15 @@ def load_key(header, _):

claims.validate(leeway=leeway)
return UserInfo(claims)

def create_load_key(self):
def load_key(header, _):
jwk_set = JsonWebKey.import_key_set(self.fetch_jwk_set())
try:
return jwk_set.find_by_kid(header.get('kid'))
except ValueError:
# re-try with new jwk set
jwk_set = JsonWebKey.import_key_set(self.fetch_jwk_set(force=True))
return jwk_set.find_by_kid(header.get('kid'))

return load_key

0 comments on commit 174248e

Please sign in to comment.