Spaces:
Sleeping
Sleeping
Download app/core/cognito.py from smartjaac/backoffice: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/smartjaac/backoffice/resolve/main/app/core/cognito.py
- Command line
-
hf download hf://spaces/smartjaac/backoffice/app/core/cognito.py
-
curl -L -o cognito.py https://huggingface.co/spaces/smartjaac/backoffice/resolve/main/app/core/cognito.py
1.04 kB
| from botocore.client import BaseClient | |
| from botocore.exceptions import BotoCoreError, ClientError | |
| from dotenv import dotenv_values | |
| from fastapi import UploadFile | |
| from app.core.aws import get_session | |
| _PATH_ENV = "cognito.env" | |
| class Cognito: | |
| def client(file: UploadFile) -> BaseClient: | |
| session = get_session(_PATH_ENV, file) | |
| return session.client("cognito-idp") | |
| def auth(client: BaseClient, username: str, password: str): | |
| config = dotenv_values(dotenv_path=_PATH_ENV) | |
| try: | |
| return client.initiate_auth( | |
| ClientId=config["AWS_CLIENT_ID_COGNITO"], | |
| AuthFlow='USER_PASSWORD_AUTH', | |
| AuthParameters={ | |
| 'USERNAME': username, | |
| 'PASSWORD': password | |
| }, | |
| ) | |
| except (BotoCoreError, ClientError) as error: | |
| if isinstance(error, ClientError): | |
| return error.response | |
| else: | |
| return {"Error": error} | |