o
    ¾­§i½  ã                   @   sL   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„ de	ƒZ
dS )	é    )ÚCallableÚOptionalÚAny)ÚAccessTokenInfoé   )Ú	AadClient)ÚGetTokenMixinc                
       s”   e Zd ZdZdededeg ef deddf
‡ fdd	„Zdd
d„Zdeddfdd„Z	ddd„Z
dededee fdd„Zdededefdd„Z‡  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           	         sb   || _ | dd ¡}| dd ¡}| dd ¡}| dd ¡}t||f||||dœ|¤Ž| _tƒ  ¡  d S )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__© úc/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_credentials/client_assertion.pyr   ,   s"   þúù	z"ClientAssertionCredential.__init__c                 C   s   | j  ¡  | S ©N)r   Ú	__enter__©r   r   r   r   r   =   s   
z#ClientAssertionCredential.__enter__Úargsc                 G   s   | j j|Ž  d S r   )r   Ú__exit__)r   r    r   r   r   r!   A   s   z"ClientAssertionCredential.__exit__c                 C   s   |   ¡  dS )zDClose the credential's underlying HTTP client and release resources.N)r!   r   r   r   r   ÚcloseD   s   zClientAssertionCredential.closeÚscopesc                 O   s   | j j|fi |¤ŽS r   )r   Zget_cached_access_token)r   r#   r   r   r   r   Ú_acquire_token_silentlyH   s   z1ClientAssertionCredential._acquire_token_silentlyc                 O   s"   |   ¡ }| jj||fi |¤Ž}|S r   )r   r   Zobtain_token_by_jwt_assertion)r   r#   r   Z	assertionÚtokenr   r   r   Ú_request_tokenK   s   z(ClientAssertionCredential._request_token)r   r	   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r!   r"   r   r   r$   r&   Ú__classcell__r   r   r   r   r	      s    *

r	   N)Útypingr   r   r   Zazure.core.credentialsr   Ú	_internalr   Z_internal.get_token_mixinr   r	   r   r   r   r   Ú<module>   s
   