Ë
    ùmxi«  ã                   ó¦   — 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y)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y)ÚClientAuthTypeé   é   N)Ú__name__Ú
__module__Ú__qualname__ÚbasicÚrequest_body© ó    úJ/home/htdocs/ttos/venv/lib/python3.12/site-packages/google/oauth2/utils.pyr   r   5   s   „ Ø€EØ�Lr   r   c                   ó   — e Zd ZdZdd„Zy)ÚClientAuthenticationz“Defines the client authentication credentials for basic and request-body
    types based on https://tools.ietf.org/html/rfc6749#section-2.3.1.
    Nc                 ó.   — || _         || _        || _        y)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   :   s   „ ñô+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.
    c                 ó8   •— t         t        | �  «        || _        y)zîInstantiates 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   s   ø€ ô 	Ô$ dÑ4Ô6Ø&;ˆÕ#r   c                 óP   — | j                  ||«       |€| j                  |«       yy)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]   s-   € ð 	×*Ñ*¨7°LÔAàÐØ×3Ñ3°LÕAð  r   c                 ó^  — |�	d|z  |d<   y | j                   �–| j                   j                  t        j                  u ro| j                   j                  }| j                   j
                  xs d}t        j                  |›d|›�j                  «       «      j                  «       }d|z  |d<   y y y )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°\Ñ'AˆG�OÒ$à×'Ñ'Ð3Ø×+Ñ+×<Ñ<Ä×@TÑ@TÑTà×2Ñ2×<Ñ<ˆHØ×2Ñ2×@Ñ@ÒFÀBˆHä ×*Ñ*Ú$¡hÐ/×7Ñ7Ó9óç‰f‹hð ð (2°KÑ'?ˆG�OÒ$ð Uð 4r   c                 ó  — | j                   �u| j                   j                  t        j                  u rN|€t	        j
                  d«      ‚| j                   j                  |d<   | j                   j                  xs d|d<   y y y )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Ñ,G×,QÑ,Q�˜[Ñ)à×/Ñ/×=Ñ=ÒCÀð ˜_Ò-ð+ð 4r   r   )NN)	r   r	   r
   r   r   r&   r"   r#   Ú__classcell__)r    s   @r   r   r   N   s#   ø„ ñõ<ð 8<óBó&@ör   r   )Ú	metaclassc                 ó�  — 	 g }t        j                  | «      }|j                  dj                  |d   «      «       d|v r#|j                  dj                  |d   «      «       d|v r#|j                  dj                  |d   «      «       dj	                  |«      }t        j                  || «      ‚# t
        t        f$ r | }Y Œ)w xY w)zÕTranslates 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‘Z Ó.ˆ
à×Ñ × 6Ñ 6°zÀ'Ñ7JÓ KÔLØ *Ñ,Ø×#Ñ# F§M¡M°*Ð=PÑ2QÓ$RÔSØ˜*Ñ$Ø×#Ñ# G§N¡N°:¸kÑ3JÓ$KÔLØŸ™Ð 0Ó1ˆô
 ×
Ñ
 ¨}Ó
=Ð=øô ”jÐ!ò &Ø%Šð&ús   ‚BB1 Â1CÃC)r   Úabcr+   Úenumr:   Úgoogle.authr   ÚEnumr   Úobjectr   ÚABCMetar   rE   r   r   r   ú<module>rL      sM   ðñó8 Û Û Û å "ô
�T—Y‘Yô ô
+˜6ô +ô(? s§{¡{õ ?óD>r   