
    -Gj:B                         d Z ddlZddlmZ ddlZddlZddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ 	 dd
Z	 ddZddZddZ	 	 	 ddZddZ	 ddZ	 ddZdS )a  OAuth 2.0 async client.

This is a client for interacting with an OAuth 2.0 authorization server's
token endpoint.

For more information about the token endpoint, see
`Section 3.1 of rfc6749`_

.. _Section 3.1 of rfc6749: https://tools.ietf.org/html/rfc6749#section-3.2
    N)_exponential_backoff)_helpers)
exceptions)jwt)_clientFTc                   K   |r6dt           j        i}t          j        |                              d          }n@dt           j        i}t          j                            |                              d          }|rd	                    |          |d<   i }d}t          j                    }	|	D ]}
 | d|||           d{V }|                                 d{V }t          |d	          r|                    d          n|}	 t          j        |          }n# t           $ r |}Y nw xY w|j        t$          j        k    rd
|dfc S t          j        |j        |          }|r|sd||fc S d||fS )a  Makes a request to the OAuth 2.0 authorization server's token endpoint.
    This function doesn't throw on response errors.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        token_uri (str): The OAuth 2.0 authorizations server's token endpoint
            URI.
        body (Mapping[str, str]): The parameters to send in the request body.
        access_token (Optional(str)): The access token needed to make the request.
        use_json (Optional(bool)): Use urlencoded format or json format for the
            content type. The default value is False.
        can_retry (bool): Enable or disable request retry behavior.

    Returns:
        Tuple(bool, Mapping[str, str], Optional[bool]): A boolean indicating
          if the request is successful, a mapping for the JSON-decoded response
          data and in the case of an error a boolean indicating if the error
          is retryable.
    zContent-Typeutf-8z	Bearer {}AuthorizationFPOST)methodurlheadersbodyNdecodeTstatus_coderesponse_data)client_JSON_CONTENT_TYPEjsondumpsencode_URLENCODED_CONTENT_TYPEurllibparse	urlencodeformatr   ExponentialBackoffcontenthasattrr   loads
ValueErrorstatushttp_clientOK
_can_retry)request	token_urir   access_tokenuse_json	can_retryr   r   retryable_errorretries_responseresponse_body1response_bodys                 c/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/google/oauth2/_client_async.py _token_endpoint_request_no_throwr3   &   s     .  <!6#<=z$&&w//!6#BC|%%d++227;; D#.#5#5l#C#C MO"577G 9 9 y'
 
 
 
 
 
 
 
 

  (//11111111 ~x00 N!!'*** 		* J}55MM 	* 	* 	*)MMM	* ?kn,,,,,, + }
 
 
  	9 	9-8888	9 -00s   DD+*D+c                 v   K   t          | |||||           d{V \  }}}|st          j        ||           |S )a=  Makes a request to the OAuth 2.0 authorization server's token endpoint.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        token_uri (str): The OAuth 2.0 authorizations server's token endpoint
            URI.
        body (Mapping[str, str]): The parameters to send in the request body.
        access_token (Optional(str)): The access token needed to make the request.
        use_json (Optional(bool)): Use urlencoded format or json format for the
            content type. The default value is False.
        can_retry (bool): Enable or disable request retry behavior.

    Returns:
        Mapping[str, str]: The JSON-decoded response data.

    Raises:
        google.auth.exceptions.RefreshError: If the token endpoint returned
            an error.
    )r)   r*   r+   N)r3   r   _handle_error_response)	r'   r(   r   r)   r*   r+   response_status_okr   r,   s	            r2   _token_endpoint_requestr7   k   s|      8 /!   	 	 	 	 	 		  F%m_EEE    c                    K   |t           j        d}t          | |||           d{V }	 |d         }n,# t          $ r}t	          j        d|d          }||d}~ww xY wt          j        |          }	||	|fS )a  Implements the JWT Profile for OAuth 2.0 Authorization Grants.

    For more details, see `rfc7523 section 4`_.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        token_uri (str): The OAuth 2.0 authorizations server's token endpoint
            URI.
        assertion (str): The OAuth 2.0 assertion.
        can_retry (bool): Enable or disable request retry behavior.

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

    Raises:
        google.auth.exceptions.RefreshError: If the token endpoint returned
            an error.

    .. _rfc7523 section 4: https://tools.ietf.org/html/rfc7523#section-4
    	assertion
