Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions descope/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Auth:

def __init__(
self,
project_id: str,
project_id: str = None,
public_key: str = None,
skip_verify: bool = False,
):
Expand Down Expand Up @@ -188,6 +188,14 @@ def validate_phone(method: DeliveryMethod, phone: str):
400, ERROR_TYPE_INVALID_ARGUMENT, "Invalid delivery method"
)

def refresh_token(self, refresh_token: str) -> dict:
uri = Auth._compose_refresh_token_url()
response = self.do_get(uri, None, None, refresh_token)

resp = response.json()
auth_info = self._generate_auth_info(resp, refresh_token)
return auth_info

@staticmethod
def _validate_and_load_public_key(public_key) -> Tuple[str, jwt.PyJWK, str]:
if isinstance(public_key, str):
Expand Down Expand Up @@ -327,14 +335,6 @@ def _get_default_headers(self, pswd: str = None):
headers["Authorization"] = f"Basic {base64.b64encode(bytes).decode('ascii')}"
return headers

def refresh_token(self, refresh_token: str) -> dict:
uri = Auth._compose_refresh_token_url()
response = self.do_get(uri, None, None, refresh_token)

resp = response.json()
auth_info = self._generate_auth_info(resp, refresh_token)
return auth_info

def _validate_and_load_tokens(self, session_token: str, refresh_token: str) -> dict:
if not session_token:
raise AuthException(
Expand Down
5 changes: 4 additions & 1 deletion descope/descope_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DescopeClient:

def __init__(
self,
project_id: str,
project_id: str = None,
public_key: str = None,
skip_verify: bool = False,
):
Expand Down Expand Up @@ -106,3 +106,6 @@ def logout(self, refresh_token: str) -> requests.Response:

uri = EndpointsV1.logoutPath
return self._auth.do_get(uri, None, None, refresh_token)

def refresh_token(self, refresh_token: str) -> dict:
return self._auth.refresh_token(refresh_token)
2 changes: 1 addition & 1 deletion samples/otp_sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():

try:
logging.info("refreshing the session token..")
claims = descope_client._auth.refresh_token(refresh_token)
claims = descope_client.refresh_token(refresh_token)
logging.info(
"going to revalidate the session with the newly refreshed token.."
)
Expand Down