Created
November 16, 2023 23:18
-
-
Save tsibley/b95deed16af217bf7cb3f40bdd48f12f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CognitoSession: | |
def __init__(self, origin: Origin) -> None: | |
assert origin | |
self.origin = origin | |
# Public ids. Client id is specific to the CLI. | |
user_pool_id = os.environ.get("NEXTSTRAIN_COGNITO_USER_POOL_ID") \ | |
or client_config(origin)["aws_cognito_user_pool_id"] | |
client_id = os.environ.get("NEXTSTRAIN_COGNITO_CLI_CLIENT_ID") \ | |
or client_config(origin)["client_id"] | |
assert user_pool_id | |
assert client_id | |
self._session = cognito.Session(user_pool_id, client_id) | |
def authenticate_with_password(self, username: str, password: str) -> None: | |
self._session.authenticate(username, password) | |
def authenticate_with_browser(self) -> None: | |
raise NotImplementedError | |
def verify_tokens(self, *, id_token: str, access_token: str, refresh_token: str) -> None: | |
self._session.verify_tokens( | |
id_token = id_token | |
access_token = access_token | |
refresh_token = refresh_token) | |
def renew_tokens(self, *, refresh_token: str) -> None: | |
self._session.renew_tokens(refresh_token = refresh_token) | |
@property | |
def id_token(self) -> Optional[str]: | |
return self._session.id_token | |
@property | |
def id_claims(self) -> Optional[Mapping[str, Any]]: | |
return self._session.id_claims | |
@property | |
def access_token(self) -> Optional[str]: | |
return self._session.access_token | |
@property | |
def refresh_token(self) -> Optional[str]: | |
return self._session.refresh_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment