
    (ph-                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr   SS jr	S	 r
S
 rS r SS jr   SS jrg)a  A module that provides functions for handling rapt authentication.

Reauth is a process of obtaining additional authentication (such as password,
security token, etc.) while refreshing OAuth 2.0 credentials for a user.

Credentials that use the Reauth flow must have the reauth scope,
``https://www.googleapis.com/auth/accounts.reauth``.

This module provides a high-level function for executing the Reauth process,
:func:`refresh_grant`, and lower-level helpers for doing the individual
steps of the reauth process.

Those steps are:

1. Obtaining a list of challenges from the reauth server.
2. Running through each challenge and sending the result back to the reauth
   server.
3. Refreshing the access token using the returned rapt token.
    N)
exceptions)_client)_client_async)
challenges)reauthc                    #    SU0nU(       a  X4S'   [         R                  " U [        R                  S-   UUSS9I Sh  vN $  N7f)a  Does initial request to reauth API to get the challenges.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    supported_challenge_types (Sequence[str]): list of challenge names
        supported by the manager.
    access_token (str): Access token with reauth scopes.
    requested_scopes (Optional(Sequence[str])): Authorized scopes for the credentials.

Returns:
    dict: The response from the reauth API.
supportedChallengeTypes oauthScopesForDomainPolicyLookupz:startTaccess_tokenuse_jsonN)r   _token_endpoint_requestr   _REAUTH_API)requestsupported_challenge_typesr   requested_scopesbodys        N/var/www/html/venv/lib/python3.13/site-packages/google/oauth2/_reauth_async.py_get_challengesr   ,   sU       &'@AD3C/066X%!   s   <AAAc                    #    UUSUS.n[         R                  " U [        R                  SR	                  U5      -   UUSS9I Sh  vN $  N7f)aN  Attempt to refresh access token by sending next challenge result.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    session_id (str): session id returned by the initial reauth call.
    challenge_id (str): challenge id returned by the initial reauth call.
    client_input: dict with a challenge-specific client input. For example:
        ``{'credential': password}`` for password challenge.
    access_token (str): Access token with reauth scopes.

Returns:
    dict: The response from the reauth API.
RESPOND)	sessionIdchallengeIdactionproposalResponsez/{}:continueTr   N)r   r   r   r   format)r   
session_idchallenge_idclient_inputr   r   s         r   _send_challenge_resultr    I   s^     $  #(	D 66^22:>>!   s   AAA
Ac                 .  #    U S    GH  nUS   S:w  a  M  [         R                  R                  US   S5      nU(       d]  [        R                  " SR                  US   SR                  [        [         R                  R                  5       5      5      5      5      eUR                  (       d(  [        R                  " SR                  US   5      5      eUR                  U5      nU(       d    g[        UU S	   US
   UU5      I Sh  vN s  $    g N	7f)aT  Get the next challenge from msg and run it.

Args:
    msg (dict): Reauth API response body (either from the initial request to
        https://reauth.googleapis.com/v2/sessions:start or from sending the
        previous challenge response to
        https://reauth.googleapis.com/v2/sessions/id:continue)
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    access_token (str): reauth access token

Returns:
    dict: The response from the reauth API.

Raises:
    google.auth.exceptions.ReauthError: if reauth failed.
r   statusREADYchallengeTypeNz4Unsupported challenge type {0}. Supported types: {1},z%Challenge {0} is not locally eligibler   r   )r   AVAILABLE_CHALLENGESgetr   ReauthFailErrorr   joinlistkeysis_locally_eligibleobtain_challenge_inputr    )msgr   r   	challengecr   s         r   _run_next_challenger1   j   s    $ &	X')++//	/0JDQ,,FMMo.HHT*"A"A"F"F"HIJ  $$,,7>>o. 
 //	:+m$
 
 	
+ '8 
s   DD	D

