
    qhh                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJr  SSKJrJrJr  SSKJr  SrS	rS
rSS0r " S S5      rg)z
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming OAuth 2.0 RFC6749.
    N)generate_token)tokens)InsecureTransportErrorTokenExpiredError)parse_token_responseprepare_token_request prepare_token_revocation_request)is_secure_transportauth_headerquerybodyzContent-Typez!application/x-www-form-urlencodedc                       \ rS rSrSrSr\SSSSSSSSS\SSS4S jr\	S 5       r
S rS	 rS
 r  SS jr  SS jr  SS jr  SS jr SS jrS S jrS!S jr  SS jrS rS S jrSSS\S4S jrS rS rS rSrg)"Client$   am  Base OAuth2 client responsible for access token management.

This class also acts as a generic interface providing methods common to all
client types such as ``prepare_authorization_request`` and
``prepare_token_revocation_request``. The ``prepare_x_request`` methods are
the recommended way of interacting with clients (as opposed to the abstract
prepare uri/body/etc methods). They are recommended over the older set
because they are easier to use (more consistent) and add a few additional
security checks, such as HTTPS and state checking.

Some of these methods require further implementation only provided by the
specific purpose clients such as
:py:class:`oauthlib.oauth2.MobileApplicationClient` and thus you should always
seek to use the client class matching the OAuth workflow you need. For
Python, this is usually :py:class:`oauthlib.oauth2.WebApplicationClient`.

