
    j                     R    d dl mZmZmZ d dlmZ ddlmZ ddlm	Z	  G d de	      Z
y)	    )CallableOptionalAny)AccessTokenInfo   )	AadClient)GetTokenMixinc            
            e Zd ZdZdededeg ef   deddf
 fdZdd	Zd
eddfdZ	ddZ
dededee   fdZdededefdZ xZS )ClientAssertionCredentiala  Authenticates a service principal with a JWT assertion.

    This credential is for advanced scenarios. :class:`~azure.identity.CertificateCredential` has a more
    convenient API for the most common assertion scenario, authenticating a service principal with a certificate.

    :param str tenant_id: ID of the principal's tenant. Also called its "directory" ID.
    :param str client_id: The principal's client ID
    :param func: A callable that returns a string assertion. The credential will call this every time it
        acquires a new token.
    :paramtype func: Callable[[], str]

    :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 cache_persistence_options: configuration for persistent token caching. If unspecified, the credential
        will cache tokens in memory.
    :paramtype cache_persistence_options: ~azure.identity.TokenCachePersistenceOptions
    :keyword List[str] additionally_allowed_tenants: Specifies tenants in addition to the specified "tenant_id"
        for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to
        acquire tokens for any tenant the application can access.

    .. admonition:: Example:

        .. literalinclude:: ../samples/credential_creation_code_snippets.py
            :start-after: [START create_client_assertion_credential]
            :end-before: [END create_client_assertion_credential]
            :language: python
            :dedent: 4
            :caption: Create a ClientAssertionCredential.
    	tenant_id	client_idfunckwargsreturnNc                     || _         |j                  dd       }|j                  dd       }|j                  dd       }|j                  dd       }t        ||f||||d|| _        t        	|           y )N	authoritycache	cae_cacheadditionally_allowed_tenants)r   r   r   r   )_funcpopr   _clientsuper__init__)
selfr   r   r   r   r   r   r   r   	__class__s
            m/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/_credentials/client_assertion.pyr   z"ClientAssertionCredential.__init__,   s    
JJ{D1	

7D)JJ{D1	'-zz2PRV'W$ 
  )E
 
 	    c                 :    | j                   j                          | S N)r   	__enter__r   s    r   r!   z#ClientAssertionCredential.__enter__=   s     r   argsc                 6     | j                   j                  |  y r    )r   __exit__)r   r#   s     r   r%   z"ClientAssertionCredential.__exit__A   s    t$r   c                 $    | j                          y)zDClose the credential's underlying HTTP client and release resources.N)r%   r"   s    r   closezClientAssertionCredential.closeD   s    r   scopesc                 <     | j                   j                  |fi |S r    )r   get_cached_access_token)r   r(   r   s      r   _acquire_token_silentlyz1ClientAssertionCredential._acquire_token_silentlyH   s    3t||33FEfEEr   c                 b    | j                         } | j                  j                  ||fi |}|S r    )r   r   obtain_token_by_jwt_assertion)r   r(   r   	assertiontokens        r   _request_tokenz(ClientAssertionCredential._request_tokenK   s0    JJL	:::69WPVWr   )r   r   )r   N)__name__
__module____qualname____doc__strr   r   r   r!   r%   r'   r   r   r+   r0   __classcell__)r   s   @r   r   r      s    ># # Xb#g=N Z] bf "%c %d %Fs Fc FhF_ Fc S _ r   r   N)typingr   r   r   azure.core.credentialsr   	_internalr   _internal.get_token_mixinr	   r    r   r   <module>r<      s$   
 + * 2 ! 5B Br   