Skip to content

Commit 8f1ec0c

Browse files
committed
lol camel case
1 parent c199df3 commit 8f1ec0c

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

workos/session.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

workos/types/user_management/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class AuthenticateWithSessionCookieFailureReason(Enum):
1212

1313
class AuthenticateWithSessionCookieSuccessResponse(WorkOSModel):
1414
authenticated: bool = True
15-
sessionId: str
16-
organizationId: Optional[str] = None
15+
session_id: str
16+
organization_id: Optional[str] = None
1717
role: Optional[str] = None
1818
permissions: Optional[List[str]] = None
1919
user: User

0 commit comments

Comments
 (0)