Spaces:
Sleeping
Sleeping
Download app/lib/graph/auth.py from cmoss3/RcmEmailAutomation: direct link, hf CLI and curl.
- Browser
- Download file 890 Bytes
-
https://huggingface.co/spaces/cmoss3/RcmEmailAutomation/resolve/main/app/lib/graph/auth.py
- Command line
-
hf download hf://spaces/cmoss3/RcmEmailAutomation/app/lib/graph/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/cmoss3/RcmEmailAutomation/resolve/main/app/lib/graph/auth.py
890 Bytes
| import msal | |
| from app.config import Settings | |
| class GraphAuthProvider: | |
| _SCOPE = ["https://graph.microsoft.com/.default"] | |
| def __init__(self, settings: Settings) -> None: | |
| self._app = msal.ConfidentialClientApplication( | |
| client_id=settings.azure_client_id, | |
| authority=f"https://login.microsoftonline.com/{settings.azure_tenant_id}", | |
| client_credential=settings.azure_client_secret.get_secret_value(), | |
| ) | |
| def get_access_token(self) -> str: | |
| result = self._app.acquire_token_silent(self._SCOPE, account=None) | |
| if not result: | |
| result = self._app.acquire_token_for_client(scopes=self._SCOPE) | |
| if "access_token" not in result: | |
| raise RuntimeError( | |
| f"MSAL token error: {result.get('error_description', result.get('error'))}" | |
| ) | |
| return result["access_token"] | |