
    qhHJ                         S r SSKrSSKrSSKrSSKJr  SSKJrJ	r	  SSK
Jr  SSKJrJrJrJrJrJr  SSKJr  SSKJrJr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g)z
oauthlib.oauth2.rfc6749.parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module contains methods related to `Section 4`_ of the OAuth 2 RFC.

.. _`Section 4`: https://tools.ietf.org/html/rfc6749#section-4
    N)add_params_to_qsadd_params_to_uri)scope_changed   )InsecureTransportErrorMismatchingStateErrorMissingCodeErrorMissingTokenErrorMissingTokenTypeErrorraise_from_error)OAuth2Token)is_secure_transportlist_to_scopescope_to_listc                    [        U 5      (       d
  [        5       eSU4SU4/n	U(       a  U	R                  SU45        U(       a  U	R                  S[        U5      45        U(       a  U	R                  SU45        Ub&  U	R                  SU45        U	R                  SU45        U H,  n
X   (       d  M  U	R                  [	        U
5      X   45        M.     [        X	5      $ )a  Prepare the authorization grant request URI.

The client constructs the request URI by adding the following
parameters to the query component of the authorization endpoint URI
using the ``application/x-www-form-urlencoded`` format as defined by
[`W3C.REC-html401-19991224`_]:

:param uri:
:param client_id: The client identifier as described in `Section 2.2`_.
:param response_type: To indicate which OAuth 2 grant/flow is required,
                      "code" and "token".
:param redirect_uri: The client provided URI to redirect back to after
                     authorization as described in `Section 3.1.2`_.
:param scope: The scope of the access request as described by
              `Section 3.3`_.
:param state: An opaque value used by the client to maintain
              state between the request and callback.  The authorization
              server includes this value when redirecting the user-agent
              back to the client.  The parameter SHOULD be used for
              preventing cross-site request forgery as described in
              `Section 10.12`_.
: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 the 
                              code_challenge. Defaults to "plain" if not present in the request.
:param kwargs: Extra arguments to embed in the grant/authorization URL.

An example of an authorization code grant authorization URL:

.. code-block:: http

    GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
        &code_challenge=kjasBS523KdkAILD2k78NdcJSk2k3KHG6&code_challenge_method=S256
        &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
    Host: server.example.com

.. _`W3C.REC-html401-19991224`: https://tools.ietf.org/html/rfc6749#ref-W3C.REC-html401-19991224
.. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2
.. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
.. _`section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12
response_type	client_idredirect_uriscopestatecode_challengecode_challenge_method)r   r   appendr   strr   )urir   r   r   r   r   r   r   kwargsparamsks              T/var/www/html/env/lib/python3.13/site-packages/oauthlib/oauth2/rfc6749/parameters.pyprepare_grant_urir       s    Z s##$&&/Y'*F ~|45we 456w&'!'89.0EFG99MM3q669-.  S))    c                    SU 4/nSU;   a  [        US   5      US'   UR                  SS5      nU(       a  Ub  UR                  SU45        Ub  UR                  SU45        UR                  SS5      nUb  UR                  SU45        U H,  nXH   (       d  M  UR                  [        U5      XH   45        M.     [	        X5      $ )a  Prepare the access token request.

The client makes a 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 grant_type: To indicate grant type being used, i.e. "password",
                   "authorization_code" or "client_credentials".

:param body: Existing request body (URL encoded string) to embed parameters
             into. This may contain extra parameters. Default ''.

:param include_client_id: `True` (default) to send the `client_id` in the
                          body of the upstream request. This is required
                          if the client is not authenticating with the
                          authorization server as described in
                          `Section 3.2.1`_.
:type include_client_id: Boolean

:param client_id: Unicode client identifier. Will only appear if
                  `include_client_id` is True. *

:param client_secret: Unicode client secret. Will only appear if set to a
                      value that is not `None`. Invoking this function with
                      an empty string will send an empty `client_secret`
                      value to the server. *

:param code: If using authorization_code grant, pass the previously
             obtained authorization code as the ``code`` argument. *

:param redirect_uri: If the "redirect_uri" parameter was included in the
                     authorization request as described in
                     `Section 4.1.1`_, and their values MUST be identical. *

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

:param kwargs: Extra arguments to embed in the request body.

Parameters marked with a `*` above are not explicit arguments in the
function signature, but are specially documented arguments for items
appearing in the generic `**kwargs` keyworded input.

An example of an authorization code token request body:

.. code-block:: http

    grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA
    &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb

.. _`Section 4.1.1`: https://tools.ietf.org/html/rfc6749#section-4.1.1

grant_typer   r   Ncode_verifierclient_secret)r   popr   r   r   )	r#   bodyinclude_client_idr$   r   r   r   r%   r   s	            r   prepare_token_requestr)   ]   s    j Z()F&'w8w 

;-I MM;	23  67 JJ5M 67 99MM3q669-.  D))r!   c                 H   [        U 5      (       d
  [        5       eSU4/nU(       a  UR                  SU45        U H,  nXW   (       d  M  UR                  [        U5      XW   45        M.     SS0nU(       a   UR                  SU45        [	        X5      X4$ X[        XF5      4$ )a   Prepare a token revocation request.

The client constructs the request by including the following parameters
using the ``application/x-www-form-urlencoded`` format in the HTTP request
entity-body:

:param token: REQUIRED.  The token that the client wants to get revoked.

:param token_type_hint: OPTIONAL.  A hint about the type of the token
                        submitted for revocation. Clients MAY pass this
                        parameter in order to help the authorization server
                        to optimize the token lookup.  If the server is
                        unable to locate the token using the given hint, it
                        MUST extend its search across all of its supported
                        token types.  An authorization server MAY ignore
                        this parameter, particularly if it is able to detect
                        the token type automatically.

This specification defines two values for `token_type_hint`:

    * access_token: An access token as defined in [RFC6749],
         `Section 1.4`_

    * refresh_token: A refresh token as defined in [RFC6749],
         `Section 1.5`_

    Specific implementations, profiles, and extensions of this
    specification MAY define other values for this parameter using the
    registry defined in `Section 4.1.2`_.

.. _`Section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4
.. _`Section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5
.. _`Section 4.1.2`: https://tools.ietf.org/html/rfc7009#section-4.1.2

tokentoken_type_hintzContent-Typez!application/x-www-form-urlencodedcallback)r   r   r   r   r   r   )	urlr+   r,   r-   r'   r   r   r   headerss	            r    prepare_token_revocation_requestr0      s    J s##$&&F(/:;99MM3q669-.  BCGz8,- -w<<-d;;;r!   c                 j   [        U 5      (       d
  [        5       e[        R                  " U 5      R                  n[	        [        R
                  " U5      5      nU(       a   UR                  SS5      U:w  a
  [        5       eSU;   a  [        UR                  S5      U5        SU;  a  [        S5      eU$ )a  Parse authorization grant response URI into a dict.

If the resource owner grants the access request, the authorization
server issues an authorization code and delivers it to the client by
adding the following parameters to the query component of the
redirection URI using the ``application/x-www-form-urlencoded`` format:

**code**
        REQUIRED.  The authorization code generated by the
        authorization server.  The authorization code MUST expire
        shortly after it is issued to mitigate the risk of leaks.  A
        maximum authorization code lifetime of 10 minutes is
        RECOMMENDED.  The client MUST NOT use the authorization code
        more than once.  If an authorization code is used more than
        once, the authorization server MUST deny the request and SHOULD
        revoke (when possible) all tokens previously issued based on
        that authorization code.  The authorization code is bound to
        the client identifier and redirection URI.

**state**
        REQUIRED if the "state" parameter was present in the client
        authorization request.  The exact value received from the
        client.

:param uri: The full redirect URL back to the client.
:param state: The state parameter from the authorization request.

For example, the authorization server redirects the user-agent by
sending the following HTTP response:

.. code-block:: http

    HTTP/1.1 302 Found
    Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA
            &state=xyz

r   Nerrorcodez#Missing code parameter in response.)
r   r   urlparsequerydict	parse_qslgetr   r   r	   )r   r   r5   r   s       r   !parse_authorization_code_responser9      s    L s##$&&c"((E($$U+,FGT*e3#%%&G,f5VDEEMr!   c                    [        U 5      (       d
  [        5       e[        R                  " U 5      R                  n[	        [        R
                  " USS95      nS H  nXT;   d  M
  [        XE   5      XE'   M     SU;   a  [        US   5      US'   SU;   a'  [        R                  " 5       [        US   5      -   US'   U(       a!  UR                  SS5      U:w  a  [        S	5      e[        XBS
9n[        U5        U$ )a  Parse the implicit token response URI into a dict.

If the resource owner grants the access request, the authorization
server issues an access token and delivers it to the client by adding
the following parameters to the fragment component of the redirection
URI using the ``application/x-www-form-urlencoded`` format:

**access_token**
        REQUIRED.  The access token issued by the authorization server.

**token_type**
        REQUIRED.  The type of the token issued as described in
        Section 7.1.  Value is case insensitive.

**expires_in**
        RECOMMENDED.  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**
        OPTIONAL, if identical to the scope requested by the client,
        otherwise REQUIRED.  The scope of the access token as described
        by Section 3.3.

**state**
        REQUIRED if the "state" parameter was present in the client
        authorization request.  The exact value received from the
        client.

:param uri:
:param state:
:param scope:

Similar to the authorization code response, but with a full token provided
in the URL fragment:

.. code-block:: http

    HTTP/1.1 302 Found
    Location: http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA
            &state=xyz&token_type=example&expires_in=3600
T)keep_blank_values
expires_inr   r=   
expires_atr   Nz'Mismatching or missing state in params.	old_scope)r   r   r4   fragmentr6   r7   intr   timer8   
ValueErrorr   validate_token_parameters)r   r   r   rA   r   keys         r   parse_implicit_responserG   !  s    Z s##$&&  %..H($$XFGF=fk*FK  &'w8wv#yy{S1E-FF|GT*e3BCC1Ff%Mr!   c                     [         R                  " U 5      nSU;   a  [        US   5      US'   SU;   a?  US   c  UR                  S5        O'[        R                  " 5       [        US   5      -   US'   [        X!S9n[        U5        U$ ! [         aA    [        [        R
                  " U 5      5      nS H  nX2;   d  M
  [        X#   5      X#'   M      Nf = f)a	  Parse the JSON token response body into a dict.

The authorization server issues an access token and optional refresh
token, and constructs the response by adding the following parameters
to the entity body of the HTTP response with a 200 (OK) status code:

access_token
        REQUIRED.  The access token issued by the authorization server.
token_type
        REQUIRED.  The type of the token issued as described in
        `Section 7.1`_.  Value is case insensitive.
expires_in
        RECOMMENDED.  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.
refresh_token
        OPTIONAL.  The refresh token which can be used to obtain new
        access tokens using the same authorization grant as described
        in `Section 6`_.
scope
        OPTIONAL, if identical to the scope requested by the client,
        otherwise REQUIRED.  The scope of the access token as described
        by `Section 3.3`_.

The parameters are included in the entity body of the HTTP response
using the "application/json" media type as defined by [`RFC4627`_].  The
parameters are serialized into a JSON structure by adding each
parameter at the highest structure level.  Parameter names and string
values are included as JSON strings.  Numerical values are included
as JSON numbers.  The order of parameters does not matter and can
vary.

:param body: The full json encoded response body.
:param scope: The scope requested during authorization.

For example:

.. code-block:: http

    HTTP/1.1 200 OK
    Content-Type: application/json
    Cache-Control: no-store
    Pragma: no-cache

    {
        "access_token":"2YotnFZFEjr1zCsicMWpAA",
        "token_type":"example",
        "expires_in":3600,
        "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
        "example_parameter":"example_value"
    }

.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
.. _`Section 6`: https://tools.ietf.org/html/rfc6749#section-6
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
.. _`RFC4627`: https://tools.ietf.org/html/rfc4627
r<   r   r=   r>   r?   )jsonloadsrD   r6   r4   r7   rB   r   r&   rC   r   rE   )r'   r   r   rF   s       r   parse_token_responserK   f  s    x/D! &'w8wv,'JJ|$#'99;VL5I1J#JF< 1Ff%M-  	/ h((./"C}!&+. #	/s   B
 
1C?CCc                 >   SU ;   a  [        U R                  S5      U 5        SU ;  a	  [        SS9eSU ;  a.  [        R                  R                  S5      (       a
  [        5       eU R                  (       a  SR                  U R                  U R                  S9n[        R                  " XR                  U R                  S	9  [        R                  R                  S
S5      (       d5  [        U5      nXl        U R                  Ul        U R                  Ul        Uegg)zCEnsures token presence, token type, expiration and scope in params.r2   access_tokenzMissing access token parameter.)description
token_typeOAUTHLIB_STRICT_TOKEN_TYPEz*Scope has changed from "{old}" to "{new}".)oldnew)messagerQ   rR   OAUTHLIB_RELAX_TOKEN_SCOPEN)r   r8   r
   osenvironr   r   formatr@   r   send
old_scopesscopesWarningr+   	new_scope)r   rS   ws      r   rE   rE     s    &G,f5V#,MNN6!::>>677')) >EE  fll F 
 	70A0Av}}Uzz~~:DAA AG ++AK --AKG B r!   )NNNNplain) TN)rM   Nr_   )N)NN) __doc__rI   rU   rC   urllib.parseparser4   oauthlib.commonr   r   oauthlib.signalsr   errorsr   r   r	   r
   r   r   tokensr   utilsr   r   r   r    r)   r0   r9   rG   rK   rE    r!   r   <module>ri      st     	   ? *    D D CGY`A*HO*d BP7<t5pBJTnr!   