
    qhD                     N    S r SSKJr  SSKJr  SSKJr  SSKJr   " S S	\5      r	g
)z
oauthlib.oauth1.rfc5849.endpoints.authorization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
    )	urlencode)add_params_to_uri   )errors   )BaseEndpointc                   :    \ rS rSrSrS r  SS jr  S	S jrSrg)
AuthorizationEndpoint   a  An endpoint responsible for letting authenticated users authorize access
to their protected resources to a client.

Typical use would be to have two views, one for displaying the authorization
form and one to process said form on submission.

The first view will want to utilize ``get_realms_and_credentials`` to fetch
requested realms and useful client credentials, such as name and
description, to be used when creating the authorization form.

During form processing you can use ``create_authorization_response`` to
validate the request, create a verifier as well as prepare the final
redirection URI used to send the user back to the client.

See :doc:`/oauth1/validator` for details on which validator methods to implement
for this endpoint.
c                     UR                   U R                  5       S.nUR                  U5        U R                  R	                  UR                   X15        U$ )zCreate and save a new request token.

:param request: OAuthlib request.
:type request: oauthlib.common.Request
:param credentials: A dict of extra token credentials.
:returns: The verifier as a dict.
)oauth_tokenoauth_verifier)resource_owner_keytoken_generatorupdaterequest_validatorsave_verifier)selfrequestcredentialsverifiers       a/var/www/html/env/lib/python3.13/site-packages/oauthlib/oauth1/rfc5849/endpoints/authorization.pycreate_verifier%AuthorizationEndpoint.create_verifier%   sR     #55"224
 	$,,&&	;    Nc                    U R                  XUUS9nUR                  (       d  [        R                  " S5      eU R                  R                  UR                  U5      (       d  [        R                  " 5       eXWl        UR                  (       aJ  U R                  R                  UR                  UR                  U5      (       d  [        R                  " SS9eU R                  Xv=(       d    0 5      nU R                  R                  UR                  U5      n	U	S:X  a  SS0n
[        U5      nXS4$ [        XR                  5       5      nS	U0S
S4$ )a   Create an authorization response, with a new request token if valid.

:param uri: The full URI of the token request.
:param http_method: A valid HTTP verb, i.e. GET, POST, PUT, HEAD, etc.
:param body: The request body as a string.
:param headers: The request headers as a dict.
:param credentials: A list of credentials to include in the verifier.
:returns: A tuple of 3 elements.
          1. A dict of headers to set on the response.
          2. The response body as a string.
          3. The response status code as an integer.

If the callback URI tied to the current token is "oob", a response with
a 200 status code will be returned. In this case, it may be desirable to
modify the response to better display the verifier to the client.

An example of an authorization request::

    >>> from your_validator import your_validator
    >>> from oauthlib.oauth1 import AuthorizationEndpoint
    >>> endpoint = AuthorizationEndpoint(your_validator)
    >>> h, b, s = endpoint.create_authorization_response(
    ...     'https://your.provider/authorize?oauth_token=...',
    ...     credentials={
    ...         'extra': 'argument',
    ...     })
    >>> h
    {'Location': 'https://the.client/callback?oauth_verifier=...&extra=argument'}
    >>> b
    None
    >>> s
    302

An example of a request with an "oob" callback::

    >>> from your_validator import your_validator
    >>> from oauthlib.oauth1 import AuthorizationEndpoint
    >>> endpoint = AuthorizationEndpoint(your_validator)
    >>> h, b, s = endpoint.create_authorization_response(
    ...     'https://your.provider/authorize?foo=bar',
    ...     credentials={
    ...         'extra': 'argument',
    ...     })
    >>> h
    {'Content-Type': 'application/x-www-form-urlencoded'}
    >>> b
    'oauth_verifier=...&extra=argument'
    >>> s
    200
http_methodbodyheadersz(Missing mandatory parameter oauth_token.zEUser granted access to realms outside of what the client may request.)descriptionoobzContent-Typez!application/x-www-form-urlencoded   LocationNi.  )_create_requestr   r   InvalidRequestErrorr   verify_request_tokenInvalidClientErrorrealmsverify_realmsr   get_redirect_urir   r   items)r   urir   r   r    r)   r   r   r   redirect_uriresponse_headersresponse_bodypopulated_redirects                r   create_authorization_response3AuthorizationEndpoint.create_authorization_response6   sP   h &&s$/6 ' 8 )),,:< <%%::**G5 5++--NN4#9#9#G#G**GNNG$E $E,,<> > ''1BC-->>&&15  C E%h/M#C77!2nn."0 23T3>>r   c                    U R                  XUUS9nU R                  R                  UR                  U5      (       d  [        R
                  " 5       eU R                  R                  UR                  U5      nUSUR                  04$ )a  Fetch realms and credentials for the presented request token.

:param uri: The full URI of the token request.
:param http_method: A valid HTTP verb, i.e. GET, POST, PUT, HEAD, etc.
:param body: The request body as a string.
:param headers: The request headers as a dict.
:returns: A tuple of 2 elements.
          1. A list of request realms.
          2. A dict of credentials which may be useful in creating the
          authorization form.
r   r   )r%   r   r'   r   r   r(   
get_realms)r   r-   r   r   r    r   r)   s          r   get_realms_and_credentials0AuthorizationEndpoint.get_realms_and_credentials   s     &&s$/6 ' 8 %%::**G5 5++--''22&&1,g.H.HIIIr    )GETNNNN)r9   NN)	__name__
__module____qualname____firstlineno____doc__r   r2   r6   __static_attributes__r8   r   r   r
   r
      s-    $" JNMQP?d GK+/Jr   r
   N)
r>   urllib.parser   oauthlib.commonr    r   baser   r
   r8   r   r   <module>rD      s(    # -  MJL MJr   