Ë
    £…j¹%  ã                   óÆ   — d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	m
Z
mZ d dl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  ej.                  e«      Z G d„ de«      Zy)é    N)ÚAnyÚOptionalÚcast)ÚClientAuthenticationError)ÚAccessTokenÚAccessTokenInfoÚTokenRequestOptions)ÚAsyncSupportsTokenInfoÚAsyncTokenCredentialÚAsyncTokenProvideré   )ÚAsyncContextManageré   )ÚCredentialUnavailableError)Ú_get_error_message)Úwithin_credential_chainc                   ó~   — e Zd ZdZdeddf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y)ÚChainedTokenCredentiala/  A sequence of credentials that is itself a credential.

    Its :func:`get_token` method calls ``get_token`` on each credential in the sequence, in order, returning the first
    valid token received. For more information, see
    https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview.

    :param credentials: credential instances to form the chain
    :type credentials: ~azure.core.credentials_async.AsyncTokenProvider

    .. admonition:: Example:

        .. literalinclude:: ../samples/credential_creation_code_snippets.py
            :start-after: [START create_chained_token_credential_async]
            :end-before: [END create_chained_token_credential_async]
            :language: python
            :dedent: 4
            :caption: Create a ChainedTokenCredential.
    ÚcredentialsÚreturnNc                 ó:   — |st        d«      ‚d | _        || _        y )Nz#at least one credential is required)Ú
ValueErrorÚ_successful_credentialr   )Úselfr   s     úh/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/aio/_credentials/chained.pyÚ__init__zChainedTokenCredential.__init__(   s!   € ÙÜÐBÓCÐCàDHˆÔ#Ø&ˆÕó    c              ƒ   óf   K  — t        j                  d„ | j                  D «       Ž ƒ d{  –—†  y7 Œ­w)z=Close the transport sessions of all credentials in the chain.c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­w)N)Úclose)Ú.0Ú
credentials     r   ú	<genexpr>z/ChainedTokenCredential.close.<locals>.<genexpr>2   s   è ø€ ÒU°j˜z×/Ñ/×1ÑUùs   ‚N)ÚasyncioÚgatherr   )r   s    r   r    zChainedTokenCredential.close/   s&   è ø€ ô �n‰nÑUÀD×DTÑDTÔUÐV×VÒVús   ‚'1©/ª1F©ÚclaimsÚ	tenant_idÚ
enable_caeÚscopesr'   r(   r)   Úkwargsc          	   �   ó,  K  — t        j                  d«       g }| j                  D ]÷  }	 t        |d«      r- t	        t
        |«      j                  ||||dœ|¤Žƒ d{  –—† }n]i }	|r||	d<   |r||	d<   ||	d<    t	        t        |«      j                  |i |¤Žƒ d{  –—† }
t        |
j                  |
j                  «      }t        j                  d| j                  j                  |j                  j                  «       || _        t        j                  d	«       |c S  t        j                  d	«       t/        |«      }| j                  j                  dz   |z   dz   }t1        |¬«      ‚7 �Œ7 ŒÒ# t"        $ r(}|j%                  ||j&                  f«       Y d}~�Œvd}~wt(        $ ri}|j%                  |t+        |«      f«       t        j-                  d
| j                  j                  |j                  j                  |d¬«       Y d}~ Œìd}~ww xY w­w)a¶  Asynchronously request a token from each credential, in order, returning the first token received.

        If no credential provides a token, raises :class:`azure.core.exceptions.ClientAuthenticationError`
        with an error message from each credential.

        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: optional tenant to include in the token request.
        :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.core.exceptions.ClientAuthenticationError: no credential in the chain provided a token
        TÚ	get_tokenr&   Nr'   r(   r)   ú%s acquired a token from %sFz4%s.get_token failed: %s raised unexpected error "%s"©Úexc_infoú: failed to retrieve a token from the included credentials.ú™
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.©Úmessage)r   Úsetr   Úhasattrr   r   r-   r
   Úget_token_infor   ÚtokenÚ