refresh_tokenBearerNc                 ,   Xl         X l        X0l        X@l        XPl        X`l        Xpl        U=(       d    0 U l        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        SU l        SU l        SU l        U R%                  U R                  5        g)am  Initialize a client with commonly used attributes.

:param client_id: Client identifier given by the OAuth provider upon
registration.

:param default_token_placement: Tokens can be supplied in the Authorization
header (default), the URL query component (``query``) or the request
body (``body``).

:param token_type: OAuth 2 token type. Defaults to Bearer. Change this
if you specify the ``access_token`` parameter and know it is of a
different token type, such as a MAC, JWT or SAML token. Can
also be supplied as ``token_type`` inside the ``token`` dict parameter.

:param access_token: An access token (string) used to authenticate
requests to protected resources. Can also be supplied inside the
``token`` dict parameter.

:param refresh_token: A refresh token (string) used to refresh expired
tokens. Can also be supplied inside the ``token`` dict parameter.

:param mac_key: Encryption key used with MAC tokens.

:param mac_algorithm:  Hashing algorithm for MAC tokens.

:param token: A dict of token attributes such as ``access_token``,
``token_type`` and ``expires_at``.

:param scope: A list of default scopes to request authorization for.

:param state: A CSRF protection string used during authorization.

:param redirect_url: The redirection endpoint on the client side to which
the user returns after authorization.

:param state_generator: A no argument state generation callable. Defaults
to :py:meth:`oauthlib.common.generate_token`.

:param code_verifier: PKCE parameter. A cryptographically random string that is used to correlate the
authorization request to the token request.

:param code_challenge: PKCE parameter. A challenge derived from the code verifier that is sent in the
authorization request, to be verified against later.

:param code_challenge_method: PKCE parameter. A method that was used to derive code challenge.
Defaults to "plain" if not present in the request.
N)	client_iddefault_token_placement
token_typeaccess_tokenr   mac_keymac_algorithmtokenscopestate_generatorstateredirect_urlcode_verifiercode_challengecode_challenge_methodcode
expires_in_expires_atpopulate_token_attributes)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   kwargss                    V/var/www/html/env/lib/python3.13/site-packages/oauthlib/oauth2/rfc6749/clients/base.py__init__Client.__init__8   s    @ #'>$$(**[b

.
(*,%:"	&&tzz2    c                 4    U R                   U R                  S.$ )a'  Supported token types and their respective methods

Additional tokens can be supported by extending this dictionary.

The Bearer token spec is stable and safe to use.

The MAC token spec is not yet stable and support for MAC tokens
is experimental and currently matching version 00 of the spec.
)r   MAC)_add_bearer_token_add_mac_token)r&   s    r(   token_typesClient.token_types   s      ,,&&
 	
r+   c                     [        S5      e)z,Abstract method used to create request URIs.*Must be implemented by inheriting classes.NotImplementedErrorr&   argsr'   s      r(   prepare_request_uriClient.prepare_request_uri       !"NOOr+   c                     [        S5      e)z.Abstract method used to create request bodies.r3   r4   r6   s      r(   prepare_request_bodyClient.prepare_request_body   r:   r+   c                     [        S5      e)z4Abstract method used to parse redirection responses.r3   r4   r6   s      r(   parse_request_uri_response!Client.parse_request_uri_response   r:   r+   GETc                    [        U5      (       d
  [        5       eU=(       d    U R                  nU R                  R	                  5        VVs0 s H  u  pxUR                  5       U_M     n	nnU R                  R                  5       U	;  a  [        SU R                  -  5      eU R                  (       d+  U R                  R                  S5      (       d  [        S5      eU R                  (       a-  U R                  [        R                  " 5       :  a
  [        5       eXR                  R                  5          " XUXE40 UD6$ s  snnf )a  Add token to the request uri, body or authorization header.

The access token type provides the client with the information
required to successfully utilize the access token to make a protected
resource request (along with type-specific attributes).  The client
MUST NOT use an access token if it does not understand the token
type.

For example, the "bearer" token type defined in
[`I-D.ietf-oauth-v2-bearer`_] is utilized by simply including the access
token string in the request:

.. code-block:: http

    GET /resource/1 HTTP/1.1
    Host: example.com
    Authorization: Bearer mF_9.B5f-4.1JqM

while the "mac" token type defined in [`I-D.ietf-oauth-v2-http-mac`_] is
utilized by issuing a MAC key together with the access token which is
used to sign certain components of the HTTP requests:

.. code-block:: http

    GET /resource/1 HTTP/1.1
    Host: example.com
    Authorization: MAC id="h480djs93hd8",
                        nonce="274312:dj83hs9s",
                        mac="kDZvddkndxvhGRXZhvuDjEWhGeE="

.. _`I-D.ietf-oauth-v2-bearer`: https://tools.ietf.org/html/rfc6749#section-12.2
.. _`I-D.ietf-oauth-v2-http-mac`: https://tools.ietf.org/html/rfc6749#section-12.2
zUnsupported token type: %sr   zMissing access token.)r
   r   r   r0   itemslowerr   
ValueErrorr   r   getr$   timer   )
r&   urihttp_methodr   headerstoken_placementr'   kvcase_insensitive_token_typess
             r(   	add_tokenClient.add_token   s   F #3''(**)IT-I-I &*%5%5%;%;%=(?%=TQAGGIqL%= 	% (?$$&*FF9DOOKLL!!TZZ^^N%C%C455 0 0499; >#%%+OO,A,A,CDSW[ELiagi 	i(?s   Ec                 .   [        U5      (       d
  [        5       eU=(       d    U R                  5       U l        U=(       d    U R                  U l        Uc  U R
                  OUnU R                  " U4U R                  X@R                  S.UD6nU[        S4$ )a  Prepare the authorization request.

This is the first step in many OAuth flows in which the user is
redirected to a certain authorization URL. This method adds
required parameters to the authorization URL.

:param authorization_url: Provider authorization endpoint URL.
:param state: CSRF protection string. Will be automatically created if
    not provided. The generated state is available via the ``state``
    attribute. Clients should verify that the state is unchanged and
    present in the authorization response. This verification is done
    automatically if using the ``authorization_response`` parameter
    with ``prepare_token_request``.
:param redirect_url: Redirect URL to which the user will be returned
    after authorization. Must be provided unless previously setup with
    the provider. If provided then it must also be provided in the
    token request.
:param scope: List of scopes to request. Must be equal to
    or a subset of the scopes granted when obtaining the refresh
    token. If none is provided, the ones provided in the constructor are
    used.
:param kwargs: Additional parameters to included in the request.
:returns: The prepared request tuple with (url, headers, body).
)redirect_urir   r    )r
   r   r   r   r   r   r8   FORM_ENC_HEADERS)r&   authorization_urlr   r   r   r'   auth_urls          r(   prepare_authorization_request$Client.prepare_authorization_request   s    4 ##455(**4d224
(=D,=,=#m

++5,0,=,=zz5-35 )2--r+   c                    [        U5      (       d
  [        5       eU=(       d    U R                  nU(       a  U R                  X$S9  U=(       d    U R                  U l        U R
                  " SUU R                  S.UD6nU[        U4$ )ar  Prepare a token creation request.

Note that these requests usually require client authentication, either
by including client_id or a set of provider specific authentication
credentials.

:param token_url: Provider token creation endpoint URL.
:param authorization_response: The full redirection URL string, i.e.
    the location to which the user was redirected after successful
    authorization. Used to mine credentials needed to obtain a token
    in this step, such as authorization code.
:param redirect_url: The redirect_url supplied with the authorization
    request (if there was one).
:param state:
:param body: Existing request body (URL encoded string) to embed parameters
             into. This may contain extra parameters. Default ''.
:param kwargs: Additional parameters to included in the request.
:returns: The prepared request tuple with (url, headers, body).
)r   )r   rR    )r
   r   r   r?   r   r<   rT   )r&   	token_urlauthorization_responser   r   r   r'   s          r(   r   Client.prepare_token_request  s    * #9--(**#!++& , 5(=D,=,=(( Sd6:6G6GSKQS *D00r+   c                     [        U5      (       d
  [        5       eUc  U R                  OUnU R                  " SUX$S.UD6nU[        U4$ )ai  Prepare an access token refresh request.

Expired access tokens can be replaced by new access tokens without
going through the OAuth dance if the client obtained a refresh token.
This refresh token and authentication credentials can be used to
obtain a new access token, and possibly a new refresh token.

:param token_url: Provider token refresh endpoint URL.
:param refresh_token: Refresh token string.
:param body: Existing request body (URL encoded string) to embed parameters
    into. This may contain extra parameters. Default ''.
:param scope: List of scopes to request. Must be equal to
    or a subset of the scopes granted when obtaining the refresh
    token. If none is provided, the ones provided in the constructor are
    used.
:param kwargs: Additional parameters to included in the request.
:returns: The prepared request tuple with (url, headers, body).
)r   r   r   rZ   )r
   r   r   prepare_refresh_bodyrT   )r&   r[   r   r   r   r'   s         r(   prepare_refresh_token_request$Client.prepare_refresh_token_request&  s\    ( #9--(** $m

(( ]d7D]U[]*D00r+   c                 T    [        U5      (       d
  [        5       e[        X4X4US.UD6$ )aU  Prepare a token revocation request.

:param revocation_url: Provider token revocation endpoint URL.
:param token: The access or refresh token to be revoked (string).
:param token_type_hint: ``"access_token"`` (default) or
    ``"refresh_token"``. This is optional and if you wish to not pass it you
    must provide ``token_type_hint=None``.
:param body:
:param callback: A jsonp callback such as ``package.callback`` to be invoked
    upon receiving the response. Not that it should not include a () suffix.
:param kwargs: Additional parameters to included in the request.
:returns: The prepared request tuple with (url, headers, body).

Note that JSONP request may use GET requests as the parameters will
be added to the request URL query as opposed to the request body.

An example of a revocation request

.. code-block:: http

    POST /revoke HTTP/1.1
    Host: server.example.com
    Content-Type: application/x-www-form-urlencoded
    Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW

    token=45ghiukldjahdnhzdauz&token_type_hint=refresh_token

An example of a jsonp revocation request

.. code-block:: http

    GET /revoke?token=agabcdefddddafdd&callback=package.myCallback HTTP/1.1
    Host: server.example.com
    Content-Type: application/x-www-form-urlencoded
    Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW

and an error response

.. code-block:: javascript

    package.myCallback({"error":"unsupported_token_type"});

Note that these requests usually require client credentials, client_id in
the case for public clients and provider specific authentication
credentials for confidential clients.
)token_type_hintr   callback)r
   r   r	   )r&   revocation_urlr   rc   r   rd   r'   s          r(   r	   'Client.prepare_token_revocation_requestC  s;    ` #>22(**/ :@Oem:28: 	:r+   c                     Uc  U R                   OUn[        XS9U l        U R                  U R                  5        U R                  $ )a{  Parse the JSON response body.

