
    j                         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      Zy)    N)AnyListUnionDictOptional)Self   )
MsalClient)get_default_authoritynormalize_authorityresolve_tenantvalidate_tenant_id   )EnvironmentVariables)_load_persistent_cachec                   6    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ZdefdZdeddfdZddZdde
dej"                  fdZdedej&                  fdZdeeef   fdZdeeef   ddfdZ x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                    |d n| | _         |rt        |      n	t               | _        t        j
                  j                  t        j                        | _	        | j                  r;| j                  j                         dv rt        j                  j                  | _	        |xs d| _        t        | j                         t!        di || _        || _        || _        || _        |xs g | _        i | _        i | _        |j1                  dd       | _        |j1                  dd       | _        | j2                  s| j4                  rd| _        nd| _        |j1                  dd       | _        t:        t<        |           y )	N)tryautodetecttrueorganizations_cache
_cae_cacheTFcache_persistence_options ) _instance_discoveryr   r   
_authorityosenvirongetr   AZURE_REGIONAL_AUTHORITY_NAME_regional_authoritylowermsalConfidentialClientApplication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__s
            j/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/_internal/msal_credentials.pyr<   zMsalCredential.__init__   s;    ,F+M4WqSq <E-i8K`Kb#%::>>2F2d2d#e ##(@(@(F(F(HLe(e'+'I'I'b'bD$#64??+!+F+"3#'=$-I-OR*GI!KM%jj40 **\48;;$//!%D!&D$jj)DdKnd,.    c                 :    | j                   j                          | S N)r1   	__enter__r=   s    r?   rC   zMsalCredential.__enter__?   s     r@   argsc                 6     | j                   j                  |  y rB   )r1   __exit__)r=   rE   s     r?   rG   zMsalCredential.__exit__C   s    t$r@   c                 $    | j                          y)zDClose the credential's underlying HTTP client and release resources.N)rG   rD   s    r?   closezMsalCredential.closeF   s    r@   is_caec                 ,   | j                   r:|rt        | j                   |      | _        nQt        | j                   |      | _        n5|rt	        j
                         | _        nt	        j
                         | _        |r| j                  S | j                  S rB   )r:   r   r"   r!   r-   
TokenCache)r=   rJ   s     r?   _initialize_cachez MsalCredential._initialize_cacheJ   sj    "89L9Lf"U4T5H5H&Q"&//"3"oo/"(t9dkk9r@   c                    t        | j                  fd| j                  i|}| j                  }d }| j                  }| j
                  rt        j                  nt        j                  }|j                  d      r| j                  }dg}| j                  }|s*| j                  t        |j                  d                  }||vrp	  || j                  | j
                  |dj                  | j                   |      | j"                  || j$                  | j&                  | j(                  	      ||<   ||   S ||   S # t*        $ r,}dt-        |      v rt+        d| j                    d	       d }~ww xY w)
Nr   
enable_caeCP1)rJ   z{}/{})	r   r   client_capabilitiesr   azure_regiontoken_cachehttp_clientinstance_discoveryenable_pii_log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   r0   r5   r6   r!   r2   r-   r.   PublicClientApplicationr)   r7   r"   rM   boolr3   formatr&   r+   r1   r%   r4   
ValueErrorstr)r=   r   r   client_applications_mapcapabilitiesrS   	app_classexs           r?   _get_appzMsalCredential._get_appX   sv   "OO
:>:\:\
`f
	 #'";";kk:>:Q:QD66W[WsWs	::l#&*&C&C#!7L//K00VZZ=U8V0WK335>"oo&*&=&=(4%nnT__iH!%!9!9 + $'+'?'?#'#?#?
6'	2( 'y11&y11  %R0$24??2C D^ ^ 
 s   A*D: :	E/'E**E/c                 j    | j                   j                         }|d= |d= | j                  s|d= |d= |S )Nr6   r7   r!   r"   )__dict__copyr9   r=   states     r?   __getstate__zMsalCredential.__getstate__   sC    ""$(),-!!hl#r@   rf   c                     | j                   j                  |       i | _        i | _        | j                  sd | _        d | _        y y rB   )rc   updater6   r7   r9   r!   r"   re   s     r?   __setstate__zMsalCredential.__setstate__   s@    U#$&!(*%!!DK"DO "r@   rB   )r   N)F)__name__
__module____qualname____doc__r\   r   r   r   r   r   rY   r<   r   rC   rG   rI   r-   rL   rM   ClientApplicationra   rg   rj   __classcell__)r>   s   @r?   r   r      s8    CG$/
 =A#'59#'15$/$/ $E#tCH~*=$>?$/
 '/tCy&9$/ C=$/ %-TN$/ C=$/ !)$/ $/ 
$/L4 %c %d %: : :)2 )2)?)? )2Vd38n #$sCx. #T #r@   r   )r'   typingr   r   r   r   r   typing_extensionsr   r-   msal_clientr
   utilsr   r   r   r   
_constantsr   _persistent_cacher   r   r$   r@   r?   <module>rw      s1   
 
 3 3 "  # a a - 6C# C#r@   