
    (phC                        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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      H/var/www/html/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_retryr0   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   r2   s     r   _parse_expiryr8   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-Typez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datarA   loadsr   statushttp_clientOKr0   )request	token_urir@   access_tokenuse_json	can_retryr?   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.
)rR   rS   rT   r?   )r[   r   )rP   rQ   r@   rR   rS   rT   r?   rU   response_status_okr   r   s              r   _token_endpoint_requestr^      sO    N :Z	: "	: 	:6 }>r9   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rT   r?   rR   No access token in response.Fr   N)	_JWT_GRANT_TYPEr^   r   API_CLIENT_HEADER'token_request_access_token_sa_assertionr   r   r   r8   )
rP   rQ   ra   rT   r@   r   rR   
caught_excnew_excexpirys
             r   	jwt_grantrk     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.

Returns:
    Tuple[str, datetime]: The ID token and expiration.
true)audienceincludeEmailuseEmailAzpT)rR   rS   tokenNo ID token in response.Fr   Nverifyexp)r^   replacer   DEFAULT_UNIVERSE_DOMAINr   r   r   r   r   rA   r6   utcfromtimestamp)rP   iam_id_token_endpointsigner_emailrn   rR   universe_domainr@   r   id_tokenrh   ri   payloadrj   s                r   #call_iam_generate_id_token_endpointr~   B  s    , !&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.
r`   rc   r|   rr   Fr   Nrs   ru   )re   r^   r   rf   #token_request_id_token_sa_assertionr   r   r   r   rA   r6   rx   )rP   rQ   ra   rT   r@   r   r|   rh   ri   r}   rj   s              r   id_token_jwt_grantr   r  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.
rR   rd   Fr   Nr
   )r   r   r   r   r8   )r   r
   rR   rh   ri   rj   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
)rb   	client_idclient_secretr
    scoperapt)rT   )_REFRESH_GRANT_TYPEjoinr^   r   )
rP   rQ   r
   r   r   scopes
rapt_tokenrT   r@   r   s
             r   refresh_grantr     sU    T *&&	D (W!V+DM *-GGr9   )NFTN)T)NNT)__doc__r6   http.clientclientrN   r   rE   google.authr   r   r   r   r   r   r	   rD   rB   re   r   r   r0   r8   r[   r^   rk   rw   r~   r   r   r   r$   r9   r   <module>r      s   	  !   ,   # "   !> ' ?% :$N6 Q1p 3l-/l  77-`1+h>J 7Hr9   