Ë
    kQêjÝ'  ã                   ó°   — d dl mZmZ d dlmZ d dlmZmZ  G d„ dee«      Z	 G d„ dee«      Z
e G d„ d	«      «       Ze G d
„ d«      «       Z G d„ d«      Zy)é    )Ú	dataclassÚfield)ÚEnum)ÚListÚOptionalc                   ó&   — e Zd ZdZdZ	 dZ	 dZ	 dZy)ÚOAuthFlowTypez OAuth authentication flow types.Úclient_credentialsÚauthorization_codeÚdevice_codeÚazure_managed_identityN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚCLIENT_CREDENTIALSÚAUTHORIZATION_CODEÚDEVICE_CODEÚAZURE_MANAGED_IDENTITY© ó    úY/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/remote/oauth.pyr	   r	   	   s(   „ Ù*à-ÐØ>à-ÐØFà€KØGà5ÐØ*r   r	   c                   ó    — e Zd ZdZdZ	 dZ	 dZy)ÚClientAuthMethoda5  How the client authenticates to the OAuth token endpoint.

    The method applies to every OAuth request that carries client
    authentication: client-credentials, authorization-code exchange,
    refresh-token, and device-authorization requests. The Azure managed
    identity flow ignores this option.
    ÚnoneÚclient_secret_basicÚclient_secret_postN)r   r   r   r   ÚNONEÚCLIENT_SECRET_BASICÚCLIENT_SECRET_POSTr   r   r   r   r      s-   „ ñð €Dð8ð 0Ðð1ð .Ðð'r   r   c                   ó:   — e Zd ZU dZdZee   ed<   dZee	   ed<   y)ÚTokenCacheOptionsaG  Options for the persistent OAuth token cache.

    The cache is opt-in: it is only used when set as ``token_cache`` on
    :class:`OAuthConfig`. Only refresh tokens are persisted, in a private
    directory with owner-only permissions, so short-lived processes can reuse
    an authenticated session instead of re-prompting on every start.

    Parameters
    ----------
    cache_dir : Optional[str]
        Directory that holds cached credentials. Defaults to
        ``$XDG_CACHE_HOME/lancedb/oauth``, ``$HOME/.cache/lancedb/oauth`` on
        Unix, or ``%LOCALAPPDATA%\lancedb\oauth`` on Windows. The directory
        is created with owner-only permissions (``0700``) when missing.
    lock_timeout_secs : Optional[int]
        How long to wait for the cross-process refresh lock before failing
        (default: 30 seconds).

    Examples
    --------
    >>> opts = TokenCacheOptions(cache_dir="/tmp/my-app/oauth-cache")

    Multiple identities (issuer, client, scopes, flow, client
    authentication) get separate cache entries. Within one identity the most
    recent login wins.
    NÚ	cache_dirÚlock_timeout_secs)
