Skip to content

Commit 6920102

Browse files
committed
Merge branch 'feat/async-methods' into feat/async-tests
2 parents d5782c9 + 2b77b65 commit 6920102

21 files changed

+111
-129
lines changed

descope/authmethod/enchantedlink.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,3 @@ def _compose_update_user_email_body(
228228
@staticmethod
229229
def _compose_get_session_body(pending_ref: str) -> dict:
230230
return {"pendingRef": pending_ref}
231-
232-
@staticmethod
233-
def _get_pending_ref_from_response(response: httpx.Response) -> dict:
234-
return response.json()

descope/authmethod/oauth.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,8 @@ def start(
4141
)
4242

4343
def exchange_token(self, code: str) -> Union[dict, Awaitable[dict]]:
44-
if not code:
45-
raise AuthException(
46-
400,
47-
ERROR_TYPE_INVALID_ARGUMENT,
48-
"exchange code is empty",
49-
)
50-
51-
uri = EndpointsV1.oauth_exchange_token_path
52-
response = self._auth.do_post(uri, {"code": code}, None)
53-
return futu_apply(
54-
response,
55-
lambda response: self._auth.generate_jwt_response(
56-
response.json(),
57-
response.cookies.get(REFRESH_SESSION_COOKIE_NAME, None),
58-
None,
59-
),
44+
return self._auth.exchange_token(
45+
EndpointsV1.oauth_exchange_token_path, code, None
6046
)
6147

6248
@staticmethod

descope/authmethod/password.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def sign_up(
2626
user (dict) optional: Preserve additional user metadata in the form of
2727
{"name": "Desmond Copeland", "phone": "2125551212", "email": "[email protected]"}
2828
29-
Return value (dict):
29+
Return value (Union[dict, Awaitable[dict]]):
3030
Return dict in the format
3131
{"jwts": [], "user": "", "firstSeen": "", "error": ""}
3232
Includes all the jwts tokens (session token, refresh token), token claims, and user information
@@ -71,7 +71,7 @@ def sign_in(
7171
login_id (str): The login ID of the user being validated
7272
password (str): The password to be validated
7373
74-
Return value (dict):
74+
Return value (Union[dict, Awaitable[dict]]):
7575
Return dict in the format
7676
{"jwts": [], "user": "", "firstSeen": "", "error": ""}
7777
Includes all the jwts tokens (session token, refresh token), token claims, and user information
@@ -119,7 +119,7 @@ def send_reset(
119119
if those are the chosen reset methods. See the Magic Link and Enchanted Link sections
120120
for more details.
121121
122-
Return value (dict):
122+
Return value (Union[dict, Awaitable[dict]]):
123123
Return dict in the format
124124
{"resetMethod": "", "pendingRef": "", "linkId": "", "maskedEmail": ""}
125125
The contents will differ according to the chosen reset method. 'pendingRef'
@@ -202,7 +202,7 @@ def replace(
202202
old_password (str): The user's current active password
203203
new_password (str): The new password to use
204204
205-
Return value (dict):
205+
Return value (Union[dict, Awaitable[dict]]):
206206
Return dict in the format
207207
{"jwts": [], "user": "", "firstSeen": false, "error": ""}
208208
Includes all the jwts tokens (session token, refresh token), token claims, and user information
@@ -250,7 +250,7 @@ def get_policy(self) -> Union[dict, Awaitable[dict]]:
250250
Get a subset of the password policy defined in the Descope console and enforced
251251
by Descope. The goal is to enable client-side validations to give users a better UX
252252
253-
Return value (dict):
253+
Return value (Union[dict, Awaitable[dict]]):
254254
Return dict in the format
255255
{"minLength": 8, "lowercase": true, "uppercase": true, "number": true, "nonAlphanumeric": true}
256256
minLength - the minimum length of a password

descope/authmethod/sso.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def start(
1919
"""
2020
Start tenant sso session (saml/oidc based on tenant settings)
2121
22-
Return value (dict): the redirect url for the login page
22+
Return value (Union[dict, Awaitable[dict]]): the redirect url for the login page
2323
Return dict in the format
2424
{'url': 'http://dummy.com/login..'}
2525
"""

descope/authmethod/totp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def sign_up(
2424
user (dict) optional: Preserve additional user metadata in the form of,
2525
{"name": "Desmond Copeland", "phone": "2125551212", "email": "[email protected]"}
2626
27-
Return value (dict):
27+
Return value (Union[dict, Awaitable[dict]]):
2828
Return dict in the format
2929
{"provisioningURL": "", "image": "", "key": ""}
3030
Includes 3 different ways to allow the user to save their credentials in
@@ -63,7 +63,7 @@ def sign_in_code(
6363
login_options (LoginOptions): Optional advanced controls over login parameters
6464
refresh_token: Optional refresh token is needed for specific login options
6565
66-
Return value (dict):
66+
Return value (Union[dict, Awaitable[dict]]):
6767
Return dict in the format
6868
{"jwts": [], "user": "", "firstSeen": "", "error": ""}
6969
Includes all the jwts tokens (session token, refresh token), token claims, and user information
@@ -107,7 +107,7 @@ def update_user(
107107
login_id (str): The login ID of the user whose information is being updated
108108
refresh_token (str): The session's refresh token (used for verification)
109109
110-
Return value (dict):
110+
Return value (Union[dict, Awaitable[dict]]):
111111
Return dict in the format
112112
{"provisioningURL": "", "image": "", "key": ""}
113113
Includes 3 different ways to allow the user to save their credentials in

descope/descope_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def get_matched_permissions(
125125
jwt_response (dict): The jwt_response object which includes all JWT claims information
126126
permissions (List[str]): List of permissions to validate for this jwt_response
127127
128-
Return value (List[str]): returns the list of permissions that are granted
128+
Return value (list[str]): returns the list of permissions that are granted
129129
"""
130130
return self.get_matched_tenant_permissions(jwt_response, "", permissions)
131131

@@ -177,7 +177,7 @@ def get_matched_tenant_permissions(
177177
tenant (str): TenantId
178178
permissions (List[str]): List of permissions to validate for this jwt_response
179179
180-
Return value (List[str]): returns the list of permissions that are granted
180+
Return value (list[str]): returns the list of permissions that are granted
181181
"""
182182
if not jwt_response:
183183
return []
@@ -224,7 +224,7 @@ def get_matched_roles(self, jwt_response: dict, roles: list[str]) -> list[str]:
224224
jwt_response (dict): The jwt_response object which includes all JWT claims information
225225
roles (List[str]): List of roles to validate for this jwt_response
226226
227-
Return value (List[str]): returns the list of roles that are granted
227+
Return value (list[str]): returns the list of roles that are granted
228228
"""
229229
return self.get_matched_tenant_roles(jwt_response, "", roles)
230230

@@ -274,7 +274,7 @@ def get_matched_tenant_roles(
274274
tenant (str): TenantId
275275
roles (List[str]): List of roles to validate for this jwt_response
276276
277-
Return value (List[str]): returns the list of roles that are granted
277+
Return value (list[str]): returns the list of roles that are granted
278278
"""
279279
if not jwt_response:
280280
return []
@@ -312,7 +312,7 @@ def validate_session(
312312
session_token (str): The session token to be validated
313313
audience (str|Iterable[str]|None): Optional recipients that the JWT is intended for (must be equal to the 'aud' claim on the provided token)
314314
315-
Return value (dict):
315+
Return value (Union[dict, Awaitable[dict]]):
316316
Return dict includes the session token and all JWT claims
317317
318318
Raise:
@@ -330,7 +330,7 @@ def refresh_session(
330330
refresh_token (str): The refresh token that will be used to refresh the session
331331
audience (str|Iterable[str]|None): Optional recipients that the JWT is intended for (must be equal to the 'aud' claim on the provided token)
332332
333-
Return value (dict):
333+
Return value (Union[dict, Awaitable[dict]]):
334334
Return dict includes the session token, refresh token, and all JWT claims
335335
336336
Raise:
@@ -355,7 +355,7 @@ def validate_and_refresh_session(
355355
refresh_token (str): The refresh token that will be used to refresh the session token, if needed
356356
audience (str|Iterable[str]|None): Optional recipients that the JWT is intended for (must be equal to the 'aud' claim on the provided token)
357357
358-
Return value (dict):
358+
Return value (Union[dict, Awaitable[dict]]):
359359
Return dict includes the session token, refresh token, and all JWT claims
360360
361361
Raise:
@@ -375,7 +375,7 @@ def logout(
375375
Args:
376376
refresh_token (str): The refresh token
377377
378-
Return value (httpx.Response): returns the response from the Descope server
378+
Return value (Union[httpx.Response, Awaitable[httpx.Response]]): returns the response from the Descope server
379379
380380
Raise:
381381
AuthException: Exception is raised if session is not authorized or another error occurs
@@ -401,7 +401,7 @@ def logout_all(
401401
Args:
402402
refresh_token (str): The refresh token
403403
404-
Return value (httpx.Response): returns the response from the Descope server
404+
Return value (Union[httpx.Response, Awaitable[httpx.Response]]): returns the response from the Descope server
405405
406406
Raise:
407407
AuthException: Exception is raised if session is not authorized or another error occurs
@@ -425,7 +425,7 @@ def me(self, refresh_token: str) -> Union[dict, Awaitable[dict]]:
425425
Args:
426426
refresh_token (str): The refresh token
427427
428-
Return value (dict): returns the user details from the server
428+
Return value (Union[dict, Awaitable[dict]]): returns the user details from the server
429429
(email:str, name:str, phone:str, loginIds[str], verifiedEmail:bool, verifiedPhone:bool)
430430
431431
Raise:
@@ -458,7 +458,7 @@ def my_tenants(
458458
ids (List[str]): Get the list of tenants
459459
refresh_token (str): The refresh token
460460
461-
Return value (dict): returns the tenant requested from the server
461+
Return value (Union[dict, Awaitable[dict]]): returns the tenant requested from the server
462462
(id:str, name:str, customAttributes:dict)
463463
464464
Raise:
@@ -498,7 +498,7 @@ def history(self, refresh_token: str) -> Union[list[dict], Awaitable[list[dict]]
498498
Args:
499499
refresh_token (str): The refresh token
500500
501-
Return value (List[dict]):
501+
Return value (Union[list[dict], Awaitable[list[dict]]]):
502502
Return List in the format
503503
[
504504
{
@@ -564,7 +564,7 @@ def select_tenant(
564564
refresh_token (str): The refresh token that will be used to refresh the session token, if needed
565565
tenant_id (str): The tenant id to place on JWT
566566
567-
Return value (dict):
567+
Return value (Union[dict, Awaitable[dict]]):
568568
Return dict includes the session token, refresh token, with the tenant id on the jwt
569569
570570
Raise:

descope/management/access_key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create(
3737
description (str): an optional text the access key can hold.
3838
permitted_ips: (List[str]): An optional list of IP addresses or CIDR ranges that are allowed to use the access key.
3939
40-
Return value (dict):
40+
Return value (Union[dict, Awaitable[dict]]):
4141
Return dict in the format
4242
{
4343
"key": {},
@@ -78,7 +78,7 @@ def load(
7878
Args:
7979
id (str): The id of the access key to be loaded.
8080
81-
Return value (dict):
81+
Return value (Union[dict, Awaitable[dict]]):
8282
Return dict in the format
8383
{"key": {}}
8484
Containing the loaded access key information.
@@ -103,7 +103,7 @@ def search_all_access_keys(
103103
Args:
104104
tenant_ids (List[str]): Optional list of tenant IDs to filter by
105105
106-
Return value (dict):
106+
Return value (Union[dict, Awaitable[dict]]):
107107
Return dict in the format
108108
{"keys": []}
109109
"keys" contains a list of all of the found users and their information

descope/management/audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def search(
4141
from_ts (datetime): Retrieve records newer than given time but not older than 30 days
4242
to_ts (datetime): Retrieve records older than given time
4343
44-
Return value (dict):
44+
Return value (Union[dict, Awaitable[dict]]):
4545
Return dict in the format
4646
{
4747
"audits": [

descope/management/authz.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def delete_schema(self) -> Union[None, Awaitable[None]]:
6666
def load_schema(self) -> Union[dict, Awaitable[dict]]:
6767
"""
6868
Load the schema for the project
69-
Return value (dict):
69+
Return value (Union[dict, Awaitable[dict]]):
7070
Return dict in the format of schema as above (see save_schema)
7171
Raise:
7272
AuthException: raised if load schema fails
@@ -277,7 +277,7 @@ def has_relations(
277277
"target": "the target that has the relation - usually users or other resources"
278278
}
279279
280-
Return value (List[dict]):
280+
Return value (Union[List[dict], Awaitable[List[dict]]]):
281281
Return List in the format
282282
[
283283
{
@@ -310,7 +310,7 @@ def who_can_access(
310310
relation_definition (str): the RD we are checking
311311
namespace (str): the namespace for the RD
312312
313-
Return value (List[str]): list of targets (user IDs usually that have the access)
313+
Return value (Union[List[dict], Awaitable[List[dict]]]): list of targets (user IDs usually that have the access)
314314
Raise:
315315
AuthException: raised if query fails
316316
"""
@@ -333,7 +333,7 @@ def resource_relations(
333333
Args:
334334
resource (str): the resource we are listing relations for
335335
336-
Return value (List[dict]):
336+
Return value (Union[List[dict], Awaitable[List[dict]]]):
337337
Return List of relations each in the format of a relation as documented in create_relations
338338
Raise:
339339
AuthException: raised if query fails
@@ -353,7 +353,7 @@ def targets_relations(
353353
Args:
354354
targets (List[str]): the list of targets we are returning the relations for
355355
356-
Return value (List[dict]):
356+
Return value (Union[List[dict], Awaitable[List[dict]]]):
357357
Return List of relations each in the format of a relation as documented in create_relations
358358
Raise:
359359
AuthException: raised if query fails
@@ -373,7 +373,7 @@ def what_can_target_access(
373373
Args:
374374
target (str): the target we are returning the relations for
375375
376-
Return value (List[dict]):
376+
Return value (Union[List[dict], Awaitable[List[dict]]]):
377377
Return List of relations each in the format of a relation as documented in create_relations
378378
Raise:
379379
AuthException: raised if query fails
@@ -395,7 +395,7 @@ def what_can_target_access_with_relation(
395395
relation_definition (str): the RD we are checking
396396
namespace (str): the namespace for the RD
397397
398-
Return value (List[dict]):
398+
Return value (Union[List[dict], Awaitable[List[dict]]]):
399399
Return List of relations each in the format of a relation as documented in create_relations
400400
Raise:
401401
AuthException: raised if query fails
@@ -419,7 +419,7 @@ def get_modified(
419419
Args:
420420
since (datetime): only return changes from this given datetime
421421
422-
Return value (dict):
422+
Return value (Union[dict, Awaitable[dict]]):
423423
Dict including "resources" list of strings, "targets" list of strings and "schemaChanged" bool
424424
Raise:
425425
AuthException: raised if query fails

descope/management/fga.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def check(
114114
"targetType": "the type of the target (namespace)"
115115
}
116116
117-
Return value (List[dict]):
117+
Return value (Union[List[dict], Awaitable[List[dict]]]):
118118
Return List in the format
119119
[
120120
{

0 commit comments

Comments
 (0)