If the access token request is valid and authorized, the
authorization server issues an access token as described in
`Section 5.1`_.  A refresh token SHOULD NOT be included.  If the request
failed client authentication or is invalid, the authorization server
returns an error response as described in `Section 5.2`_.

:param body: The response body from the token request.
:param scope: Scopes originally requested. If none is provided, the ones
    provided in the constructor are used.
:return: Dictionary of token parameters.
:raises: Warning if scope has changed. :py:class:`oauthlib.oauth2.errors.OAuth2Error`
    if response is invalid.

These response are json encoded and could easily be parsed without
the assistance of OAuthLib. However, there are a few subtle issues
to be aware of regarding the response which are helpfully addressed
through the raising of various errors.

A successful response should always contain

**access_token**
        The access token issued by the authorization server. Often
        a random string.

**token_type**
    The type of the token issued as described in `Section 7.1`_.
    Commonly ``Bearer``.

While it is not mandated it is recommended that the provider include

**expires_in**
    The lifetime in seconds of the access token.  For
    example, the value "3600" denotes that the access token will
    expire in one hour from the time the response was generated.
    If omitted, the authorization server SHOULD provide the
    expiration time via other means or document the default value.

 **scope**
    Providers may supply this in all responses but are required to only
    if it has changed since the authorization request.

