o
    i                     @   s`   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 deZdS )	    N)Any)AccessTokenAccessTokenInfoSupportsTokenInfo   )CredentialUnavailableError)get_broker_credentialis_wslc                   @   sj   e Zd ZdZdeddfddZdededefdd	Zdedede	fd
dZ
dddZdd ZdddZdS )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              
   K   s   | dd | _| dd | _d | _d | _t }|r[tjds"t	 r[z| jt
jjddd|}| jr7| j|d< |d	i || _W d S  tyZ } zd| | _W Y d }~d S d }~ww |d u rdd| _d S d| _d S )
N	tenant_idZ	client_idwinT)r   Zparent_window_handleZuse_default_broker_accountZ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. )popZ
_tenant_idZ
_client_id_broker_credential_unavailable_messager   sysplatform
startswithr	   msalZPublicClientApplicationZCONSOLE_WINDOW_HANDLE	Exception)selfr   Zbroker_credential_classZbroker_credential_argsexr   r   Y/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_credentials/broker.py__init__   s4   
zBrokerCredential.__init__scopesc                 O   $   | j r| j j|i |S t| jdN)message)r   	get_tokenr   r   r   r   r   r   r   r   r    ;      zBrokerCredential.get_tokenc                 O   r   r   )r   get_token_infor   r   r!   r   r   r   r#   @   r"   zBrokerCredential.get_token_infoc                 C   s   | j r| j   | S N)r   	__enter__r   r   r   r   r%   E   s   
zBrokerCredential.__enter__c                 G   s   | j r| j j|  d S d S r$   )r   __exit__)r   argsr   r   r   r'   J   s   zBrokerCredential.__exit__c                 C   s   |    d S r$   )r'   r&   r   r   r   closeN   s   zBrokerCredential.close)r   r
   )r   N)__name__
__module____qualname____doc__r   r   strr   r    r   r#   r%   r'   r)   r   r   r   r   r
      s    %
r
   )r   typingr   r   Zazure.core.credentialsr   r   r   _exceptionsr   Z_internal.utilsr   r	   r
   r   r   r   r   <module>   s   