o
    i                     @   s   d dl Z d dlmZmZmZmZmZ d dlmZ d dl	Z	ddl
mZ ddlmZmZmZmZ ddlmZ dd	lmZ G d
d dZdS )    N)AnyListUnionDictOptional)Self   )
MsalClient)get_default_authoritynormalize_authorityresolve_tenantvalidate_tenant_id   )EnvironmentVariables)_load_persistent_cachec                       s  e Zd ZdZ	d!dddddddedeeeeeef f  dee	e  dee dee
 d	ee d
ee
 deddf fddZdefddZdeddfddZd"ddZd#de
dejfddZdedejfddZdeeef fddZdeeef ddfdd Z  ZS )$MsalCredentialzBase class for credentials wrapping MSAL applications.

    :param str client_id: the principal's client ID
    :param client_credential: client credential data for the application
    :type client_credential: dict
    N)additionally_allowed_tenants	authoritydisable_instance_discovery	tenant_idenable_support_logging	client_idclient_credentialr   r   r   r   r   kwargsreturnc          	         s   |d u rd n| | _ |rt|nt | _tjtj| _	| j	r+| j	
 dv r+tjj| _	|p.d| _t| j tdi || _|| _|| _|| _|pIg | _i | _i | _|dd | _|dd | _| jse| jrid| _nd| _|dd | _tt|   d S )	N)ZtryautodetecttrueZorganizations_cache
_cae_cacheTFZcache_persistence_options ) _instance_discoveryr   r
   
_authorityosenvirongetr   ZAZURE_REGIONAL_AUTHORITY_NAME_regional_authoritylowermsalConfidentialClientApplicationZATTEMPT_REGION_DISCOVERY
_tenant_idr   r	   _client_client_credential
_client_id_enable_support_logging_additionally_allowed_tenants_client_applications_cae_client_applicationspopr   r   _custom_cache_cache_optionssuperr   __init__)	selfr   r   r   r   r   r   r   r   	__class__r   `/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_internal/msal_credentials.pyr4      s*   



zMsalCredential.__init__c                 C   s   | j   | S N)r)   	__enter__r5   r   r   r8   r:   ?   s   
zMsalCredential.__enter__argsc                 G   s   | j j|  d S r9   )r)   __exit__)r5   r<   r   r   r8   r=   C   s   zMsalCredential.__exit__c                 C   s   |    dS )zDClose the credential's underlying HTTP client and release resources.N)r=   r;   r   r   r8   closeF   s   zMsalCredential.closeFis_caec                 C   sT   | j r|rt| j || _nt| j || _n|rt | _nt | _|r'| jS | jS r9   )r2   r   r   r   r&   
TokenCache)r5   r?   r   r   r8   _initialize_cacheJ   s   
z MsalCredential._initialize_cachec                 K   s   t | jfd| ji|}| j}d }| j}| jrtjntj}|	dr+| j
}dg}| j}|s8| jt|	dd}||vrxz|| j| j|d| j|| j|| j| j| jd	||< W || S  tyw } zdt|v rrtd| j d	 d }~ww || S )
Nr   Z
enable_caeZCP1)r?   z{}/{})	r   r   Zclient_capabilitiesr   Zazure_regiontoken_cachehttp_clientZinstance_discoveryZenable_pii_logZinvalid_instancezThe authority provided, z, is not well-known. If this authority is valid and trustworthy, you can disable this check by passing in 'disable_instance_discovery=True' when constructing the credential.)r   r(   r-   r.   r   r*   r&   r'   ZPublicClientApplicationr#   r/   r   rA   boolr+   formatr    r$   r)   r   r,   
ValueErrorstr)r5   r   r   Zclient_applications_mapZcapabilitiesrB   Z	app_classexr   r   r8   _get_appX   sP   
	zMsalCredential._get_appc                 C   s,   | j  }|d= |d= | js|d= |d= |S )Nr.   r/   r   r   )__dict__copyr1   r5   stater   r   r8   __getstate__   s   
zMsalCredential.__getstate__rM   c                 C   s2   | j | i | _i | _| jsd | _d | _d S d S r9   )rJ   updater.   r/   r1   r   r   rL   r   r   r8   __setstate__   s   
zMsalCredential.__setstate__r9   )r   N)F)__name__
__module____qualname____doc__rG   r   r   r   r   r   rD   r4   r   r:   r=   r>   r&   r@   rA   ZClientApplicationrI   rN   rP   __classcell__r   r   r6   r8   r      sF    

	
&
+"
r   )r!   typingr   r   r   r   r   Ztyping_extensionsr   r&   Zmsal_clientr	   utilsr
   r   r   r   
_constantsr   Z_persistent_cacher   r   r   r   r   r8   <module>   s   