r   r   r   r   r#   r   ÚstrÚ__annotations__r$   Úintr   r   r   r"   r"   0   s&   … ñð6  $€Iˆx˜‰}Ó#Ø'+Ð�x ‘}Ô+r   r"   c                   ó*  — e Zd ZU dZeed<   eed<   ee   ed<   ej                  Z	eed<    e
dd¬«      Zee   ed	<   dZee   ed
<   dZee   ed<   dZee   ed<   dZeed<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   y)ÚOAuthConfigaB  OAuth configuration for LanceDB authentication.

    All token acquisition and refresh is handled in the Rust layer.
    This config is passed through to Rust via PyO3.

    Parameters
    ----------
    issuer_url : str
        OIDC issuer URL or OAuth authority URL.
        For Azure: ``https://login.microsoftonline.com/{tenant_id}/v2.0``
    client_id : str
        Application / Client ID.
    scopes : List[str]
        OAuth scopes to request.
        For Azure managed identity, exactly one scope or resource is required.
        For example: ``["api://{app_id}/.default"]``
    flow : OAuthFlowType
        Authentication flow to use. Default: CLIENT_CREDENTIALS.
    client_secret : Optional[str]
        Client secret (required for CLIENT_CREDENTIALS).
    client_auth_method : Optional[ClientAuthMethod]
        How the client authenticates to the token endpoint (default: auto).
        With a ``client_secret`` the default is
        ``ClientAuthMethod.CLIENT_SECRET_BASIC``, which matches the RFC 6749
        recommendation and the default configuration of Okta confidential
        applications; without a secret the client is public and no client
        authentication is sent.
    redirect_uri : Optional[str]
        Loopback redirect URI for AUTHORIZATION_CODE. The default is
        ``http://127.0.0.1:{callback_port}/callback``.
    callback_port : Optional[int]
        Port for the AUTHORIZATION_CODE loopback callback server (default: 8400).
    use_pkce : bool
        Protect AUTHORIZATION_CODE with S256 PKCE (default: True).
    managed_identity_client_id : Optional[str]
        Client ID for user-assigned managed identity (AZURE_MANAGED_IDENTITY).
    resource : Optional[str]
        Resource indicator (RFC 8707), forwarded verbatim to authorization and
        token endpoints, including refresh requests. Must be an absolute URI
        without a fragment. Not supported for Azure managed identity.
    audience : Optional[str]
        Provider-specific audience, forwarded to authorization and token
        endpoints, including refresh requests. Not supported for Azure managed identity.
    refresh_buffer_secs : Optional[int]
        Seconds before expiry to trigger proactive refresh (default: 300).
        Keep this well below the token TTL; if it is greater than or equal to
        the TTL, each request refreshes the token.
    token_cache : Optional[TokenCacheOptions]
        Opt in to the persistent token cache so short-lived processes reuse
        one session. Only supported by AUTHORIZATION_CODE and DEVICE_CODE;
        azure managed identity is rejected. Default: None (memory only).

    Examples
    --------
    Client Credentials (service-to-service):

    >>> config = OAuthConfig(
    ...     issuer_url="https://login.microsoftonline.com/{tenant}/v2.0",
    ...     client_id="app-id",
    ...     client_secret="secret",
    ...     scopes=["api://lancedb-api/.default"],
    ... )

    Providers that require an explicit target can use ``resource`` and/or
    ``audience`` (these are forwarded unchanged):

    >>> config.resource = "https://api.example.com"
    >>> config.audience = "lancedb-api"

    Azure Managed Identity:

    >>> config = OAuthConfig(
    ...     issuer_url="https://login.microsoftonline.com/{tenant}/v2.0",
    ...     client_id="app-id",
    ...     scopes=["api://lancedb-api/.default"],
    ...     flow=OAuthFlowType.AZURE_MANAGED_IDENTITY,
    ... )

    Authorization Code with PKCE:

    The authorization URL is written to standard error before LanceDB tries to
    open a browser, so it can be copied in headless environments.

    >>> config = OAuthConfig(
    ...     issuer_url="https://login.microsoftonline.com/{tenant}/v2.0",
    ...     client_id="app-id",
    ...     scopes=["openid", "api://lancedb-api/access"],
    ...     flow=OAuthFlowType.AUTHORIZATION_CODE,
    ... )

    Device Authorization, with a persistent cache so later processes reuse
    the session without a new device prompt. The verification URL and user
    code are written to standard error before polling begins:

    >>> config = OAuthConfig(
    ...     issuer_url="https://login.microsoftonline.com/{tenant}/v2.0",
    ...     client_id="app-id",
    ...     scopes=["openid", "offline_access", "api://lancedb-api/access"],
    ...     flow=OAuthFlowType.DEVICE_CODE,
    ...     token_cache=TokenCacheOptions(),
    ... )
    Ú
