
    j$                         d dl mZmZmZmZ d dlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZmZ  edd      Z G d d      Z G d de      Zy)    )AnyOptionalTypeVarcast)AccessTokenTokenRequestOptionsAccessTokenInfoSupportsTokenInfoTokenCredential   )SilentAuthenticationCredential   )CredentialUnavailableError)DEVELOPER_SIGN_ON_CLIENT_ID)	AadClientAadClientBase
within_dac)log_get_token)NO_TOKENSharedTokenCacheBaseT_SharedTokenCacheCredential)boundc                       e Zd ZdZddee   deddfdZddZdeddfd	Z	dd
Z
edddddedee   dee   dededefd       Zedddedee   defd       Zedefd       Zy)SharedTokenCacheCredentiala  Authenticates using tokens in the local cache shared between Microsoft applications.

    :param str username: Username (typically an email address) of the user to authenticate as. This is used when the
        local cache contains tokens for multiple identities.

    :keyword str authority: Authority of a Microsoft Entra endpoint, for example 'login.microsoftonline.com',
        the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
        defines authorities for other clouds.
    :keyword str tenant_id: a Microsoft Entra tenant ID. Used to select an account when the cache contains
        tokens for multiple identities.
    :keyword AuthenticationRecord authentication_record: an authentication record returned by a user credential such as
        :class:`DeviceCodeCredential` or :class:`InteractiveBrowserCredential`
    :keyword cache_persistence_options: configuration for persistent token caching. If not provided, the credential
        will use the persistent cache shared by Microsoft development applications
    :paramtype cache_persistence_options: ~azure.identity.TokenCachePersistenceOptions
    Nusernamekwargsreturnc                 R    d|v rt        di || _        y t        dd|i|| _        y )Nauthentication_recordr    )r   _credentialr   )selfr   r   s      i/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/_credentials/shared_cache.py__init__z#SharedTokenCacheCredential.__init__%   s1    "f,2P2ZSY2ZD:WHWPVWD    c                 :    | j                   j                          | S N)r"   	__enter__r#   s    r$   r)   z$SharedTokenCacheCredential.__enter__+   s    ""$r&   argsc                 6     | j                   j                  |  y r(   )r"   __exit__r#   r+   s     r$   r-   z#SharedTokenCacheCredential.__exit__/   s    !!!4(r&   c                 $    | j                          y)z)Close the credential's transport session.Nr-   r*   s    r$   closez SharedTokenCacheCredential.close2   s    r&   Fclaims	tenant_id
enable_caescopesr3   r4   r5   c                ^     t        t        | j                        j                  ||||d|S )a
  Get an access token for `scopes` from the shared cache.

        If no access token is cached, attempt to acquire one using a cached refresh token.

        This method is called automatically by Azure SDK clients.

        :param str scopes: desired scopes for the access token. This method requires at least one scope.
            For more information about scopes, see
            https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
        :keyword str claims: additional claims required in the token, such as those returned in a resource provider's
            claims challenge following an authorization failure
        :keyword str tenant_id: not used by this credential; any value provided will be ignored.
        :keyword bool enable_cae: indicates whether to enable Continuous Access Evaluation (CAE) for the requested
            token. Defaults to False.

        :return: An access token with the desired scopes.
        :rtype: ~azure.core.credentials.AccessToken
        :raises ~azure.identity.CredentialUnavailableError: the cache is unavailable or contains insufficient user
            information
        :raises ~azure.core.exceptions.ClientAuthenticationError: authentication failed. The error's ``message``
            attribute gives a reason.
        r2   )r   r   r"   	get_token)r#   r3   r4   r5   r6   r   s         r$   r8   z$SharedTokenCacheCredential.get_token6   s8    > AtOT%5%56@@FiJ
RX
 	
r&   optionsr:   c                V     t        t        | j                        j                  |d|iS )a  Request an access token for `scopes`.

        If no access token is cached, attempt to acquire one using a cached refresh token.

        This is an alternative to `get_token` to enable certain scenarios that require additional properties
        on the token. This method is called automatically by Azure SDK clients.

        :param str scopes: desired scope for the access token. This method requires at least one scope.
            For more information about scopes, see https://learn.microsoft.com/entra/identity-platform/scopes-oidc.
        :keyword options: A dictionary of options for the token request. Unknown options will be ignored. Optional.
        :paramtype options: ~azure.core.credentials.TokenRequestOptions

        :rtype: ~azure.core.credentials.AccessTokenInfo
        :return: An AccessTokenInfo instance containing information about the token.
        :raises ~azure.identity.CredentialUnavailableError: the cache is unavailable or contains insufficient user
            information.
        :raises ~azure.core.exceptions.ClientAuthenticationError: authentication failed. The error's ``message``
            attribute gives a reason.
        r:   )r   r
   r"   get_token_infor#   r:   r6   s      r$   r<   z)SharedTokenCacheCredential.get_token_infoY   s,    * Ht%t'7'78GGaY`aar&   c                  *    t        j                         S )zWhether the shared token cache is supported on the current platform.

        :return: True if the shared token cache is supported on the current platform, otherwise False.
        :rtype: bool
        )r   	supportedr!   r&   r$   r?   z$SharedTokenCacheCredential.supportedp   s     $--//r&   r(   )r   r   r   N)__name__
