@@ -28,15 +28,9 @@ def __init__(
2828 self .session_data = session_data
2929 self .cookie_password = cookie_password
3030
31- self .jwks = self .create_remote_jwk_set (
32- self .user_management .get_jwks_url ()
33- )
34- self .jwk_algorithms = [str (key .Algorithm ) for key in self .jwks ]
31+ self .jwks = PyJWKClient (self .user_management .get_jwks_url ())
3532
36- for key in self .jwks :
37- print ("Key properties:" , dir (key )) # This will show all available attributes
38- print ("Algorithm:" , key .Algorithm )
39- print ("Key type:" , key .key_type )
33+ self .jwk_algorithms = ['RS256' ]
4034
4135 def authenticate (
4236 self ,
@@ -66,19 +60,20 @@ def authenticate(
6660 authenticated = False , reason = AuthenticateWithSessionCookieFailureReason .INVALID_JWT
6761 )
6862
63+ signing_key = self .jwks .get_signing_key_from_jwt (session ["access_token" ])
6964 decoded = jwt .decode (
70- session ["access_token" ], self . jwks , algorithms = self .jwk_algorithms
65+ session ["access_token" ], signing_key . key , algorithms = self .jwk_algorithms
7166 )
7267
7368 return AuthenticateWithSessionCookieSuccessResponse (
7469 authenticated = True ,
7570 session_id = decoded ["sid" ],
76- organization_id = decoded [ "org_id" ] ,
77- role = decoded [ "role" ] ,
78- permissions = decoded [ "permissions" ] ,
79- entitlements = decoded [ "entitlements" ] ,
71+ organization_id = decoded . get ( "org_id" , None ) ,
72+ role = decoded . get ( "role" , None ) ,
73+ permissions = decoded . get ( "permissions" , None ) ,
74+ entitlements = decoded . get ( "entitlements" , None ) ,
8075 user = session ["user" ],
81- impersonator = session [ "impersonator" ] ,
76+ impersonator = session . get ( "impersonator" , None ) ,
8277 reason = None ,
8378 )
8479
@@ -131,13 +126,10 @@ def get_logout_url(self) -> str:
131126 session_id = auth_response ["session_id" ]
132127 )
133128
134- def create_remote_jwk_set (self , url : str ) -> List [Dict [str , Any ]]:
135- jwks_client = PyJWKClient (url )
136- return jwks_client .get_signing_keys ()
137-
138129 def is_valid_jwt (self , token : str ) -> bool :
139130 try :
140- jwt .decode (token , self .jwks , algorithms = self .jwk_algorithms )
131+ signing_key = self .jwks .get_signing_key_from_jwt (token )
132+ jwt .decode (token , signing_key .key , algorithms = self .jwk_algorithms )
141133 return True
142134 except jwt .exceptions .InvalidTokenError as error :
143135 print ("invalid token" , error )
0 commit comments