s365b.setup.devicecode ====================== .. py:module:: s365b.setup.devicecode .. autoapi-nested-parse:: OAuth 2.0 device authorisation grant against Entra ID. Implemented directly on ``httpx`` (two endpoints) so polling is async and the flow state can live in the database between UI requests. Attributes ---------- .. autoapisummary:: s365b.setup.devicecode.LOGIN s365b.setup.devicecode.DEFAULT_PUBLIC_CLIENT_ID s365b.setup.devicecode.SETUP_SCOPES Exceptions ---------- .. autoapisummary:: s365b.setup.devicecode.DeviceCodeError Classes ------- .. autoapisummary:: s365b.setup.devicecode.DeviceCode s365b.setup.devicecode.DeviceCodeClient Module Contents --------------- .. py:data:: LOGIN :value: 'https://login.microsoftonline.com' .. py:data:: DEFAULT_PUBLIC_CLIENT_ID :value: '14d82eec-204b-4c2f-b7e8-296a70dab67e' .. py:data:: SETUP_SCOPES :value: ('https://graph.microsoft.com/Application.ReadWrite.All',... .. py:exception:: DeviceCodeError(code: str, message: str) Bases: :py:obj:`Exception` The device code flow failed. The message is safe to show. :param code: OAuth error code (``expired_token``, ``authorization_declined``…). :param message: Explanation for the admin. .. py:attribute:: code .. py:class:: DeviceCode A pending device code sign-in. :ivar device_code: Secret polling handle (keep server-side). :ivar user_code: Code the admin types at the verification URL. :ivar verification_uri: Where to type it. :ivar interval: Minimum seconds between polls. :ivar expires_at: When the code stops working. .. py:attribute:: device_code :type: str .. py:attribute:: user_code :type: str .. py:attribute:: verification_uri :type: str .. py:attribute:: interval :type: int .. py:attribute:: expires_at :type: datetime.datetime .. py:class:: DeviceCodeClient(client_id: str = DEFAULT_PUBLIC_CLIENT_ID, *, tenant: str = 'organizations', http: httpx.AsyncClient | None = None) Starts and polls device code sign-ins. :param client_id: Public client application ID. :param tenant: ``organizations`` (any work account) or a tenant ID. :param http: HTTP client (replaced in tests). .. py:attribute:: client_id :value: '14d82eec-204b-4c2f-b7e8-296a70dab67e' .. py:method:: aclose() -> None :async: Close the HTTP client. .. py:method:: start(scopes: tuple[str, ...] = SETUP_SCOPES) -> DeviceCode :async: Request a device code. :param scopes: Delegated scopes to request. :returns: The pending sign-in. :raises DeviceCodeError: If Entra refuses (unknown client, bad scope…). .. py:method:: poll(device_code: str) -> str | None :async: Ask once whether the admin has finished signing in. :param device_code: From :meth:`start`. :returns: The access token, or ``None`` while the sign-in is still pending. :raises DeviceCodeError: If the sign-in was declined, expired or blocked.