Skip to content

Commit 6399f53

Browse files
authored
Merge branch 'main' into outbound-apps
2 parents 11914e4 + 6ebd3d6 commit 6399f53

File tree

7 files changed

+298
-110
lines changed

7 files changed

+298
-110
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repos:
5252
- id: tox-ini-fmt
5353
args: ["-p", "type"]
5454
- repo: https://github.com/gitleaks/gitleaks
55-
rev: v8.27.2
55+
rev: v8.28.0
5656
hooks:
5757
- id: gitleaks
5858
- repo: local

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ pip install descope[Flask]
2626
A Descope `Project ID` is required to initialize the SDK. Find it on the
2727
[project page in the Descope Console](https://app.descope.com/settings/project).
2828

29+
**Note:** Authentication APIs public access can be disabled via the Descope console.
30+
If disabled, it's still possible to use the authentication API by providing a management key with
31+
the appropriate access (`Authentication` / `Full Access`).
32+
If not provided directly, this value is retrieved from the `DESCOPE_AUTH_MANAGEMENT_KEY` environment variable instead.
33+
If neither values are set then any disabled authentication methods API calls will fail.
34+
2935
```python
3036
from descope import DescopeClient
3137

32-
# Initialized after setting the DESCOPE_PROJECT_ID env var
38+
# Initialized after setting the DESCOPE_PROJECT_ID and DESCOPE_AUTH_MANAGEMENT_KEY env vars
3339
descope_client = DescopeClient()
3440

3541
# ** Or directly **
36-
descope_client = DescopeClient(project_id="<Project ID>")
42+
descope_client = DescopeClient(
43+
project_id="<Project ID>"
44+
auth_management_key="<Auth Managemet Key>
45+
)
3746
```
3847

3948
## Authentication Functions

descope/auth.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(
7373
management_key: str | None = None,
7474
timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS,
7575
jwt_validation_leeway: int = 5,
76+
auth_management_key: str | None = None,
7677
):
7778
self.lock_public_keys = Lock()
7879
# validate project id
@@ -95,6 +96,9 @@ def __init__(
9596
self.base_url = self.base_url_for_project_id(self.project_id)
9697
self.timeout_seconds = timeout_seconds
9798
self.management_key = management_key or os.getenv("DESCOPE_MANAGEMENT_KEY")
99+
self.auth_management_key = auth_management_key or os.getenv(
100+
"DESCOPE_AUTH_MANAGEMENT_KEY"
101+
)
98102

99103
public_key = public_key or os.getenv("DESCOPE_PUBLIC_KEY")
100104
with self.lock_public_keys:
@@ -498,7 +502,9 @@ def adjust_properties(self, jwt_response: dict, user_jwt: bool):
498502
] # support both url issuer and project ID issuer
499503

500504
sub = (
501-
jwt_response.get(SESSION_TOKEN_NAME, {}).get("sub", None)
505+
jwt_response.get(SESSION_TOKEN_NAME, {}).get("dsub", None)
506+
or jwt_response.get(SESSION_TOKEN_NAME, {}).get("sub", None)
507+
or jwt_response.get(REFRESH_SESSION_TOKEN_NAME, {}).get("dsub", None)
502508
or jwt_response.get(REFRESH_SESSION_TOKEN_NAME, {}).get("sub", None)
503509
or jwt_response.get("sub", "")
504510
)
@@ -564,6 +570,8 @@ def _get_default_headers(self, pswd: str | None = None):
564570
bearer = self.project_id
565571
if pswd:
566572
bearer = f"{self.project_id}:{pswd}"
573+
if self.auth_management_key:
574+
bearer = f"{bearer}:{self.auth_management_key}"
567575
headers["Authorization"] = f"Bearer {bearer}"
568576
return headers
569577

descope/descope_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
management_key: str | None = None,
3131
timeout_seconds: float = DEFAULT_TIMEOUT_SECONDS,
3232
jwt_validation_leeway: int = 5,
33+
auth_management_key: str | None = None,
3334
):
3435
auth = Auth(
3536
project_id,
@@ -38,6 +39,7 @@ def __init__(
3839
management_key,
3940
timeout_seconds,
4041
jwt_validation_leeway,
42+
auth_management_key,
4143
)
4244
self._auth = auth
4345
self._mgmt = MGMT(auth)

0 commit comments

Comments
 (0)