Skip to content

Commit 91e673c

Browse files
authored
expose refresh token on DescopeClient, add default value to project_id (#39)
1 parent 1d40771 commit 91e673c

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

descope/auth.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Auth:
3333

3434
def __init__(
3535
self,
36-
project_id: str,
36+
project_id: str = None,
3737
public_key: str = None,
3838
skip_verify: bool = False,
3939
):
@@ -199,6 +199,14 @@ def validate_phone(method: DeliveryMethod, phone: str):
199199
400, ERROR_TYPE_INVALID_ARGUMENT, "Invalid delivery method"
200200
)
201201

202+
def refresh_token(self, refresh_token: str) -> dict:
203+
uri = Auth._compose_refresh_token_url()
204+
response = self.do_get(uri, None, None, refresh_token)
205+
206+
resp = response.json()
207+
auth_info = self._generate_auth_info(resp, refresh_token)
208+
return auth_info
209+
202210
@staticmethod
203211
def _validate_and_load_public_key(public_key) -> Tuple[str, jwt.PyJWK, str]:
204212
if isinstance(public_key, str):
@@ -338,14 +346,6 @@ def _get_default_headers(self, pswd: str = None):
338346
headers["Authorization"] = f"Basic {base64.b64encode(bytes).decode('ascii')}"
339347
return headers
340348

341-
def refresh_token(self, refresh_token: str) -> dict:
342-
uri = Auth._compose_refresh_token_url()
343-
response = self.do_get(uri, None, None, refresh_token)
344-
345-
resp = response.json()
346-
auth_info = self._generate_auth_info(resp, refresh_token)
347-
return auth_info
348-
349349
def _validate_and_load_tokens(self, session_token: str, refresh_token: str) -> dict:
350350
if not session_token:
351351
raise AuthException(

descope/descope_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DescopeClient:
1717

1818
def __init__(
1919
self,
20-
project_id: str,
20+
project_id: str = None,
2121
public_key: str = None,
2222
skip_verify: bool = False,
2323
):
@@ -106,3 +106,6 @@ def logout(self, refresh_token: str) -> requests.Response:
106106

107107
uri = EndpointsV1.logoutPath
108108
return self._auth.do_get(uri, None, None, refresh_token)
109+
110+
def refresh_token(self, refresh_token: str) -> dict:
111+
return self._auth.refresh_token(refresh_token)

samples/otp_sample_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main():
4646

4747
try:
4848
logging.info("refreshing the session token..")
49-
claims = descope_client._auth.refresh_token(refresh_token)
49+
claims = descope_client.refresh_token(refresh_token)
5050
logging.info(
5151
"going to revalidate the session with the newly refreshed token.."
5252
)

0 commit comments

Comments
 (0)