
    j                     f    d dl Z d dlmZ d dlZd dlmZmZmZ ddlm	Z	 ddl
mZmZ  G d de      Zy)	    N)Any)AccessTokenAccessTokenInfoSupportsTokenInfo   )CredentialUnavailableError)get_broker_credentialis_wslc                   ^    e Zd ZdZdeddfdZdededefdZdedede	fdZ
dd	Zd
 ZddZy)BrokerCredentiala[  A broker credential that handles prerequisite checking and falls back appropriately.

    This credential checks if the azure-identity-broker package is available and the platform
    is supported. If both conditions are met, it uses the real broker credential. Otherwise,
    it raises CredentialUnavailableError with an appropriate message.
    kwargsreturnNc                    |j                  dd       | _        |j                  dd       | _        d | _        d | _        t               }|r~t        j                  j                  d      s
t               rU	 | j                  t        j                  j                  ddd|}| j                  r| j                  |d<    |d	i || _        y |d| _        y d| _        y # t        $ r}d| | _        Y d }~y d }~ww xY w)
N	tenant_id	client_idwinT)r   parent_window_handleuse_default_broker_accountdisable_interactive_fallbackz:InteractiveBrowserBrokerCredential initialization failed: zInteractiveBrowserBrokerCredential unavailable. The 'azure-identity-broker' package is required to use brokered authentication.zwInteractiveBrowserBrokerCredential unavailable. Brokered authentication is only supported on Windows and WSL platforms. )pop
_tenant_id
_client_id_broker_credential_unavailable_messager	   sysplatform
startswithr
   msalPublicClientApplicationCONSOLE_WINDOW_HANDLE	Exception)selfr   broker_credential_classbroker_credential_argsexs        c/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/azure/identity/_credentials/broker.py__init__zBrokerCredential.__init__   s    **[$7 **[$7"&$(! #8"9"(?(?(F&(n!%,0,H,H,^,^2648	*
 *& ??:>//*;7*A*[DZ*['
 '.f )^ )  n.hikhl,m))ns   3AC 	C6"
C11C6scopesc                 ~    | j                   r | j                   j                  |i |S t        | j                        N)message)r   	get_tokenr   r   r#   r)   r   s      r'   r-   zBrokerCredential.get_token;   s:    ""44**44fGGG(1J1JKK    c                 ~    | j                   r | j                   j                  |i |S t        | j                        r+   )r   get_token_infor   r   r.   s      r'   r1   zBrokerCredential.get_token_info@   s:    ""94**996LVLL(1J1JKKr/   c                 R    | j                   r| j                   j                          | S N)r   	__enter__r#   s    r'   r4   zBrokerCredential.__enter__E   s"    ""##--/r/   c                 P    | j                   r | j                   j                  |  y y r3   )r   __exit__)r#   argss     r'   r7   zBrokerCredential.__exit__J   s&    "",D##,,d3 #r/   c                 $    | j                          y r3   )r7   r5   s    r'   closezBrokerCredential.closeN   s    r/   )r   r   )r   N)__name__
__module____qualname____doc__r   r(   strr   r-   r   r1   r4   r7   r:   r   r/   r'   r   r      sf    # # #JL L L L
Lc LS L_ L

4r/   r   )r   typingr   r   azure.core.credentialsr   r   r   _exceptionsr   _internal.utilsr	   r
   r   r   r/   r'   <module>rD      s+   
    R R 4 ;A( Ar/   