o
    iG(                     @   s   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
mZmZmZ ddlmZ ddlmZ e eZdd	 ZG d
d dZdS )    N)AnyOptionalcast)ClientAuthenticationError)AccessTokenAccessTokenInfoTokenRequestOptionsSupportsTokenInfoTokenCredentialTokenProvider   )CredentialUnavailableError)within_credential_chainc                 C   s^   g }| D ]"\}}t |dr|j}n|jj}|r!|d|| q|| qdd|S )N_credential_namez{}: {}z
Attempted credentials:
	{}z
	)hasattrr   	__class____name__appendformatjoin)historyattempts
credentialerrorZcredential_name r   Z/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_credentials/chained.py_get_error_message   s   
r   c                   @   s   e Zd ZdZdeddfddZdddZd	eddfd
dZdddZ	ddddde
dee
 dee
 dededefddZddde
dee defddZdS )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 `ChainedTokenCredential overview
    <"https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview">`__.

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

    .. admonition:: Example:

        .. literalinclude:: ../samples/credential_creation_code_snippets.py
            :start-after: [START create_chained_token_credential]
            :end-before: [END create_chained_token_credential]
            :language: python
            :dedent: 4
            :caption: Create a ChainedTokenCredential.
    credentialsreturnNc                 G   s   |st dd | _|| _d S )Nz#at least one credential is required)
ValueError_successful_credentialr   )selfr   r   r   r   __init__>   s   
zChainedTokenCredential.__init__c                 C   s   | j D ]}|  q| S N)r   	__enter__)r"   r   r   r   r   r%   E   s   

z ChainedTokenCredential.__enter__argsc                 G   s   | j D ]}|j|  qd S r$   )r   __exit__)r"   r&   r   r   r   r   r'   J   s   
zChainedTokenCredential.__exit__c                 C   s   |    dS )z<Close the transport session of each credential in the chain.N)r'   )r"   r   r   r   closeN   s   zChainedTokenCredential.closeFclaims	tenant_id
enable_caescopesr*   r+   r,   kwargsc                O   s|  t d g }| jD ]}zQt|dr"tt|j||||d|}n$i }	|r*||	d< |r0||	d< ||	d< tt|j|d|	i}
t	|
j
|
j}td| jj|jj || _t d	 |W   S  tyw } z|||jf W Y d
}~q
d
}~w ty } z||t|f tjd| jj|jj|dd W Y d
}~ nd
}~ww t d	 t|}| jjd | d }t| t|d)a  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 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)   r*   r+   r,   options%s acquired a token from %sFNz4%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   r   r   r
   r/   r	   get_token_infor   token
expires_on_LOGGERinfor   r   r!   r   r   r7   	Exceptionstrdebugr   warningr   )r"   r*   r+   r,   r-   r.   r   r   r:   r0   
token_infoexr   r7   r   r   r   r/   R   sb   








z ChainedTokenCredential.get_token)r0   r0   c          
      G   sl  t d g }|p
i }| jD ]}zEt|dr"tt|j|d|i}n|dr+tdtt	|j
|i |}t|j|jd}td| jj|jj || _t d |W   S  tyo } z|||jf W Y d	}~qd	}~w ty } z||t|f tjd
| jj|jj|dd W Y d	}~ nd	}~ww t d t|}| jjd | d }	t|	 t|	d)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.
        Tr9   r0   popzDProof of possession arguments are not supported for this credential.)r:   r;   r1   FNz9%s.get_token_info failed: %s raised unexpected error "%s"r2   r4   r5   r6   )r   r8   r   r   r   r	   r9   getr   r
   r/   r   r:   r;   r<   r=   r   r   r!   r   r7   r>   r?   r@   r   rA   r   )
r"   r0   r-   r   r   rB   r:   rC   r   r7   r   r   r   r9      sX   








z%ChainedTokenCredential.get_token_info)r   r   )r   N)r   
__module____qualname____doc__r   r#   r%   r   r'   r(   r?   r   boolr   r/   r   r   r9   r   r   r   r   r   *   s.    


$Or   )loggingtypingr   r   r   Zazure.core.exceptionsr   Zazure.core.credentialsr   r   r   r	   r
   r    r   	_internalr   	getLoggerr   r<   r   r   r   r   r   r   <module>   s    
