
    k7i#                         S SK r S SKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	K	J
r
  SS
K	Jr  \ R                  " \5      r " S S\\
5      rg)    N)add_params_to_uri   )AccessDeniedError)OAuth2Error)UnauthorizedClientError)hooked   )AuthorizationEndpointMixin)	BaseGrantc                   P    \ rS rSrSrSrS/rS1rSrSr	\
S 5       r\
S 5       rS	rg
)ImplicitGrant   a  The implicit grant type is used to obtain access tokens (it does not
support the issuance of refresh tokens) and is optimized for public
clients known to operate a particular redirection URI.  These clients
are typically implemented in a browser using a scripting language
such as JavaScript.

Since this is a redirection-based flow, the client must be capable of
interacting with the resource owner's user-agent (typically a web
browser) and capable of receiving incoming requests (via redirection)
from the authorization server.

Unlike the authorization code grant type, in which the client makes
separate requests for authorization and for an access token, the
client receives the access token as the result of the authorization
request.

The implicit grant type does not include client authentication, and
relies on the presence of the resource owner and the registration of
the redirection URI.  Because the access token is encoded into the
redirection URI, it may be exposed to the resource owner and other
applications residing on the same device::

    +----------+
    | Resource |
    |  Owner   |
    |          |
    +----------+
         ^
         |
        (B)
    +----|-----+          Client Identifier     +---------------+
    |         -+----(A)-- & Redirection URI --->|               |
    |  User-   |                                | Authorization |
    |  Agent  -|----(B)-- User authenticates -->|     Server    |
    |          |                                |               |
    |          |<---(C)--- Redirection URI ----<|               |
    |          |          with Access Token     +---------------+
    |          |            in Fragment
    |          |                                +---------------+
    |          |----(D)--- Redirection URI ---->|   Web-Hosted  |
    |          |          without Fragment      |     Client    |
    |          |                                |    Resource   |
    |     (F)  |<---(E)------- Script ---------<|               |
    |          |                                +---------------+
    +-|--------+
      |    |
     (A)  (G) Access Token
      |    |
      ^    v
    +---------+
    |         |
    |  Client |
    |         |
    +---------+
Tnonetokenimplicitc                    U R                  5       n[        R                  SU5        U R                  U R                  U5      nU R                  R
                  R                  nUR                  U5      (       d  [        SU S3USS9e XR                  l	        U R                  5         U$ ! [         a  nX$l        SUl        UeSnAff = f)a:  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.
Per `Section 4.2.1`_.

response_type
     REQUIRED.  Value MUST be set to "token".

client_id
     REQUIRED.  The client identifier as described in Section 2.2.

redirect_uri
     OPTIONAL.  As described in Section 3.1.2.

scope
     OPTIONAL.  The scope of the access request as described by
     Section 3.3.

state
     RECOMMENDED.  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.

The client directs the resource owner to the constructed URI using an
HTTP redirection response, or by other means available to it via the
user-agent.

For example, the client directs the user-agent to make the following
HTTP request using TLS:

.. code-block:: http

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

.. _`Section 4.2.1`: https://tools.ietf.org/html/rfc6749#section-4.2.1
z$Validate authorization request of %rz3The client is not authorized to use 'response_type='Tredirect_uriredirect_fragmentN)"authenticate_token_endpoint_clientlogdebug#validate_authorization_redirect_urirequestpayloadresponse_typecheck_response_typer   clientvalidate_requested_scoper   r   r   )selfr   r   r   errors        `/home/james-whalen/.local/lib/python3.13/site-packages/authlib/oauth2/rfc6749/grants/implicit.pyvalidate_authorization_request,ImplicitGrant.validate_authorization_requestQ   s    \ 88:		8&A??fU,,::))-88)Em_TUV)"& 	"(LL))+
 	  	!-&*E#K	s   	 B+ +
C	5CC	c                    U R                   R                  R                  nU(       a  X R                   l        U R	                  UU R                   R                  R
                  SS9n[        R                  SX@R                   R                  5        U R                  U5        U Vs/ s H  oUXE   4PM
     nnU(       a  UR                  SU45        [        XSS9nSU4/nSS	U4$ [        USS
9es  snf )a\  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.
Per `Section 4.2.2`_.

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.

The authorization server MUST NOT issue a refresh token.

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

.. code-block:: http

    HTTP/1.1 302 Found
    Location: http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA
           &state=xyz&token_type=example&expires_in=3600

Developers should note that some user-agents do not support the
inclusion of a fragment component in the HTTP "Location" response
header field.  Such clients will require using other methods for
redirecting the client than a 3xx redirection response -- for
example, returning an HTML page that includes a 'continue' button
with an action linked to the redirection URI.

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

:param redirect_uri: Redirect to the given URI for the authorization
:param grant_user: if resource owner granted the request, pass this
    resource owner, otherwise pass None.
:returns: (status_code, body, headers)
F)userscopeinclude_refresh_tokenzGrant token %r to %rstateT)fragmentLocationi.   r   )r   r   r*   r'   generate_tokenr(   r   r   r   
save_tokenappendr   r   )	r!   r   
grant_userr*   r   kparamsuriheaderss	            r#   create_authorization_response+ImplicitGrant.create_authorization_response   s    r $$** *LL''ll**00&+ ( E
 II,e\\5H5HIOOE"-23U%(mUF3w./#L4HC"C()GG###QUVV 4s   &C/ N)__name__
__module____qualname____firstlineno____doc__AUTHORIZATION_ENDPOINTTOKEN_ENDPOINT_AUTH_METHODSRESPONSE_TYPES
GRANT_TYPEERROR_RESPONSE_FRAGMENTr   r$   r6   __static_attributes__r8       r#   r   r      sW    6r "#)(YNJ"A AF KW KWrD   r   )loggingauthlib.common.urlsr   errorsr   r   r   hooksr   baser
   r   	getLoggerr9   r   r   r8   rD   r#   <module>rK      s@     1 &   ,  , !RWI9 RWrD   