Dc                   #    [        U [        [        R                  R	                  5       5      UU5      I Sh  vN nUS   [
        R                  :X  a  US   $ [        S[
        R                  5       H  nUS   [
        R                  :X  d?  US   [
        R                  :X  d(  [        R                  " SR                  US   5      5      e[
        R                  " 5       (       d  [        R                  " S5      e[        X0U5      I Sh  vN nUS   [
        R                  :X  d  M  US   s  $    [        R                  " S5      e GN N?7f)a  Given an http request method and reauth access token, get rapt token.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    access_token (str): reauth access token
    requested_scopes (Sequence[str]): scopes required by the client application

Returns:
    str: The rapt token.

Raises:
    google.auth.exceptions.ReauthError: if reauth failed
Nr"   encodedProofOfReauthTokenr   z6Reauthentication challenge failed due to API error: {}z_Reauthentication challenge could not be answered because you are not in an interactive session.zFailed to obtain rapt token.)r   r*   r   r&   r+   r   _AUTHENTICATEDrangeRUN_CHALLENGE_RETRY_LIMIT_CHALLENGE_REQUIRED_CHALLENGE_PENDINGr   r(   r   is_interactiver1   )r   r   r   r.   _s        r   _obtain_raptr;      s1      Z,,1134	 C 8}---.//1f667MV7778} 9 99,,HOOM  $$&&,,. 
 (lCCx=F111233) 8. 
$
$%C
DDC6 Ds(   7EE	CEEE* EEc           	         #    [         R                  R                  S5        [        R                  " U UUUU[
        R                  /S9I Sh  vN u  n    n[        XUS9I Sh  vN nU$  N N7f)ah  Given an http request method and refresh_token, get rapt token.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    client_id (str): client id to get access token for reauth scope.
    client_secret (str): client secret for the client_id
    refresh_token (str): refresh token to refresh access token
    token_uri (str): uri to refresh access token
    scopes (Optional(Sequence[str])): scopes required by the client application

Returns:
    str: The rapt token.
Raises:
    google.auth.exceptions.RefreshError: If reauth failed.
zReauthentication required.
)r   	client_idclient_secretrefresh_token	token_uriscopesN)r   )sysstderrwriter   refresh_grantr   _REAUTH_SCOPEr;   )	r   r=   r>   r?   r@   rA   r   r:   
rapt_tokens	            r   get_rapt_tokenrH      sw     & JJ34 #0"="=##$$%# L!Q $GFSSJ Ts$   AA/A+A/$A-%A/-A/c           	        #    [         R                  UUUS.nU(       a  SR                  U5      US'   U(       a  XhS'   [        R                  " XU5      I Sh  vN u  pnU	(       d  U
R                  S5      [        R                  :X  a  U
R                  S5      [        R                  :X  d#  U
R                  S5      [        R                  :X  aW  U(       d  [        R                  " S5      e[        XXBXS	9I Sh  vN nXhS'   [        R                  " XU5      I Sh  vN u  n	n
nU	(       d  [         R                  " X5        [         R                  " X5      nX4-   $  GN Nf NE7f)
a  Implements the reauthentication flow.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests. This must be an aiohttp request.
    token_uri (str): The OAuth 2.0 authorizations server's token endpoint
        URI.
    refresh_token (str): The refresh token to use to get a new access
        token.
    client_id (str): The OAuth 2.0 application's client ID.
    client_secret (str): The Oauth 2.0 appliaction's client secret.
    scopes (Optional(Sequence[str])): Scopes to request. If present, all
        scopes must be authorized for the refresh token. Useful if refresh
        token has a wild card scope (e.g.
        'https://www.googleapis.com/auth/any-api').
    rapt_token (Optional(str)): The rapt token for reauth.
    enable_reauth_refresh (Optional[bool]): Whether reauth refresh flow
        should be used. The default value is False. This option is for
        gcloud only, other users should use the default value.

Returns:
    Tuple[str, Optional[str], Optional[datetime], Mapping[str, str], str]: The
        access token, new refresh token, expiration, the additional data
        returned by the token endpoint, and the rapt token.

Raises:
    google.auth.exceptions.RefreshError: If the token endpoint returned
        an error.
)
grant_typer=   r>   r?    scoperaptNerrorerror_subtypezaReauthentication is needed. Please run `gcloud auth application-default login` to reauthenticate.)rA   )r   _REFRESH_GRANT_TYPEr)   r    _token_endpoint_request_no_throwr'   r   _REAUTH_NEEDED_ERROR!_REAUTH_NEEDED_ERROR_INVALID_RAPT"_REAUTH_NEEDED_ERROR_RAPT_REQUIREDr   RefreshErrorrH   _handle_error_response_handle_refresh_grant_response)r   r@   r?   r=   r>   rA   rG   enable_reauth_refreshr   response_status_okresponse_dataretryable_errorrefresh_responses                r   rE   rE      sa    P 11&&	D (W!V?L?m?mD@ :6 g&&*E*EEo.778  1889 %))s  *i
 

 "V
  @@
 
		

 &&}F== m++G:$

s8   AE&EB"E&;E"<"E&E$AE&"E&$E&)N)NNF)__doc__rB   google.authr   google.oauth2r   r   r   r   r   r    r1   r;   rH   rE        r   <module>rb      s[   (  " ! ' $   HL:B.b0Eh IM"V U,ra   