Skip to content

Commit

Permalink
Use JsonWebKey directly (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrman authored Oct 25, 2023
1 parent 7a9ceb4 commit 0e2a1e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog of nens-auth-client
1.3 (unreleased)
----------------

- Nothing changed yet.
- Fixed deprecation warning by using JsonWebKey directly instead of calling
jwk.loads.


1.2 (2023-03-20)
Expand Down
7 changes: 4 additions & 3 deletions nens_auth_client/cognito.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from authlib.integrations.django_client import DjangoOAuth2App
from authlib.jose import JsonWebKey
from authlib.jose import JsonWebToken
from authlib.jose import jwk
from django.conf import settings
from django.http.response import HttpResponseRedirect
from urllib.parse import urlencode
Expand Down Expand Up @@ -118,12 +118,13 @@ def parse_access_token(self, token, claims_options=None, leeway=120):
# this is a copy from the _parse_id_token equivalent function
def load_key(header, payload):
jwk_set = self.fetch_jwk_set()
kid = header.get("kid")
try:
return jwk.loads(jwk_set, header.get("kid"))
return JsonWebKey.import_key_set(jwk_set).find_by_kid(kid)
except ValueError:
# re-try with new jwk set
jwk_set = self.fetch_jwk_set(force=True)
return jwk.loads(jwk_set, header.get("kid"))
return JsonWebKey.import_key_set(jwk_set).find_by_kid(kid)

metadata = self.load_server_metadata()
claims_options = {
Expand Down

0 comments on commit 0e2a1e7

Please sign in to comment.