o
    ÔèFh  ã                   @   s®   d Z ddlZddlZddlZddlZddlmZ ddlmZ dZdZ	dd„ Z
G d	d
„ d
ejd�ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ eƒ eƒ eƒ fD ƒZdS )z" Challenges for reauthentication.
é    N)Ú_helpers)Ú
exceptionszhttps://accounts.google.comzFPlease run `gcloud auth login` to complete reauthentication with SAML.c                 C   s
   t   | ¡S )zìGet password from user.

    Override this function with a different logic if you are using this library
    outside a CLI.

    Args:
        text (str): message for the password prompt.

    Returns:
        str: password string.
    )Úgetpass)Útext© r   úQ/var/www/html/loop/nvenv/lib/python3.10/site-packages/google/oauth2/challenges.pyÚget_user_password!   s   
r   c                   @   sB   e Zd ZdZeejdd„ ƒƒZeejdd„ ƒƒZejdd„ ƒZ	dS )	ÚReauthChallengez!Base class for reauth challenges.c                 C   ó   t dƒ‚)z"Returns the name of the challenge.z!name property must be implemented©ÚNotImplementedError©Úselfr   r   r   Úname3   ó   zReauthChallenge.namec                 C   r
   )zAReturns true if a challenge is supported locally on this machine.z0is_locally_eligible property must be implementedr   r   r   r   r   Úis_locally_eligible9   r   z#ReauthChallenge.is_locally_eligiblec                 C   r
   )ac  Performs logic required to obtain credentials and returns it.

        Args:
            metadata (Mapping): challenge metadata returned in the 'challenges' field in
                the initial reauth request. Includes the 'challengeType' field
                and other challenge-specific fields.

        Returns:
            response that will be send to the reauth service as the content of
            the 'proposalResponse' field in the request body. Usually a dict
            with the keys specific to the challenge. For example,
            ``{'credential': password}`` for password challenge.
        z1obtain_challenge_input method must be implementedr   ©r   Úmetadatar   r   r   Úobtain_challenge_input?   s   z&ReauthChallenge.obtain_challenge_inputN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚabcÚabstractmethodr   r   r   r   r   r   r   r	   0   s    r	   )Ú	metaclassc                   @   ó:   e Zd ZdZedd„ ƒZedd„ ƒZe e	¡dd„ ƒZ
dS )	ÚPasswordChallengez(Challenge that asks for user's password.c                 C   ó   dS )NÚPASSWORDr   r   r   r   r   r   T   ó   zPasswordChallenge.namec                 C   r   ©NTr   r   r   r   r   r   X   r!   z%PasswordChallenge.is_locally_eligiblec                 C   s   t dƒ}|sd}d|iS )NzPlease enter your password:ú Ú
credential)r   )r   Úunused_metadataÚpasswdr   r   r   r   \   s   z(PasswordChallenge.obtain_challenge_inputN©r   r   r   r   r   r   r   r   Úcopy_docstringr	   r   r   r   r   r   r   Q   ó    

r   c                   @   r   )	ÚSecurityKeyChallengez2Challenge that asks for user's security key touch.c                 C   r   )NÚSECURITY_KEYr   r   r   r   r   r   g   r!   zSecurityKeyChallenge.namec                 C   r   r"   r   r   r   r   r   r   k   r!   z(SecurityKeyChallenge.is_locally_eligiblec                 C   s   zdd l }dd l}dd l}W n ty   t d¡‚w |d }|d }|d }|d }||kr4||g}n|g}g }|D ](}	|	d  d¡}
|j t	t
 |
¡ƒ¡}|	d	  d¡}t
 |¡}| ||d
œ¡ q;d}|D ]•}z|d7 }|jj t¡}|j||tjjd�}d|iW   S  |jjyÏ } z;|j|jjjkr²|t|ƒkr¬tj d¡ W Y d }~ d S W Y d }~qh|j|jjjkrÁtj d¡ n|‚W Y d }~ d S d }~w |jjyë } ztj d |¡¡ W Y d }~qhd }~w |jjyý   tj d¡ Y  d S w d S )Nr   z’pyu2f dependency is required to use Security key reauth feature. It can be installed via `pip install pyu2f` or `pip install google-auth[reauth]`.ÚsecurityKeyÚ
challengesÚapplicationIdÚrelyingPartyIdÚ	keyHandleÚasciiÚ	challenge)Úkeyr2   é   )Úprint_callbackzIneligible security key.
z0Timed out while waiting for security key touch.
zPlugin error: {}.
zNo security key found.
)Úpyu2f.convenience.authenticatorÚpyu2f.errorsÚpyu2f.modelÚImportErrorr   ÚReauthFailErrorÚencodeÚmodelÚRegisteredKeyÚ	bytearrayÚbase64Úurlsafe_b64decodeÚappendÚconvenienceÚauthenticatorÚCreateCompositeAuthenticatorÚREAUTH_ORIGINÚAuthenticateÚsysÚstderrÚwriteÚerrorsÚU2FErrorÚcodeÚDEVICE_INELIGIBLEÚlenÚTIMEOUTÚPluginErrorÚformatÚNoDeviceFoundError)r   r   Úpyu2fÚskr-   Úapplication_idÚrelying_party_idÚapplication_parametersÚchallenge_dataÚcÚkhr3   r2   ÚtriesÚapp_idÚapiÚresponseÚer   r   r   r   o   sr   ÿÿ

ÿ
ÿÿ
ü
€û€þæz+SecurityKeyChallenge.obtain_challenge_inputNr'   r   r   r   r   r*   d   r)   r*   c                   @   s0   e Zd ZdZedd„ ƒZedd„ ƒZdd„ ZdS )	ÚSamlChallengezÿChallenge that asks the users to browse to their ID Providers.

    Currently SAML challenge is not supported. When obtaining the challenge
    input, exception will be raised to instruct the users to run
    `gcloud auth login` for reauthentication.
    c                 C   r   )NÚSAMLr   r   r   r   r   r   ¹   r!   zSamlChallenge.namec                 C   r   r"   r   r   r   r   r   r   ½   r!   z!SamlChallenge.is_locally_eligiblec                 C   s
   t  t¡‚)N)r   ÚReauthSamlChallengeFailErrorÚSAML_CHALLENGE_MESSAGEr   r   r   r   r   Á   s   
z$SamlChallenge.obtain_challenge_inputN)r   r   r   r   r   r   r   r   r   r   r   r   r`   ±   s    

r`   c                 C   s   i | ]}|j |“qS r   )r   )Ú.0r2   r   r   r   Ú
<dictcomp>È   s    ÿÿre   )r   r   r?   r   rG   Úgoogle.authr   r   rE   rc   r   ÚABCMetar	   r   r*   r`   ÚAVAILABLE_CHALLENGESr   r   r   r   Ú<module>   s$   ÿ!M
þ