expires_onÚ_LOGGERÚinfoÚ	__class__Ú__name__r   r   Úappendr4   Ú	ExceptionÚstrÚdebugr   r   )r   r'   r(   r)   r*   r+   Úhistoryr"   r8   ÚoptionsÚ
token_infoÚexÚattemptsr4   s                 r   r-   z ChainedTokenCredential.get_token4   s   è ø€ ô8 	 ×#Ñ# DÔ)ØˆØ×*Ñ*ò "	ˆJð!ä˜: {Ô3Ø"R¤$Ô';¸ZÓ"H×"RÑ"RØ¨¸)ÐPZñ#Ø^dñ#÷ ‘Eð 46�GÙØ,2˜ Ñ)Ù Ø/8˜ Ñ,Ø,6�G˜LÑ)Ø'^¤tÔ,BÀJÓ'O×'^Ñ'^Ð`fÐ'qÐjpÑ'q×!q�JÜ'¨
×(8Ñ(8¸*×:OÑ:OÓP�Eä—‘Ð:¸D¿N¹N×<SÑ<SÐU_×UiÑUi×UrÑUrÔsØ.8�Ô+Ü'×+Ñ+¨EÔ2Ø’ð)"	ôF 	 ×#Ñ# EÔ*Ü% gÓ.ˆà�N‰N×#Ñ#ØJñKàñðXñXð 	ô (°Ô8Ð8ðQùð "rùô .ò 9à—‘ 
¨B¯J©JÐ7×8Ò8ûÜò 
à—‘ 
¬C°«GÐ4Ô5Ü—‘ØJØ—N‘N×+Ñ+Ø×(Ñ(×1Ñ1ØØ!ð ô õ ûð
üsg   ‚'Hª3E0ÁE+Á=E0ÂE.ÂB E0ÄAHÅ+E0Å.E0Å0	HÅ9FÆHÆHÆ(AHÈHÈHÈH)rC   rC   c          	   ‡   ól  K  — t        j                  d«       g }|xs i }| j                  D ]û  }	 t        |d«      r) t	        t
        |«      j                  |d|iŽƒ d{  –—† }ne|j                  d«      rt        d«      ‚ t	        t        |«      j                  |i |¤Žƒ d{  –—† }t        |j                  |j                  ¬«      }t        j                  d| j                   j"                  |j                   j"                  «       || _        t        j                  d	«       |c S  t        j                  d	«       t1        |«      }| j                   j"                  dz   |z   dz   }	t        j3                  |	«       t5        |	¬«      ‚7 �Œ+7 Œè# t        $ r(}|j'                  ||j(                  f«       Y d}~�Œ�d}~wt*        $ rj}|j'                  |t-        |«      f«       t        j/                  d
| j                   j"                  |j                   j"                  |d¬«       Y d}~ �Œd}~ww xY w­w)aZ  Request a token from each chained credential, in order, returning the first token received.

        If no credential provides a token, raises :class:`azure.core.exceptions.ClientAuthenticationError`
        with an error message from each credential.

        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 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 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.core.exceptions.ClientAuthenticationError: no credential in the chain provided a token.
        Tr7   rC   NÚpopzDProof of possession arguments are not supported for this credential.)r8   r9   r.   Fz9%s.get_token_info failed: %s raised unexpected error "%s"r/   r1   r2   r3   )r   r5   r   r6   r   r
   r7   Úgetr   r   r-   r   r8   r9   r:   r;   r<   r=   r   r>   r4   r?   r@   rA   r   Úwarningr   )
r   rC   r*   rB   r"   rD   r8   rE   rF   r4   s
             r   r7   z%ChainedTokenCredential.get_token_info€   sý  è ø€ ô& 	 ×#Ñ# DÔ)ØˆØ’-˜RˆØ×*Ñ*ò 	ˆJðä˜:Ð'7Ô8Ø'^¤tÔ,BÀJÓ'O×'^Ñ'^Ð`fÐ'xÐpwÑ'x×!x‘Jà—{‘{ 5Ô)Ü8Øbóð ð #S¤$Ô';¸ZÓ"H×"RÑ"RÐTZÐ"fÐ^eÑ"f×f�EÜ!0°u·{±{Èu×O_ÑO_Ô!`�Jä—‘Ð:¸D¿N¹N×<SÑ<SÐU_×UiÑUi×UrÑUrÔsØ.8�Ô+Ü'×+Ñ+¨EÔ2Ø!Ò!ð!	ô@ 	 ×#Ñ# EÔ*Ü% gÓ.ˆà�N‰N×#Ñ#ØJñKàñðXñXð 	ô 	�‰˜Ô Ü'°Ô8Ð8ðM "yùð gùô .ò 9à—‘ 
¨B¯J©JÐ7×8Ò8ûÜò 
à—‘ 
¬C°«GÐ4Ô5Ü—‘ØOØ—N‘N×+Ñ+Ø×(Ñ(×1Ñ1ØØ!ð ô ö ûð
üsh   ‚-H4°/FÁF
Á AFÂ$FÂ%BFÄ&A$H4Æ
FÆFÆ	H1ÆF;Æ5H4Æ;H1ÇAH,È%H4È,H1È1H4)r   N)r=   Ú
__module__Ú__qualname__Ú__doc__r   r   r    r@   r   Úboolr   r   r-   r	   r   r7   © r   r   r   r      s§   „ ñð&'Ð%7ð '¸Dó 'óWð !%Ø#'Ø òJ9àðJ9ð ˜‘ðJ9ð ˜C‘=ð	J9ð
 ðJ9ð ðJ9ð 
óJ9ðX [_ò @9¨Cð @9¸(ÐCVÑ:Wð @9Ðcrô @9r   r   )r$   ÚloggingÚtypingr   r   r   Úazure.core.exceptionsr   Úazure.core.credentialsr   r   r	   Úazure.core.credentials_asyncr
   r   r   Ú	_internalr   Ú r   Ú_credentials.chainedr   r   Ú	getLoggerr=   r:   r   rO   r   r   ú<module>rY      sO   ðó
 Û ß &Ñ &å ;ß TÑ Tß iÑ iÝ +Ý *Ý 6Ý 0à
ˆ'×
Ñ
˜HÓ
%€ôl9Ð0õ l9r   