o
    iq                     @   sj   d dl mZmZ d dlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ G d	d
 d
ee	ZdS )    )OptionalAny)AccessTokenInfo   )	AadClientAsyncContextManager)GetTokenMixin   )get_client_credential)AadClientCertificatevalidate_tenant_idc                       s   e Zd ZdZddededee deddf
 fdd	Zd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 )CertificateCredentiala  Authenticates as a service principal using a certificate.

    The certificate must have an RSA private key, because this credential signs assertions using RS256. See
    `Microsoft Entra ID documentation
    <https://learn.microsoft.com/entra/identity-platform/certificate-credentials#register-your-certificate-with-microsoft-identity-platform>`__
    for more information on configuring certificate authentication.

    :param str tenant_id: ID of the service principal's tenant. Also called its 'directory' ID.
    :param str client_id: The service principal's client ID
    :param str certificate_path: Optional path to a certificate file in PEM or PKCS12 format, including the private
        key. If not provided, **certificate_data** is required.

    :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 bytes certificate_data: The bytes of a certificate in PEM or PKCS12 format, including the private key.
    :keyword password: The certificate's password. If a unicode string, it will be encoded as UTF-8. If the certificate
          requires a different encoding, pass appropriately encoded bytes instead.
    :paramtype password: str or bytes
    :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_certificate_credential_async]
            :end-before: [END create_certificate_credential_async]
            :language: python
            :dedent: 4
            :caption: Create a CertificateCredential.
    N	tenant_id	client_idcertificate_pathkwargsreturnc                    sX   t | t|fi |}t|d |dd| _t||fi || _|| _t 	  d S )NZprivate_keyZ
passphrase)password)
r   r
   r   get_certificater   _clientZ
_client_idsuper__init__)selfr   r   r   r   Zclient_credential	__class__ b/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/aio/_credentials/certificate.pyr   3   s   zCertificateCredential.__init__c                    s   | j  I d H  | S N)r   
__aenter__r   r   r   r   r   @   s   z CertificateCredential.__aenter__c                    s   | j  I dH  dS )z)Close the credential's transport session.N)r   	__aexit__r    r   r   r   closeD   s   zCertificateCredential.closescopesc                    s   | j j|fi |S r   )r   Zget_cached_access_tokenr   r#   r   r   r   r   _acquire_token_silentlyI   s   z-CertificateCredential._acquire_token_silentlyc                    s    | j j|| jfi |I d H S r   )r   Z"obtain_token_by_client_certificater   r$   r   r   r   _request_tokenL   s   z$CertificateCredential._request_tokenr   )r   r   )r   N)__name__
__module____qualname____doc__strr   r   r   r   r"   r   r%   r&   __classcell__r   r   r   r   r      s    ($

r   N)typingr   r   Zazure.core.credentialsr   	_internalr   r   Z_internal.get_token_mixinr   Z_credentials.certificater
   r   r   r   r   r   r   r   <module>   s   