grant_typer+   Nr)   zNo access token in response.F	retryable)r   _JWT_GRANT_TYPEr7   KeyErrorr   RefreshError_parse_expiry)
r'   r(   r;   r+   r   r   r)   
caught_excnew_excexpirys
             r2   	jwt_grantrG      s      . #&2HIID1DI        M&$^4 & & &)*MU
 
 
 :%	& !-00F..   5 
AAAc                 ,  K   |t           j        d}t          | |||           d{V }	 |d         }n,# t          $ r}t	          j        d|d          }||d}~ww xY wt          j        |d          }	t          j	        |	d	                   }
||
|fS )
a:  Implements the JWT Profile for OAuth 2.0 Authorization Grants, but
    requests an OpenID Connect ID Token instead of an access token.

    This is a variant on the standard JWT Profile that is currently unique
    to Google. This was added for the benefit of authenticating to services
    that require ID Tokens instead of access tokens or JWT bearer tokens.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        token_uri (str): The OAuth 2.0 authorization server's token endpoint
            URI.
        assertion (str): JWT token signed by a service account. The token's
            payload must include a ``target_audience`` claim.
        can_retry (bool): Enable or disable request retry behavior.

    Returns:
        Tuple[str, Optional[datetime], Mapping[str, str]]:
            The (encoded) Open ID Connect ID Token, expiration, and additional
            data returned by the endpoint.

    Raises:
        google.auth.exceptions.RefreshError: If the token endpoint returned
            an error.
    r:   r=   Nid_tokenzNo ID token in response.Fr>   )verifyexp)
r   r@   r7   rA   r   rB   r   r   r   utcfromtimestamp)r'   r(   r;   r+   r   r   rJ   rD   rE   payloadrF   s              r2   id_token_jwt_grantrO      s      4 #&2HIID1DI        M& , & & &)&
 
 
 :%	& j%000G&wu~66FV]**rH   c                    K   t           j        |||d}|rd                    |          |d<   |r||d<   t          | |||           d{V }	t          j        |	|          S )a0  Implements the OAuth 2.0 refresh token grant.

    For more details, see `rfc678 section 6`_.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        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 reauth Proof Token.
        can_retry (bool): Enable or disable request retry behavior.

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

    Raises:
        google.auth.exceptions.RefreshError: If the token endpoint returned
            an error.

    .. _rfc6748 section 6: https://tools.ietf.org/html/rfc6749#section-6
    )r<   	client_idclient_secretrefresh_token scoperaptr=   N)r   _REFRESH_GRANT_TYPEjoinr7   _handle_refresh_grant_response)