__module____qualname____doc__r   strr   r%   r)   r-   r1   r   boolr   r8   r   r	   r<   staticmethodr?   r!   r&   r$   r   r      s    "X# X X X)c )d )  !%#'  
 
  
 C=	 

  
  
 
 
  
D TX bc bH=P4Q b]l b b, 0t 0 0r&   r   c                       e Zd ZdZdedefdZd ZddZdddd	d
ede	e   de	e   de
dedefdZddd
ede	e   defdZdddd
ede	e   dededef
dZdedefdZy)r   zQThe original SharedTokenCacheCredential, which doesn't use msal.ClientApplicationr#   r   c                 R    | j                   r| j                   j                          | S r(   )_clientr)   r*   s    r$   r)   z%_SharedTokenCacheCredential.__enter__}   s    <<LL""$r&   c                 P    | j                   r | j                   j                  |  y y r(   )rJ   r-   r.   s     r$   r-   z$_SharedTokenCacheCredential.__exit__   s"    <<!DLL!!4( r&   Nc                 $    | j                          y r(   r0   r*   s    r$   r1   z!_SharedTokenCacheCredential.close   s    r&   Fr2   r6   r3   r4   r5   r   c                    i }|r||d<   |r||d<   ||d<    | j                   ||dd|}t        |j                  |j                        S )Nr3   r4   r5   r8   r:   base_method_name)_get_token_baser   token
expires_on)r#   r3   r4   r5   r6   r   r:   
token_infos           r$   r8   z%_SharedTokenCacheCredential.get_token   sc     (* &GH#,GK  *)T))67U`kdjk
:++Z-B-BCCr&   r9   r:   c                (     | j                   ||ddS )Nr<   rN   )rP   r=   s      r$   r<   z*_SharedTokenCacheCredential.get_token_info   s    #t##VWO_``r&   r<   rN   rO   c                f   |st        d| d      | j                  s| j                          |xs i }|j                  d      }|j                  d      }|j                  dd      }|r| j                  n| j
                  }|s | j                  |      }|st        d	      | j                  | j                  | j                  |      }	|s| j                  ||	|      }
|
r|
S | j                  |	|      D ]6  }	  t        t        | j                        j                   ||f|||d
|}
|
c S  t        t+        j,                  |	j                  d            	      # t"        $ rG}t%        j                         r-t        t'        |dt)        |            t'        |dd             | d }~ww xY w)N'z' requires at least one scoper3   r4   r5   F)is_caezShared token cache unavailable)messager2   rX   response)rX   rY   r   )
ValueError_client_initialized_initialize_clientget
_cae_cache_cache_initialize_cacher   _get_account	_username
_tenant_id_get_cached_access_token_get_refresh_tokensr   r   rJ   obtain_token_by_refresh_token	Exceptionr   getattrrE   r   format)r#   r:   rO   r6   r   r3   r4   rW   token_cacheaccountrQ   refresh_tokenes                r$   rP   z+_SharedTokenCacheCredential._get_token_base   s    q!1 22OPQQ''##%-RX&KK,	\51)/dooT[[ 000?K 09YZZ##DNNDOOF#S11&'&1QE "55gf5M 	M
SY5SSM28IZ`dj 	 )ZAX1YZZ  >>#4 '9c!f =PQS]_cHd s   =1E  	F0)AF++F0c                 $    t        ddt        i|S )N	client_idr!   )r   r   )r#   r   s     r$   _get_auth_clientz,_SharedTokenCacheCredential._get_auth_client   s    I#>I&IIr&   r@   )rA   rB   rC   rD   r   r)   r-   r1   rE   r   rF   r   r   r8   r   r	   r<   rP   r   rp   r!   r&   r$   r   r   z   s   [ a 
) !%#' DD D C=	D
 D D 
D$ UY ac aH=P4Q a]l a 26 0	1[1[ -.1[ 	1[
 1[ 
1[fJ J Jr&   N)typingr   r   r   r   azure.core.credentialsr   r   r	   r
   r   silentr    r   
_constantsr   	_internalr   r   r   _internal.decoratorsr   _internal.shared_token_cacher   r   r   r   r   r!   r&   r$   <module>ry      sU   
 0 / x x 2 ) 4 < < 0 I C45d0 d0NXJ"6 XJr&   