o
    tBh,                     @   s   d Z ddl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d Z
eejG dd	 d	eZG d
d deZG dd deZdd e e fD ZdS )z" Challenges for reauthentication.
    N)_helpers)
exceptionszhttps://accounts.google.comc                 C   s
   t  | S )zGet 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   o/var/www/html/riverr-enterprise-integrations-main/venv/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	   /   s    r	   c                   @   :   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   sp  zdd l }dd l}dd l}W n ty   tdw |d }|d }|d }g }|D ](}|d d}|jt	t
|}	|d d}
t
|
}
||	|
d	 q+z|jjt}|j||tjjd
}d|iW S  |jjy } z.|j|jjjkrtjd n|j|jjjkrtjd n	|W Y d }~d S W Y d }~d S d }~w |jjy   tjd Y d S w )Nr   zpyu2f 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	keyHandleascii	challenge)keyr/   )print_callbackzIneligible security key.
z0Timed out while waiting for security key touch.
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TIMEOUTNoDeviceFoundError)r   r   pyu2fskr+   app_idchallenge_datackhr0   r/   apiresponseer   r   r   r   o   sT   




z+SecurityKeyChallenge.obtain_challenge_inputNr%   r   r   r   r   r(   d   r'   r(   c                 C   s   i | ]}|j |qS r   )r   ).0r/   r   r   r   
<dictcomp>   s    rV   )r   r   r;   r   rC   sixgoogle.authr   r   rA   r   add_metaclassABCMetaobjectr	   r   r(   AVAILABLE_CHALLENGESr   r   r   r   <module>   s"   
!6