.. _`Section 5.1`: https://tools.ietf.org/html/rfc6749#section-5.1
.. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2
.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
)r   )r   r   r   r%   )r&   r   r   r'   s       r(   parse_request_body_response"Client.parse_request_body_responsez  s<    ` $m

)$<
&&tzz2zzr+   c                     U=(       d    U R                   nUc  U R                  OUn[        U R                  4XUS.UD6$ )a  Prepare an access token request, using a refresh token.

If the authorization server issued a refresh token to the client, the
client makes a refresh request to the token endpoint by adding the
following parameters using the `application/x-www-form-urlencoded`
format in the HTTP request entity-body:

:param refresh_token: REQUIRED.  The refresh token issued to the client.
:param scope:  OPTIONAL.  The scope of the access request as described by
    Section 3.3.  The requested scope MUST NOT include any scope
    not originally granted by the resource owner, and if omitted is
    treated as equal to the scope originally granted by the
    resource owner. Note that if none is provided, the ones provided
    in the constructor are used if any.
)r   r   r   )r   r   r   refresh_token_key)r&   r   r   r   r'   s        r(   r_   Client.prepare_refresh_body  sN      &;););#m

$T%;%; L$3@LDJL 	Lr+   c                 (   U[         :X  a"  [        R                  " U R                  U5      nOcU[        :X  a"  [        R
                  " U R                  U5      nO7U[        :X  a"  [        R                  " U R                  U5      nO[        S5      eXU4$ )zDAdd a bearer token to the request uri, body or authorization header.Invalid token placement.)	AUTH_HEADERr   prepare_bearer_headersr   	URI_QUERYprepare_bearer_uriBODYprepare_bearer_bodyrE   )r&   rH   rI   r   rJ   rK   s         r(   r.   Client._add_bearer_token  s}     k)33D4E4EwOG	)++D,=,=sCC$--d.?.?FD 788T!!r+   c                     SnUS:  d  [        S5      eUS::  d  [        S5      e[        R                  " S5      n[        R                  " U5      n[        R
                  " X25      (       d  [        S5      eX l        U$ )a  Create PKCE **code_verifier** used in computing **code_challenge**. 
See `RFC7636 Section 4.1`_

:param length: REQUIRED. The length of the code_verifier.

The client first creates a code verifier, "code_verifier", for each
OAuth 2.0 [RFC6749] Authorization Request, in the following manner:

.. code-block:: text

       code_verifier = high-entropy cryptographic random STRING using the
       unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
       from Section 2.3 of [RFC3986], with a minimum length of 43 characters
       and a maximum length of 128 characters.

.. _`RFC7636 Section 4.1`: https://tools.ietf.org/html/rfc7636#section-4.1
N+   z*Length must be greater than or equal to 43   z(Length must be less than or equal to 128z^[A-Zaa-z0-9-._~]z)code_verifier contains invalid characters)rE   recompilesecretstoken_urlsafesearchr   )r&   lengthr   allowed_characterss       r(   create_code_verifierClient.create_code_verifier  sw    $ |IJJ}GHHZZ(;<--f5yy+;;HII*r+   c                    SnUS:X  a  [        S5      eUS:X  a  SnX l        UnX0l        US:X  a  [        R                  " 5       nUR                  UR                  SS95        UR                  5       n[        R                  [        R                  " U5      5      nUR                  SS5      R                  S	S
5      R                  SS5      nX0l        U$ )a  Create PKCE **code_challenge** derived from the  **code_verifier**.
See `RFC7636 Section 4.2`_

:param code_verifier: REQUIRED. The **code_verifier** generated from `create_code_verifier()`.
:param code_challenge_method: OPTIONAL. The method used to derive the **code_challenge**. Acceptable values include `S256`. DEFAULT is `plain`.

       The client then creates a code challenge derived from the code
       verifier by using one of the following transformations on the code
       verifier::

           plain
              code_challenge = code_verifier
           S256
              code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))

       If the client is capable of using `S256`, it MUST use `S256`, as
       `S256` is Mandatory To Implement (MTI) on the server.  Clients are
       permitted to use `plain` only if they cannot support `S256` for some
       technical reason and know via out-of-band configuration that the
       server supports `plain`.

       The plain transformation is for compatibility with existing
       deployments and for constrained environments that can't use the S256 transformation.

.. _`RFC7636 Section 4.2`: https://tools.ietf.org/html/rfc7636#section-4.2
NzInvalid code_verifierplainS256ascii)encoding+-/_=rS   )rE   r!   r    hashlibsha256updateencodedigestbytesdecodebase64urlsafe_b64encodereplace)r&   r   r!   r    h
sha256_vals         r(   create_code_challengeClient.create_code_challenge  s    6 D 455 D($+!)>&*N"0 F* AHH]))7);<J"\\&*B*B:*NON+33C=EEc3OWWX[]_`N"0r+   c                     U[         :w  a  [        S5      e[        R                  " U R                  UU R
                  U4XCUU R                  S.UD6nXU4$ )zAdd a MAC token to the request authorization header.

Warning: MAC token support is experimental as the spec is not yet stable.
rn   )rJ   r   exthash_algorithm)ro   rE   r   prepare_mac_headerr   r   r   )r&   rH   rI   r   rJ   rK   r   r'   s           r(   r/   Client._add_mac_token)  sg     k)788++D,=,=s,0LL+YOVgj;?;M;MYQWY T!!r+   c                 Z    [         R                  " S[        5        U R                  U5      $ )Nz=Please switch to the public method populate_token_attributes.)warningswarnDeprecationWarningr%   r&   responses     r(   _populate_attributesClient._populate_attributes7  s(     34F	H--h77r+   c                 >    SU;   a  UR                  S5      U l        gg)z2Add attributes from an auth code response to self.r"   N)rF   r"   r   s     r(   populate_code_attributesClient.populate_code_attributes<  s!     X V,DI r+   c                    SU;   a  UR                  S5      U l        SU;   a  UR                  S5      U l        SU;   a  UR                  S5      U l        SU;   aF  UR                  S5      U l        [
        R
                  " 5       [        U R                  5      -   U l        SU;   a    [        UR                  S5      5      U l        SU;   a  UR                  S5      U l        SU;   a  UR                  S5      U l	        gg!   SU l         NE= f)	z6Add attributes from a token exchange response to self.r   r   r   r#   
expires_atNr   r   )
rF   r   r   r   r#   rG   intr$   r   r   r   s     r(   r%    Client.populate_token_attributesB  s     X% (^ <Dh&!)o!>D8#&ll<8DO8#&ll<8DO#yy{S-AAD8#(#&x||L'A#B   #<<	2DLh&!)o!>D '(#' s   (D 	D)r$   r   r   r"   r    r!   r   r   r#   r   r   r   r   r   r   r   r   r   )rA   NNN)NNN)NNNrS   )NrS   N)r   rS   N)N)rS   NN)__name__
__module____qualname____firstlineno____doc__rk   ro   r   r)   propertyr0   r8   r<   r?   rO   rW   r   r`   r	   rh   r_   r.   r   r   r/   r   r   r%   __static_attributes__rZ   r+   r(   r   r   $   s    " ( *5$"##"!/# $'+R3h 
 
PPP DH"&4il FJ?C$.L GKBD 1D FJ591< \`5:n3jL* >B8<" "H/b /4$#[d"8
-?r+   r   )r   r   r   ry   r{   rG   r   oauthlib.commonr   oauthlib.oauth2.rfc6749r   oauthlib.oauth2.rfc6749.errorsr   r   "oauthlib.oauth2.rfc6749.parametersr   r   r	   oauthlib.oauth2.rfc6749.utilsr
   ro   rq   rs   rT   r   rZ   r+   r(   <module>r      sc      	    * *  >	 7 
x? x?r+   