Skip to content

Commit 28c2130

Browse files
committed
Satisfy type checker
1 parent 25e6e5a commit 28c2130

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

workos/session.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
from __future__ import annotations
2+
from typing import TYPE_CHECKING
3+
24
import json
35
from typing import Any, Dict, Optional, Union, cast
46
import jwt
57
from jwt import PyJWKClient
68
from cryptography.fernet import Fernet
79

10+
from workos.types.user_management.authentication_response import (
11+
RefreshTokenAuthenticationResponse,
12+
)
813
from workos.types.user_management.session import (
914
AuthenticateWithSessionCookieFailureReason,
1015
AuthenticateWithSessionCookieSuccessResponse,
1116
AuthenticateWithSessionCookieErrorResponse,
1217
RefreshWithSessionCookieErrorResponse,
1318
RefreshWithSessionCookieSuccessResponse,
1419
)
15-
from workos.user_management import UserManagementModule
20+
21+
if TYPE_CHECKING:
22+
from workos.user_management import UserManagementModule
1623

1724

1825
class Session:
@@ -114,14 +121,19 @@ def refresh(
114121
)
115122

116123
try:
117-
auth_response = self.user_management.authenticate_with_refresh_token(
118-
refresh_token=session["refresh_token"],
119-
organization_id=organization_id,
120-
session={"seal_session": True, "cookie_password": cookie_password},
124+
auth_response = cast(
125+
RefreshTokenAuthenticationResponse,
126+
self.user_management.authenticate_with_refresh_token(
127+
refresh_token=session["refresh_token"],
128+
organization_id=organization_id,
129+
session={"seal_session": True, "cookie_password": cookie_password},
130+
),
121131
)
122132

123-
self.session_data = auth_response.sealed_session
124-
self.cookie_password = cookie_password
133+
self.session_data = str(auth_response.sealed_session)
134+
self.cookie_password = (
135+
cookie_password if cookie_password is not None else self.cookie_password
136+
)
125137

126138
signing_key = self.jwks.get_signing_key_from_jwt(auth_response.access_token)
127139

@@ -133,7 +145,7 @@ def refresh(
133145

134146
return RefreshWithSessionCookieSuccessResponse(
135147
authenticated=True,
136-
sealed_session=auth_response.sealed_session,
148+
sealed_session=str(auth_response.sealed_session),
137149
session_id=decoded["sid"],
138150
organization_id=decoded.get("org_id", None),
139151
role=decoded.get("role", None),

0 commit comments

Comments
 (0)