
    kCi~U                     .   S r SSKrSSKJr  SSK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KJr  SS	KJr  S
rSrSrSrS rS rS r    SS jr    SS jrSS jr\
R2                  4S jrSS jrS r   SS jrSS jrSS jrSS jr g) a  OAuth 2.0 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)credentials)
exceptions)jwt)metrics)	transportz!application/x-www-form-urlencodedzapplication/jsonz+urn:ietf:params:oauth:grant-type:jwt-bearerrefresh_tokenc                 6   U(       a  UOSn[        U [        5      (       a  [        R                  " XS9e SR	                  U S   U R                  S5      5      n[        R                  " X US9e! [        [        4 a    [        R                  " U 5      n N=f = f)a<  Translates an error response into an exception.

Args:
    response_data (Mapping | str): The decoded response data.
    retryable_error Optional[bool]: A boolean indicating if an error is retryable.
        Defaults to False.

Raises:
    google.auth.exceptions.RefreshError: The errors contained in response_data.
F	retryablez{}: {}errorerror_description)

isinstancestrr   RefreshErrorformatgetKeyError
ValueErrorjsondumps)response_dataretryable_errorerror_detailss      Q/var/www/html/land-ocr/venv/lib/python3.13/site-packages/google/oauth2/_client.py_handle_error_responser   -   s     *9oeO-%%%%mOO2 '"M$5$56I$J
 
!
!  j! 2

=12s   $A/ /&BBc                 R  ^ U [         R                  ;   a  g UR                  S5      =(       d    SnUR                  S5      =(       d    Sn[        U[        5      (       a  [        U[        5      (       d  g1 Skm[        U4S jX24 5       5      (       a  g g! [         a     gf = f)a  Checks if a request can be retried by inspecting the status code
and response body of the request.

Args:
    status_code (int): The response status code.
    response_data (Mapping | str): The decoded response data.

Returns:
  bool: True if the response is retryable. False otherwise.
Tr    r   F>   server_errorinternal_failuretemporarily_unavailablec              3   ,   >#    U  H	  oT;   v   M     g 7fN ).0eretryable_error_descriptionss     r   	<genexpr>_can_retry.<locals>.<genexpr>h   s     S:RQ00:Rs   )r	   DEFAULT_RETRYABLE_STATUS_CODESr   r   r   anyAttributeError)status_coder   
error_desc
error_coder(   s       @r   
_can_retryr1   J   s     i>>>"&&':;Ar
"&&w/52
*c***Z2M2M(
$ S::RSSS T   s   AB 7B 
B&%B&c                     U R                  SS5      nUbJ  [        U[        5      (       a  [        U5      n[        R
                  " 5       [        R                  " US9-   $ g)zParses the expiry field from a response into a datetime.

Args:
    response_data (Mapping): The JSON-parsed response data.

Returns:
    Optional[datetime]: The expiration or ``None`` if no expiration was
        specified.

expires_inN)seconds)r   r   r   intr   utcnowdatetime	timedelta)r   r3   s     r   _parse_expiryr9   q   sT     ""<6J j#&&ZJ 8#5#5j#III    c           	         U(       a.  S[         0n[        R                  " U5      R                  S5      nO6S[        0n[
        R                  R                  U5      R                  S5      nU(       a  SR                  U5      US'   U(       a  UR                  U5        0 n	Sn
[        R                  " 5       nU H  nU " SSXUS.UD6n[        UR                  S5      (       a  UR                  R                  S5      OUR                  n [        R                  " U5      n	UR"                  [$        R&                  :X  a  S	U	S
4s  $ [)        UR"                  U	S9n
U(       a	  U
(       a  M  SX4s  $    SX4$ ! [          a    Un	 Ncf = f)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.
    headers (Optional[Mapping[str, str]]): The headers for the request.
    kwargs: Additional arguments passed on to the request method. The
        kwargs will be passed to `requests.request` method, see:
        https://docs.python-requests.org/en/latest/api/#requests.request.
        For example, you can use `cert=("cert_pem_path", "key_pem_path")`
        to set up client side SSL certificate, and use
        `verify="ca_bundle_path"` to set up the CA certificates for sever
        side SSL certificate verification.

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bodydecodeTNr.   r   r%   )_JSON_CONTENT_TYPEr   r   encode_URLENCODED_CONTENT_TYPEurllibparse	urlencoder   updater   ExponentialBackoffhasattrdatarC   loadsr   statushttp_clientOKr1   )request	token_urirB   access_tokenuse_json	can_retryrA   kwargsheaders_to_user   r   retries_responseresponse_bodys                  r    _token_endpoint_request_no_throwr^      sn   L (*<=zz$&&w/(*BC||%%d+227;*5*<*<\*J'g&MO"557G 
yt
OU

 x}}h// MM  ) 		* JJ}5M ??knn,,,$ }
 -881 4 -00  	*)M	*s   E77FFc                 V    [        U UU4UUUUS.UD6u  pn
U(       d  [        X5        U	$ )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.
    headers (Optional[Mapping[str, str]]): The headers for the request.
    kwargs: Additional arguments passed on to the request method. The
        kwargs will be passed to `requests.request` method, see:
        https://docs.python-requests.org/en/latest/api/#requests.request.
        For example, you can use `cert=("cert_pem_path", "key_pem_path")`
        to set up client side SSL certificate, and use
        `verify="ca_bundle_path"` to set up the CA certificates for sever
        side SSL certificate verification.

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

Raises:
    google.auth.exceptions.RefreshError: If the token endpoint returned
        an error.
)rU   rV   rW   rA   )r^   r   )rS   rT   rB   rU   rV   rW   rA   rX   response_status_okr   r   s              r   _token_endpoint_requestra      sO    N :Z	: "	: 	:6 }>r:   c           	          U[         S.n[        U UUU[        R                  [        R                  " 5       0S9n US   n[        U5      n	XiU4$ ! [
         a  n[        R                  " SUSS9nXeSnAff = f)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rW   rA   rU   No access token in response.Fr   N)	_JWT_GRANT_TYPEra   r   API_CLIENT_HEADER'token_request_access_token_sa_assertionr   r   r   r9   )
rS   rT   rd   rW   rB   r   rU   
caught_excnew_excexpirys
             r   	jwt_grantrn     s    . #/BD+%%w'V'V'X
M&$^4 =)F..  &))*MU
 %	&s   A 
A6A11A6c                 V   USSS.n[        U UR                  [        R                  U5      R	                  U5      UUSS9n US   n[        R                  " USS
9n[        R                  R                  US   5      nX4$ ! [
         a  n	[        R                  " SUSS9n
XeS	n	A	ff = f)a`  Call iam.generateIdToken endpoint to get ID token.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests.
    iam_id_token_endpoint (str): The IAM ID token endpoint to use.
    signer_email (str): The signer email used to form the IAM
        generateIdToken endpoint.
    audience (str): The audience for the ID token.
    access_token (str): The access token used to call the IAM endpoint.
    universe_domain (str): The universe domain for the request. The
        default is ``googleapis.com``.

Returns:
    Tuple[str, datetime]: The ID token and expiration.
true)audienceincludeEmailuseEmailAzpT)rU   rV   tokenNo ID token in response.Fr   Nverifyexp)ra   replacer   DEFAULT_UNIVERSE_DOMAINr   r   r   r   r   rC   r7   utcfromtimestamp)rS   iam_id_token_endpointsigner_emailrq   rU   universe_domainrB   r   id_tokenrk   rl   payloadrm   s                r   #call_iam_generate_id_token_endpointr   B  s    0 !&PD+%%//	

&
!M& ) jj%0G//?F  &))&
 %	&s   B 
B(B##B(c           	      J   U[         S.n[        U UUU[        R                  [        R                  " 5       0S9n US   n[        R                  " USS9n	[        R                  R                  U	S	   5      n
XjU4$ ! [
         a  n[        R                  " SUSS9nXeSnAff = f)
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.
rc   rf   r   ru   Fr   Nrv   rx   )rh   ra   r   ri   #token_request_id_token_sa_assertionr   r   r   r   rC   r7   r{   )rS   rT   rd   rW   rB   r   r   rk   rl   r   rm   s              r   id_token_jwt_grantr   t  s    4 #/BD+%%w'R'R'T
M& , jj%0G//?F]**  &))&
 %	&s   A; ;
B"BB"c                      U S   nU R                  SU5      n[	        U 5      nX!XP4$ ! [          a  n[        R                  " SU SS9nXCeSnAff = f)a'  Extract tokens from refresh grant response.

Args:
    response_data (Mapping[str, str]): Refresh grant response data.
    refresh_token (str): Current refresh token.

Returns:
    Tuple[str, str, Optional[datetime], Mapping[str, str]]: The access token,
        refresh token, expiration, and additional data returned by the token
        endpoint. If response_data doesn't have refresh token, then the current
        refresh token will be returned.

Raises:
    google.auth.exceptions.RefreshError: If the token endpoint returned
        an error.
rU   rg   Fr   Nr
   )r   r   r   r   r9   )r   r
   rU   rk   rl   rm   s         r   _handle_refresh_grant_responser     sk    "&$^4 "%%o}EM=)F==  &))*MU
 %	&s   ( 
AA

Ac                     [         UUUS.nU(       a  SR                  U5      US'   U(       a  XhS'   [        XXS9n	[        X5      $ )a  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, 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
)re   	client_idclient_secretr
    scoperapt)rW   )_REFRESH_GRANT_TYPEjoinra   r   )
rS   rT   r
   r   r   scopes
rapt_tokenrW   rB   r   s
             r   refresh_grantr     sU    T *&&	D (W!V+DM *-GGr:   c                 p    [        XUS9nSU;  a%  [        R                  " SR                  U5      5      eU$ )a  Implements the global lookup of a credential trust 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 trust boundaries configured.
Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests.
    url (str): The trust boundary lookup url.
    headers (Optional[Mapping[str, str]]): The headers for the request.
Returns:
    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"
        }
        If the credential is not set up with explicit trust boundaries, a trust boundary
        of "all" will be returned as a default response.
        {
            "locations": [],
            "encodedLocations": "0x0"
        }
Raises:
    exceptions.RefreshError: If the response status code is not 200.
    exceptions.MalformedError: If the response is not in a valid format.
)rA   encodedLocationszInvalid trust boundary info: {})_lookup_trust_boundary_requestr   MalformedErrorr   )rS   r@   rA   r   s       r   _lookup_trust_boundaryr     sB    @ 37QM.''-44]C
 	
 r:   c                 H    [        XX#5      u  pEnU(       d  [        XV5        U$ )a  Makes a request to the trust boundary lookup endpoint.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests.
    url (str): The trust 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.

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

Raises:
    google.auth.exceptions.RefreshError: If the token endpoint returned
        an error.
)'_lookup_trust_boundary_request_no_throwr   )rS   r@   rW   rA   r`   r   r   s          r   r   r   *  s-    " :ai:6 }>r:   c                    0 nSn[         R                  " 5       nU H  nU " SXS9n[        UR                  S5      (       a  UR                  R	                  S5      OUR                  n	 [
        R                  " U	5      nUR                  [        R                  :X  a  SUS4s  $ [        UR                  US9nU(       a	  U(       a  M  SXE4s  $    SXE4$ ! [         a    U	n Ncf = f)	a  Makes a request to the trust boundary lookup endpoint. This
    function doesn't throw on response errors.

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests.
    url (str): The trust 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.

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.
FGET)r?   r@   rA   rC   r<   TNrD   )r   rL   rM   rN   rC   r   rO   r   rP   rQ   rR   r1   )
rS   r@   rW   rA   r   r   rZ   r[   r\   r]   s
             r   r   r   C  s    $ MO"557G%SB x}}h// MM  ) 		* JJ}5M ??knn,,,$ }
 -88- 0 -00  	*)M	*s   )CC#"C#)NFTN)T)NNTr$   )TN)!__doc__r7   http.clientclientrQ   r   rH   google.authr   r   r   r   r   r   r	   rG   rE   rh   r   r   r1   r9   r^   ra   rn   rz   r   r   r   r   r   r   r   r%   r:   r   <module>r      s   	  !   ,   # "   !> ' ?% :$N6 Q1p 3l-/l  77/d1+h>J 7Ht&R2.1r:   