s365b.graph.auth ================ .. py:module:: s365b.graph.auth .. autoapi-nested-parse:: App-only authentication to Microsoft Graph with a certificate. Each app registration (Backup, Restore, Notifications) has its own certificate whose private key never leaves the server. Tokens are cached by MSAL and refreshed shortly before they expire. Attributes ---------- .. autoapisummary:: s365b.graph.auth.GRAPH_SCOPE Exceptions ---------- .. autoapisummary:: s365b.graph.auth.AuthError Classes ------- .. autoapisummary:: s365b.graph.auth.TokenProvider s365b.graph.auth.CertificateCredential s365b.graph.auth.StaticToken Module Contents --------------- .. py:data:: GRAPH_SCOPE :value: 'https://graph.microsoft.com/.default' .. py:exception:: AuthError Bases: :py:obj:`Exception` Raised when a token cannot be obtained. .. py:class:: TokenProvider Bases: :py:obj:`Protocol` Anything that can supply a bearer token for Graph. .. py:method:: get_token(*, force_refresh: bool = False) -> str :async: Return an access token. :param force_refresh: Ignore any cached token (used after a 401). :returns: The access token. .. py:class:: CertificateCredential(tenant_id: str, client_id: str, private_key_pem: str, certificate_pem: str, authority_host: str = 'https://login.microsoftonline.com') Client-credentials flow using a certificate (no client secret). :param tenant_id: Entra tenant ID. :param client_id: Application (client) ID of the app registration. :param private_key_pem: PEM private key matching the uploaded certificate. :param certificate_pem: PEM certificate uploaded to the app registration. :param authority_host: Login host; change only for sovereign clouds. .. py:attribute:: thumbprint .. py:attribute:: not_after .. py:method:: get_token(*, force_refresh: bool = False) -> str :async: Return an access token for Microsoft Graph. :param force_refresh: Skip MSAL's token cache. :returns: The access token. :raises AuthError: If Entra refuses the request (wrong certificate, app deleted, consent missing…). .. py:class:: StaticToken(token: str) A fixed token, for tests and one-off scripts. :param token: The access token to return. .. py:method:: get_token(*, force_refresh: bool = False) -> str :async: Return the fixed token. :param force_refresh: Ignored. :returns: The token.