r'   r(   rS   rQ   rR   scopes
rapt_tokenr+   r   r   s
             r2   refresh_grantr\      s      T 0&&	 D  )((W "!V1DI        M 0NNNr8   c                    K   t          | |||           d{V }|dS t          |t                    rd|vr"t          j                            d|           dS |S )a  Implements the global lookup of a credential Regional Access Boundary.
    For the lookup, we send a request to the global lookup endpoint and then
    parse the response. Service account credentials, workload identity
    pools and workforce pools implementation may have Regional Access Boundaries configured.
    Args:
        request (google.auth.aio.transport.Request): A callable used to make
            HTTP requests. The returned response must support `await response.read()`
            (standard async transport) or `await response.content()` (legacy/custom transport).
        url (str): The Regional Access Boundary lookup url.
        headers (Optional[Mapping[str, str]]): The headers for the request.
        fail_fast (bool): Whether the lookup should fail fast (uses a short timeout and no retries).
    Returns:
        Optional[Mapping[str,list|str]]: A dictionary containing
            "locations" as a list of allowed locations as strings and
            "encodedLocations" as a hex string.
            e.g:
            {
                "locations": [
                    "us-central1", "us-east1", "europe-west1", "asia-east1"
                ],
                "encodedLocations": "0xA30"
            }
    )r   	fail_fastNencodedLocationszQRegional Access Boundary response malformed: missing 'encodedLocations' key in %s)(_lookup_regional_access_boundary_request
isinstancedictr   _LOGGERerror)r'   r   r   r^   r   s        r2    _lookup_regional_access_boundaryre   &  s      0 Cg        M tmT** .@.U.U_	
 	
 	
 tr8   c                    K   t          | ||||           d{V \  }}}|s#t          j                            d||           dS |S )a  Makes a request to the Regional Access Boundary lookup endpoint.

    Args:
        request (google.auth.aio.transport.Request): A callable used to make
            HTTP requests. The returned response must support `await response.read()`
            (standard async transport) or `await response.content()` (legacy/custom transport).
        url (str): The Regional Access Boundary lookup url.
        can_retry (bool): Enable or disable request retry behavior. Defaults to true.
        headers (Optional[Mapping[str, str]]): The headers for the request.
        fail_fast (bool): Whether the lookup should fail fast (uses a short timeout and no retries).

    Returns:
        Optional[Mapping[str, str]]: The JSON-decoded response data on success, or None on failure.
    )r+   r   r^   Nz`Regional Access Boundary HTTP request failed after retries: response_data=%s, retryable_error=%s)1_lookup_regional_access_boundary_request_no_throwr   rc   debug)r'   r   r+   r   r^   r6   r   r,   s           r2   r`   r`   N  s      * @	7i   	 	 	 	 	 		  n	
 	
 	

 tr8   c           	        K   i }d}|rt           j        nd}|rdnd}t          j        |          }	|	2 3 d{V }
	 |r*t	          j         | d|||          |           d{V }n | d||	           d{V }t          |d
          r|                                 d{V }n|                                 d{V }n@# t          j	        t          j        f$ r d}|s	di |fcY c S Y t          $ r
 di dfcY c S w xY w	 t          |d          r|                    d          n|}t          j        |          }n# t           t"          f$ r i }Y nw xY wt          |d          r|j        n|j        }|t(          j        k    rd|dfc S t          j        ||          }|t(          j        k    rd}|r|sd||fc S 6 d||fS )a  Makes a request to the Regional Access Boundary lookup endpoint. This
        function doesn't throw on response errors.

    Args:
        request (google.auth.aio.transport.Request): A callable used to make
            HTTP requests. The returned response must support `await response.read()`
            (standard async transport) or `await response.content()` (legacy/custom transport).
        url (str): The Regional Access Boundary lookup url.
        can_retry (bool): Enable or disable request retry behavior. Defaults to true.
        headers (Optional[Mapping[str, str]]): The headers for the request.
        fail_fast (bool): Whether the lookup should fail fast (uses a short timeout and no retries).

    Returns:
        Tuple(bool, Mapping[str, str], Optional[bool]): A boolean indicating
          if the request is successful, a mapping for the JSON-decoded response
          data and in the case of an error a boolean indicating if the error
          is retryable.
    FN      )total_attemptsGET)r   r   r   timeout)rn   )r   r   r   readTr   r	   r   r   )r   1_BLOCKING_REGIONAL_ACCESS_BOUNDARY_LOOKUP_TIMEOUTr   AsyncExponentialBackoffasynciowait_forr    ro   r   TimeoutErrorr   TransportError	Exceptionr   r   r!   UnicodeDecodeErrorr"   r   r#   r$   r%   r&   BAD_GATEWAY)r'   r   r+   r   r^   r   r,   rn   rl   r-   r.   r/   response_bytesr1   r   s                  r2   rg   rg   p  s     , MO ENW@@SW  $*QQN":%  G  39 39 39 39 39 39 39a	$ Q!(!1G5c7GTTT#" " "      
 ")3!P!P!PPPPPPP x(( :'/}}!6!6!6!6!6!6'/'7'7'9'9!9!9!9!9!9!9$j&?@ 	 	 	"O 2b/111111H 	$ 	$ 	$"e######	$		 >844$%%g...# 
 !J}55MM"J/ 	 	 	MMM	 x//!H   	 +.((,,,, +#=
 
 
 +111"O 	9 	9-8888	9e j -00s/   GBC$C?,C?>C?;D??EE)NFT)T)NNT)NF)TNF)__doc__rr   http.clientr   r$   r   r   google.authr   r   r   r   google.oauth2r   r3   r7   rG   rO   r\   re   r`   rg    r8   r2   <module>r      s|  	 	  ! ! ! ! ! !   , , , , , ,             " " " " " "       + + + + + + LPB1 B1 B1 B1L LP& & & &R'/ '/ '/ '/T++ ++ ++ ++h 7O 7O 7O 7Ot% % % %R ;@   F ;@V1 V1 V1 V1 V1 V1r8   