Skip to content

Commit 11914e4

Browse files
committed
Add fetching outbound token by using inbound app token + fix linting
1 parent c836fd9 commit 11914e4

File tree

20 files changed

+716
-104
lines changed

20 files changed

+716
-104
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,46 @@ latest_tenant_token = descope_client.mgmt.outbound_application.fetch_tenant_toke
14251425
)
14261426
```
14271427

1428+
Fetch outbound application tokens using an inbound application token that includes the "outbound.token.fetch" scope (no management key required)
1429+
1430+
```python
1431+
# Fetch user token with specific scopes
1432+
user_token = descope_client.mgmt.outbound_application_by_token.fetch_token_by_scopes(
1433+
"inbound-app-token",
1434+
"my-app-id",
1435+
"user-id",
1436+
["read", "write"],
1437+
{"refreshToken": True}, # Optional
1438+
"tenant-id" # Optional
1439+
)
1440+
1441+
# Fetch latest user token
1442+
latest_user_token = descope_client.mgmt.outbound_application_by_token.fetch_token(
1443+
"inbound-app-token",
1444+
"my-app-id",
1445+
"user-id",
1446+
"tenant-id", # Optional
1447+
{"forceRefresh": True} # Optional
1448+
)
1449+
1450+
# Fetch tenant token with specific scopes
1451+
tenant_token = descope_client.mgmt.outbound_application_by_token.fetch_tenant_token_by_scopes(
1452+
"inbound-app-token",
1453+
"my-app-id",
1454+
"tenant-id",
1455+
["read", "write"],
1456+
{"refreshToken": True} # Optional
1457+
)
1458+
1459+
# Fetch latest tenant token
1460+
latest_tenant_token = descope_client.mgmt.outbound_application_by_token.fetch_tenant_token(
1461+
"inbound-app-token",
1462+
"my-app-id",
1463+
"tenant-id",
1464+
{"forceRefresh": True} # Optional
1465+
)
1466+
```
1467+
14281468
### Utils for your end to end (e2e) tests and integration tests
14291469

14301470
To ease your e2e tests, we exposed dedicated management methods,

descope/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _raise_rate_limit_exception(self, response):
120120
)
121121
except RateLimitException:
122122
raise
123-
except Exception as e:
123+
except Exception:
124124
raise RateLimitException(
125125
status_code=HTTPStatus.TOO_MANY_REQUESTS,
126126
error_type=ERROR_TYPE_API_RATE_LIMIT,

descope/authmethod/enchantedlink.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ def update_user_email(
118118
Auth.validate_email(email)
119119

120120
body = EnchantedLink._compose_update_user_email_body(
121-
login_id, email, add_to_login_ids, on_merge_use_existing,
122-
template_options, template_id, provider_id
121+
login_id,
122+
email,
123+
add_to_login_ids,
124+
on_merge_use_existing,
125+
template_options,
126+
template_id,
127+
provider_id,
123128
)
124129
uri = EndpointsV1.update_user_email_enchantedlink_path
125130
response = self._auth.do_post(uri, body, None, refresh_token)

descope/authmethod/magiclink.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ def update_user_email(
117117
Auth.validate_email(email)
118118

119119
body = MagicLink._compose_update_user_email_body(
120-
login_id, email, add_to_login_ids, on_merge_use_existing,
121-
template_options, template_id, provider_id
120+
login_id,
121+
email,
122+
add_to_login_ids,
123+
on_merge_use_existing,
124+
template_options,
125+
template_id,
126+
provider_id,
122127
)
123128
uri = EndpointsV1.update_user_email_magiclink_path
124129
response = self._auth.do_post(uri, body, None, refresh_token)
@@ -144,8 +149,13 @@ def update_user_phone(
144149
Auth.validate_phone(method, phone)
145150

146151
body = MagicLink._compose_update_user_phone_body(
147-
login_id, phone, add_to_login_ids, on_merge_use_existing,
148-
template_options, template_id, provider_id
152+
login_id,
153+
phone,
154+
add_to_login_ids,
155+
on_merge_use_existing,
156+
template_options,
157+
template_id,
158+
provider_id,
149159
)
150160
uri = EndpointsV1.update_user_phone_magiclink_path
151161
response = self._auth.do_post(uri, body, None, refresh_token)

descope/authmethod/otp.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ def update_user_email(
198198

199199
uri = EndpointsV1.update_user_email_otp_path
200200
body = OTP._compose_update_user_email_body(
201-
login_id, email, add_to_login_ids, on_merge_use_existing,
202-
template_options, template_id, provider_id
201+
login_id,
202+
email,
203+
add_to_login_ids,
204+
on_merge_use_existing,
205+
template_options,
206+
template_id,
207+
provider_id,
203208
)
204209
response = self._auth.do_post(uri, body, None, refresh_token)
205210
return Auth.extract_masked_address(response.json(), DeliveryMethod.EMAIL)
@@ -241,8 +246,13 @@ def update_user_phone(
241246

242247
uri = OTP._compose_update_phone_url(method)
243248
body = OTP._compose_update_user_phone_body(
244-
login_id, phone, add_to_login_ids, on_merge_use_existing,
245-
template_options, template_id, provider_id
249+
login_id,
250+
phone,
251+
add_to_login_ids,
252+
on_merge_use_existing,
253+
template_options,
254+
template_id,
255+
provider_id,
246256
)
247257
response = self._auth.do_post(uri, body, None, refresh_token)
248258
return Auth.extract_masked_address(response.json(), method)

descope/descope_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def __init__(
5353

5454
@property
5555
def mgmt(self):
56-
if not self._auth.management_key:
57-
raise AuthException(
58-
400, ERROR_TYPE_INVALID_ARGUMENT, "management_key cannot be empty"
59-
)
6056
return self._mgmt
6157

6258
@property

descope/flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid
55
from functools import wraps
66

7-
from flask import Response, redirect, request, g
7+
from flask import Response, g, redirect, request
88

99
from .. import (
1010
COOKIE_DATA_NAME,

descope/management/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import List, Optional, Dict, Any
21
from enum import Enum
2+
from typing import List, Optional
33

44

55
class AccessType(Enum):

descope/management/fga.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from datetime import datetime, timezone
2-
from typing import Any, List, Optional
1+
from typing import List
32

43
from descope._auth_base import AuthBase
54
from descope.management.common import MgmtV1

descope/management/jwt.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def impersonate(
8787
pswd=self._auth.management_key,
8888
)
8989
return response.json().get("jwt", "")
90-
90+
9191
def stop_impersonation(
9292
self,
9393
jwt: str,
@@ -109,9 +109,7 @@ def stop_impersonation(
109109
AuthException: raised if update failed
110110
"""
111111
if not jwt or jwt == "":
112-
raise AuthException(
113-
400, ERROR_TYPE_INVALID_ARGUMENT, "jwt cannot be empty"
114-
)
112+
raise AuthException(400, ERROR_TYPE_INVALID_ARGUMENT, "jwt cannot be empty")
115113

116114
response = self._auth.do_post(
117115
MgmtV1.stop_impersonation_path,

0 commit comments

Comments
 (0)