
    &g                         d Z ddlZddlZddlZddlZddlmZ  G d dej                  Z G d de	          Z
 G d d	ej        
          Zd ZdS )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                       e Zd ZdZdZdS )ClientAuthType      N)__name__
__module____qualname__basicrequest_body     E/var/www/api/venv/lib/python3.11/site-packages/google/oauth2/utils.pyr   r   5   s        ELLLr   r   c                       e Zd ZdZddZdS )ClientAuthenticationzDefines the client authentication credentials for basic and request-body
    types based on https://tools.ietf.org/html/rfc6749#section-2.3.1.
    Nc                 0    || _         || _        || _        dS )a  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__zClientAuthentication.__init__?   s!     !1"*r   N)r   r	   r
   __doc__r   r   r   r   r   r   :   s2         + + + + + +r   r   c                   <     e Zd ZdZd fd	Z	 ddZddZd Z xZS )	OAuthClientAuthHandlerzUAbstract class for handling client authentication in OAuth-based
    operations.
    Nc                 d    t          t          |                                            || _        dS )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   zOAuthClientAuthHandler.__init__S   s0     	$d++44666&;###r   c                 d    |                      ||           ||                     |           dS dS )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_optionsz:OAuthClientAuthHandler.apply_client_authentication_options]   sB     	**7LAAA33LAAAAA  r   c                 "   |
d|z  |d<   d S | j         y| j         j        t          j        u rc| j         j        }| j         j        pd}t          j        |d|                                          	                                }d|z  |d<   d S d S d S )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"   z4OAuthClientAuthHandler._inject_authenticated_headersp   s    #'2\'AGO$$$'3+<@TTT2<H2@FBH *$HHhh/7799 fhh  (2K'?GO$$$ 43TTr   c                     | j         P| j         j        t          j        u r:|t	          j        d          | j         j        |d<   | j         j        pd|d<   d S d S d S )Nz*HTTP request does not support request-bodyr   r)   r   )r   r   r   r   r   
OAuthErrorr   r   )r   r   s     r   r#   z9OAuthClientAuthHandler._inject_authenticated_request_body   s    '3+<*+ + # +@   -1,G,Q[)/=C _--- 43+ +r   r   )NN)	r   r	   r
   r   r   r&   r"   r#   __classcell__)r    s   @r   r   r   N   s         < < < < < < 8<B B B B&@ @ @ @      r   r   )	metaclassc                    	 g }t          j        |           }|                    d                    |d                              d|v r.|                    d                    |d                              d|v r.|                    d                    |d                              d                    |          }n# t
          t          f$ r | }Y nw xY wt          j        ||           )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 - {}r)   )	jsonloadsappendformatjoinKeyError
ValueErrorr   r3   )response_bodyerror_components
error_dataerror_detailss       r   handle_error_responserE      s    &Z..
 6 6z'7J K KLLL*,,##FMM*=P2Q$R$RSSS*$$##GNN:k3J$K$KLLL 011j! & & &%& 
}
=
==s   B=C   CC)r   abcr+   enumr:   google.authr   Enumr   objectr   ABCMetar   rE   r   r   r   <module>rL      s    8 


    " " " " " "
    TY   
+ + + + +6 + + +(? ? ? ? ?s{ ? ? ? ?D> > > > >r   