
    (ph                         S r SSKrSSKrSSKrSSKrSSKJr   " S S\R                  5      r " S S\	5      r
 " S S	\R                  S
9rS rg)a'  OAuth 2.0 Utilities.

This module provides implementations for various OAuth 2.0 utilities.
This includes `OAuth error handling`_ and
`Client authentication for OAuth flows`_.

OAuth error handling
--------------------
This will define interfaces for handling OAuth related error responses as
stated in `RFC 6749 section 5.2`_.
This will include a common function to convert these HTTP error responses to a
:class:`google.auth.exceptions.OAuthError` exception.


Client authentication for OAuth flows
-------------------------------------
We introduce an interface for defining client authentication credentials based
on `RFC 6749 section 2.3.1`_. This will expose the following
capabilities:

    * Ability to support basic authentication via request header.
    * Ability to support bearer token authentication via request header.
    * Ability to support client ID / secret authentication via request body.

.. _RFC 6749 section 2.3.1: https://tools.ietf.org/html/rfc6749#section-2.3.1
.. _RFC 6749 section 5.2: https://tools.ietf.org/html/rfc6749#section-5.2
    N)
exceptionsc                       \ rS rSrSrSrSrg)ClientAuthType5          N)__name__
__module____qualname____firstlineno__basicrequest_body__static_attributes__r	       F/var/www/html/venv/lib/python3.13/site-packages/google/oauth2/utils.pyr   r   5   s    ELr   r   c                   "    \ rS rSrSrSS jrSrg)ClientAuthentication:   zDefines the client authentication credentials for basic and request-body
types based on https://tools.ietf.org/html/rfc6749#section-2.3.1.
Nc                 (    Xl         X l        X0l        g)aH  Instantiates a client authentication object containing the client ID
and secret credentials for basic and response-body auth.

Args:
    client_auth_type (google.oauth2.oauth_utils.ClientAuthType): The
        client authentication type.
    client_id (str): The client ID.
    client_secret (Optional[str]): The client secret.
Nclient_auth_type	client_idclient_secret)selfr   r   r   s       r   __init__ClientAuthentication.__init__?   s     !1"*r   r   N)r
   r   r   r   __doc__r   r   r	   r   r   r   r   :   s    +r   r   c                   L   ^  \ rS rSrSrSU 4S jjr S	S jrSS jrS rSr	U =r
$ )
OAuthClientAuthHandlerN   zMAbstract class for handling client authentication in OAuth-based
operations.
c                 6   > [         [        U ]  5         Xl        g)zInstantiates an OAuth client authentication handler.

Args:
    client_authentication (Optional[google.oauth2.utils.ClientAuthentication]):
        The OAuth client authentication credentials if available.
N)superr!   r   _client_authentication)r   client_authentication	__class__s     r   r   OAuthClientAuthHandler.__init__S   s     	$d46&;#r   c                 P    U R                  X5        Uc  U R                  U5        gg)a|  Applies client authentication on the OAuth request's headers or POST
body.

Args:
    headers (Mapping[str, str]): The HTTP request header.
    request_body (Optional[Mapping[str, str]]): The HTTP request body
        dictionary. For requests that do not support request body, this
        is None and will be ignored.
    bearer_token (Optional[str]): The optional bearer token.
N)_inject_authenticated_headers"_inject_authenticated_request_body)r   headersr   bearer_tokens       r   #apply_client_authentication_options:OAuthClientAuthHandler.apply_client_authentication_options]   s+     	**7A33LA  r   c                 t   Ub	  SU-  US'   g U R                   b  U R                   R                  [        R                  L aw  U R                   R                  nU R                   R
                  =(       d    Sn[        R                  " U< SU< 3R                  5       5      R                  5       nSU-  US'   g g g )Nz	Bearer %sAuthorization :zBasic %s)
r%   r   r   r   r   r   base64	b64encodeencodedecode)r   r,   r-   usernamepasswordcredentialss         r   r*   4OAuthClientAuthHandler._inject_authenticated_headersp   s    #'2\'AGO$''3++<<@T@TT22<<H22@@FBH **$h/779fh  (2K'?GO$ U 4r   c                    U R                   b}  U R                   R                  [        R                  L aU  Uc  [        R
                  " S5      eU R                   R                  US'   U R                   R                  =(       d    SUS'   g g g )Nz*HTTP request does not support request-bodyr   r2   r   )r%   r   r   r   r   
OAuthErrorr   r   )r   r   s     r   r+   9OAuthClientAuthHandler._inject_authenticated_request_body   s    ''3++<<**+ # ++@  -1,G,G,Q,Q[)//==C _-+ 4r   )r%   r   )NN)r
   r   r   r   r   r   r.   r*   r+   r   __classcell__)r'   s   @r   r!   r!   N   s(    < 8<B&@ r   r!   )	metaclassc                     / n[         R                  " U 5      nUR                  SR                  US   5      5        SU;   a#  UR                  SR                  US   5      5        SU;   a#  UR                  SR                  US   5      5        SR	                  U5      n[        R                  " X05      e! [
        [        4 a    U n N*f = f)zTranslates an error response from an OAuth operation into an
OAuthError exception.

Args:
    response_body (str): The decoded response data.

Raises:
    google.auth.exceptions.OAuthError
zError code {}errorerror_descriptionz: {}	error_uriz - {}r2   )	jsonloadsappendformatjoinKeyError
ValueErrorr   r=   )response_bodyerror_components
error_dataerror_detailss       r   handle_error_responserP      s    &ZZ.
 6 6z'7J KL*,##FMM*=P2Q$RS*$##GNN:k3J$KL 01
 


== j! &%&s   BB6 6C
C)r   abcr4   enumrE   google.authr   Enumr   objectr   ABCMetar!   rP   r	   r   r   <module>rW      sM   8     "
TYY 
+6 +(?s{{ ?D>r   