Skip to content

Commit 6c2be90

Browse files
committed
Trying to fix python version compatibility
1 parent 8476f54 commit 6c2be90

File tree

10 files changed

+45
-32
lines changed

10 files changed

+45
-32
lines changed

descope/auth.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
import re
77
from http import HTTPStatus
88
from threading import Lock
9-
from typing import Iterable
9+
from typing import Iterable, Optional
1010

1111
import jwt
1212
from email_validator import EmailNotValidError, validate_email
1313
from jwt import ExpiredSignatureError, ImmatureSignatureError
1414

1515
from descope.common import (
16-
COOKIE_DATA_NAME,
1716
DEFAULT_BASE_URL,
1817
DEFAULT_DOMAIN,
1918
DEFAULT_URL_PREFIX,
2019
PHONE_REGEX,
2120
REFRESH_SESSION_COOKIE_NAME,
22-
REFRESH_SESSION_TOKEN_NAME,
2321
SESSION_TOKEN_NAME,
2422
AccessKeyLoginOptions,
2523
DeliveryMethod,
@@ -47,8 +45,8 @@ class Auth:
4745

4846
def __init__(
4947
self,
50-
project_id: str | None = None,
51-
public_key: dict | str | None = None,
48+
project_id: Optional[str] = None,
49+
public_key: Optional[dict | str] = None,
5250
jwt_validation_leeway: int = 5,
5351
*,
5452
http_client: HTTPClient,
@@ -114,7 +112,7 @@ def http_client(self) -> HTTPClient:
114112
return self._http
115113

116114
def exchange_token(
117-
self, uri, code: str, audience: str | None | Iterable[str] = None
115+
self, uri, code: str, audience: Optional[Iterable[str] | str] = None
118116
) -> dict:
119117
if not code:
120118
raise AuthException(

descope/descope_client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import os
4-
from typing import Iterable
4+
from typing import Iterable, Optional
55

66
import requests
77

@@ -27,10 +27,10 @@ class DescopeClient:
2727
def __init__(
2828
self,
2929
project_id: str,
30-
public_key: dict | None = None,
30+
public_key: Optional[dict] = None,
3131
skip_verify: bool = False,
32-
management_key: str | None = None,
33-
auth_management_key: str | None = None,
32+
management_key: Optional[str] = None,
33+
auth_management_key: Optional[str] = None,
3434
timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS,
3535
jwt_validation_leeway: int = 5,
3636
):
@@ -310,7 +310,7 @@ def get_matched_tenant_roles(
310310
return matched
311311

312312
def validate_session(
313-
self, session_token: str, audience: str | Iterable[str] | None = None
313+
self, session_token: str, audience: Optional[Iterable[str] | str] = None
314314
) -> dict:
315315
"""
316316
Validate a session token. Call this function for every incoming request to your
@@ -333,7 +333,7 @@ def validate_session(
333333
return self._auth.validate_session(session_token, audience)
334334

335335
def refresh_session(
336-
self, refresh_token: str, audience: str | Iterable[str] | None = None
336+
self, refresh_token: str, audience: Optional[Iterable[str] | str] = None
337337
) -> dict:
338338
"""
339339
Refresh a session. Call this function when a session expires and needs to be refreshed.
@@ -354,7 +354,7 @@ def validate_and_refresh_session(
354354
self,
355355
session_token: str,
356356
refresh_token: str,
357-
audience: str | Iterable[str] | None = None,
357+
audience: Optional[Iterable[str] | str] = None,
358358
) -> dict:
359359
"""
360360
Validate the session token and refresh it if it has expired, the session token will automatically be refreshed.
@@ -454,7 +454,7 @@ def my_tenants(
454454
self,
455455
refresh_token: str,
456456
dct: bool = False,
457-
ids: list[str] | None = None,
457+
ids: Optional[list[str]] = None,
458458
) -> dict:
459459
"""
460460
Retrieve tenant attributes that user belongs to, one of dct/ids must be populated .
@@ -535,8 +535,8 @@ def history(self, refresh_token: str) -> list[dict]:
535535
def exchange_access_key(
536536
self,
537537
access_key: str,
538-
audience: str | Iterable[str] | None = None,
539-
login_options: AccessKeyLoginOptions | None = None,
538+
audience: Optional[Iterable[str] | str] = None,
539+
login_options: Optional[AccessKeyLoginOptions] = None,
540540
) -> dict:
541541
"""
542542
Return a new session token for the given access key

descope/http_client.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import platform
55
from http import HTTPStatus
6+
from typing import Optional, Union
67

78
try:
89
from importlib.metadata import version
@@ -45,11 +46,11 @@ class HTTPClient:
4546
def __init__(
4647
self,
4748
project_id: str,
48-
base_url: str | None = None,
49+
base_url: Optional[str] = None,
4950
*,
5051
timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS,
5152
secure: bool = True,
52-
management_key: str | None = None,
53+
management_key: Optional[str] = None,
5354
) -> None:
5455
if not project_id:
5556
raise AuthException(
@@ -73,8 +74,8 @@ def get(
7374
uri: str,
7475
*,
7576
params=None,
76-
allow_redirects: bool | None = None,
77-
pswd: str | None = None,
77+
allow_redirects: Optional[bool] = None,
78+
pswd: Optional[str] = None,
7879
) -> requests.Response:
7980
response = requests.get(
8081
f"{self.base_url}{uri}",
@@ -91,9 +92,9 @@ def post(
9192
self,
9293
uri: str,
9394
*,
94-
body: dict | list[dict] | list[str] | None = None,
95+
body: Optional[Union[dict, list[dict], list[str]]] = None,
9596
params=None,
96-
pswd: str | None = None,
97+
pswd: Optional[str] = None,
9798
) -> requests.Response:
9899
response = requests.post(
99100
f"{self.base_url}{uri}",
@@ -111,9 +112,9 @@ def patch(
111112
self,
112113
uri: str,
113114
*,
114-
body: dict | list[dict] | list[str] | None,
115+
body: Optional[Union[dict, list[dict], list[str]]],
115116
params=None,
116-
pswd: str | None = None,
117+
pswd: Optional[str] = None,
117118
) -> requests.Response:
118119
response = requests.patch(
119120
f"{self.base_url}{uri}",
@@ -132,7 +133,7 @@ def delete(
132133
uri: str,
133134
*,
134135
params=None,
135-
pswd: str | None = None,
136+
pswd: Optional[str] = None,
136137
) -> requests.Response:
137138
response = requests.delete(
138139
f"{self.base_url}{uri}",
@@ -145,7 +146,7 @@ def delete(
145146
self._raise_from_response(response)
146147
return response
147148

148-
def get_default_headers(self, pswd: str | None = None) -> dict:
149+
def get_default_headers(self, pswd: Optional[str] = None) -> dict:
149150
return self._get_default_headers(pswd)
150151

151152
# ------------- helpers -------------
@@ -197,7 +198,7 @@ def _raise_from_response(self, response):
197198
response.text,
198199
)
199200

200-
def _get_default_headers(self, pswd: str | None = None):
201+
def _get_default_headers(self, pswd: Optional[str] = None):
201202
headers = _default_headers.copy()
202203
headers["x-descope-project-id"] = self.project_id
203204
bearer = self.project_id

descope/management/audit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24
from typing import Any, List, Optional
35

descope/management/authz.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime, timezone
24
from typing import Any, List, Optional
35

descope/management/outbound_application.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any, List, Optional
24

35
from descope._http_base import HTTPBase
@@ -19,7 +21,7 @@ class _OutboundApplicationTokenFetcher:
1921
def fetch_token_by_scopes(
2022
*,
2123
http: HTTPClient,
22-
token: str | None = None,
24+
token: Optional[str] = None,
2325
app_id: str,
2426
user_id: str,
2527
scopes: List[str],
@@ -45,7 +47,7 @@ def fetch_token_by_scopes(
4547
def fetch_token(
4648
*,
4749
http: HTTPClient,
48-
token: str | None = None,
50+
token: Optional[str] = None,
4951
app_id: str,
5052
user_id: str,
5153
tenant_id: Optional[str] = None,
@@ -69,7 +71,7 @@ def fetch_token(
6971
def fetch_tenant_token_by_scopes(
7072
*,
7173
http: HTTPClient,
72-
token: str | None = None,
74+
token: Optional[str] = None,
7375
app_id: str,
7476
tenant_id: str,
7577
scopes: List[str],
@@ -93,7 +95,7 @@ def fetch_tenant_token_by_scopes(
9395
def fetch_tenant_token(
9496
*,
9597
http: HTTPClient,
96-
token: str | None = None,
98+
token: Optional[str] = None,
9799
app_id: str,
98100
tenant_id: str,
99101
options: Optional[dict] = None,

descope/management/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import List, Optional
24

35
from descope._http_base import HTTPBase

descope/management/role.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import List, Optional
24

35
from descope._http_base import HTTPBase

descope/management/sso_application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any, List, Optional
24

35
from descope._http_base import HTTPBase

tests/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import platform
35
import unittest
@@ -47,7 +49,7 @@ def setUp(self) -> None:
4749
)
4850

4951
# Test helper to build a default HTTP client
50-
def make_http_client(self, management_key: str | None = None):
52+
def make_http_client(self, management_key: "str | None" = None):
5153
from descope.http_client import HTTPClient
5254

5355
return HTTPClient(

0 commit comments

Comments
 (0)