Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JsonWebKey directly #81

Merged
merged 5 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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