issuer_urlÚ	client_idÚscopesÚflowNF)ÚdefaultÚreprÚclient_secretÚclient_auth_methodÚredirect_uriÚcallback_portTÚuse_pkceÚmanaged_identity_client_idÚrefresh_buffer_secsÚtoken_cacheÚresourceÚaudience)r   r   r   r   r%   r&   r   r	   r   r-   r   r0   r   r1   r   r2   r3   r'   r4   Úboolr5   r6   r7   r"   r8   r9   r   r   r   r)   r)   Q   sÅ   … ñeðN ƒOØƒNØ�‰IÓØ'×:Ñ:€Dˆ-Ó:Ù#(°¸EÔ#B€M�8˜C‘=ÓBØ59Ð˜Ð!1Ñ2Ó9Ø"&€L�(˜3‘-Ó&Ø#'€M�8˜C‘=Ó'Ø€HˆdÓØ04Ð ¨¡Ó4Ø)-Ð˜ #™Ó-Ø/3€K�Ð+Ñ,Ó3Ø"€Hˆh�s‰mÓ"Ø"€Hˆh�s‰mÔ"r   r)   c                   ó.   — e Zd ZdZdefd„Zd„ Zd„ Zd„ Zy)ÚOAuthSessionaF  Explicit OAuth session lifecycle for the persistent token cache.

    Built from the same :class:`OAuthConfig` used for
    :func:`lancedb.connect_async` (including its ``token_cache`` options).
    A connection created with the same configuration shares the cache, so
    logging in here prepares tokens for later processes without any database
    request.

    ``login`` always runs the configured interactive flow and replaces the
    cached session (the most recent login wins). ``logout`` removes only the
    local credential; it does not revoke anything with the provider and does
    not sign out of a browser SSO session.

    Examples
    --------
    >>> config = OAuthConfig(
    ...     issuer_url="https://issuer.example.com",
    ...     client_id="my-app",
    ...     scopes=["openid", "offline_access"],
    ...     flow=OAuthFlowType.DEVICE_CODE,
    ...     token_cache=TokenCacheOptions(),
    ... )
    >>> session = OAuthSession(config)  # doctest: +SKIP
    >>> status = await session.login()  # doctest: +SKIP
    >>> status.refreshable  # doctest: +SKIP
    True
    Úconfigc                 ó*   — ddl m}  ||«      | _        y )Nr   )r<   )Úlancedb._lancedbr<   Ú_inner)Úselfr=   ÚPyOAuthSessions      r   Ú__init__zOAuthSession.__init__ç   s   € ÝCá&4°VÓ&<ˆ�r   c              ƒ   óR   K  — | j                   j                  «       ƒ d{  –—† S 7 Œ­w)a¢  Eagerly run the configured flow and store the session.

        Returns a :class:`lancedb._lancedb.SessionStatus` describing the
        cached session. A successful login always replaces any prior cached
        session for this identity; if the provider does not issue a refresh
        token (for example without ``offline_access``), the previous record
        is removed and ``refreshable`` is ``False``.
        N)r@   Úlogin©rA   s    r   rE   zOAuthSession.loginì   s!   è ø€ ð —[‘[×&Ñ&Ó(×(Ð(Ð(úó   ‚' %¡'c              ƒ   óR   K  — | j                   j                  «       ƒ d{  –—† S 7 Œ­w)z’Report whether a cached session exists, with safe metadata.

        Never contacts the identity provider and never exposes token values.
        N)r@   ÚstatusrF   s    r   rI   zOAuthSession.status÷   s!   è ø€ ð
 —[‘[×'Ñ'Ó)×)Ð)Ð)úrG   c              ƒ   óR   K  — | j                   j                  «       ƒ d{  –—† S 7 Œ­w)zËRemove the matching local cached credential.

        Returns a :class:`lancedb._lancedb.SessionLogout` whose ``removed``
        flag reports whether a credential existed. Logout is idempotent.
        N)r@   ÚlogoutrF   s    r   rK   zOAuthSession.logoutþ   s!   è ø€ ð —[‘[×'Ñ'Ó)×)Ð)Ð)úrG   N)	r   r   r   r   r)   rC   rE   rI   rK   r   r   r   r<   r<   Ê   s"   „ ñð8=˜{ó =ò
	)ò*ó*r   r<   N)Údataclassesr   r   Úenumr   Útypingr   r   r%   r	   r   r"   r)   r<   r   r   r   ú<module>rO      sm   ð÷ )Ý ß !ô+�C˜ô +ô '�s˜Dô 'ð. ÷,ð ,ó ð,ð@ ÷u#ð u#ó ðu#÷p:*ò :*r   