
    kh%                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
mZ  ej                  e      Z G d de
      Zy)	z
oauthlib.oauth2.rfc8628
~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC8628.
    N)Callable)Requestgenerate_token)errors)BaseEndpointcatch_errors_and_unavailabilityc                       e Zd ZdZ	 	 	 	 ddedgef   fdZed        Zed        Z	ed        Z
d Zed	        Ze	 dd
       Zy)DeviceAuthorizationEndpointai  DeviceAuthorization endpoint - used by the client to initiate
    the authorization flow by requesting a set of verification codes
    from the authorization server by making an HTTP "POST" request to
    the device authorization endpoint.

    The client authentication requirements of Section 3.2.1 of [RFC6749]
    apply to requests on this endpoint, which means that confidential
    clients (those that have established client credentials) authenticate
    in the same manner as when making requests to the token endpoint, and
    public clients provide the "client_id" parameter to identify
    themselves.
    Nuser_code_generatorc                     || _         || _        || _        || _        || _        || _        t        j                  |        y)a  
        :param request_validator: An instance of RequestValidator.
        :type request_validator: oauthlib.oauth2.rfc6749.RequestValidator.
        :param verification_uri: a string containing the URL that can be polled by the client application
        :param expires_in: a number that represents the lifetime of the `user_code` and `device_code`
        :param interval: an option number that represents the number of seconds between each poll requests
        :param verification_uri_complete: a string of a function that can be called with `user_data` as parameter
        :param user_code_generator: a callable that returns a configurable user code
        N)request_validator_expires_in	_interval_verification_uri_verification_uri_completer   r   __init__)selfr   verification_uri
expires_inintervalverification_uri_completer   s          r/var/www/teggl/fontify/venv/lib/python3.12/site-packages/oauthlib/oauth2/rfc8628/endpoints/device_authorization.pyr   z$DeviceAuthorizationEndpoint.__init__$   sA    $ "3%!!1*C'#6 d#    c                     | j                   S )zThe minimum amount of time in seconds that the client
        SHOULD wait between polling requests to the token endpoint.  If no
        value is provided, clients MUST use 5 as the default.
        )r   r   s    r   r   z$DeviceAuthorizationEndpoint.interval?   s     ~~r   c                     | j                   S )z=The lifetime in seconds of the "device_code" and "user_code".)r   r   s    r   r   z&DeviceAuthorizationEndpoint.expires_inG   s     r   c                     | j                   S )zThe end-user verification URI on the authorization
        server.  The URI should be short and easy to remember as end users
        will be asked to manually type it into their user agent.
        )r   r   s    r   r   z,DeviceAuthorizationEndpoint.verification_uriL   s     %%%r   c                     | j                   sy t        | j                   t              r| j                   j                  |      S t	        | j                         r| j                  |      S y )N)	user_code)r   
isinstancestrformatcallable)r   r   s     r   r   z5DeviceAuthorizationEndpoint.verification_uri_completeT   sZ    ..d55s;2299I9NND334229==r   c                    dD ]-  }	 |j                   }||v st        j                  d|z  |       |j                  d   dk7  rt        j
                  d|      |j                  st        j                  |      | j                  j                  |j                  |      st        j                  |      | j                  |       y	# t        $ r t        j                  d|      w xY w)
a  Validate the device authorization request.

        The client_id is required if the client is not authenticating with the
        authorization server as described in `Section 3.2.1. of [RFC6749]`_.
        The client identifier as described in `Section 2.2 of [RFC6749]`_.

        .. _`Section 3.2.1. of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-3.2.1
        .. _`Section 2.2 of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-2.2
        )	client_idscopezUnable to parse query string)descriptionrequestzDuplicate %s parameter.zContent-Typez!application/x-www-form-urlencodedz6Content-Type must be application/x-www-form-urlencoded)r(   N)duplicate_params
ValueErrorr   InvalidRequestFatalErrorheadersInvalidRequestErrorr%   MissingClientIdErrorr   validate_client_idInvalidClientIdError_raise_on_invalid_client)r   r(   paramr)   s       r   %validate_device_authorization_requestzADeviceAuthorizationEndpoint.validate_device_authorization_request]   s     , 
	E#*#;#; 
 ((55 9E A7 
	 ??>*.QQ,,H    --g>>%%889J9JGT--g>> 	%%g.A  55 > s   C!C-c                 r   t        ||||      }| j                  |       t        j                  d|       i }| j                  r| j	                         n	t               }| j                  | j                  |t               d}| j                  | j                  |d<   | j                  |      }|r||d<   ||dfS )a
  
           Generate a unique device verification code and an end-user code that are valid for a limited time.
           Include them in the HTTP response body using the "application/json" format [RFC8259] with a
           200 (OK) status code, as described in `Section-3.2`_.

           :param uri: The full URI of the token request.
           :type uri: str
           :param request: OAuthlib request.
           :type request: oauthlib.common.Request
           :param user_code_generator:
               A callable that returns a string for the user code.
               This allows the caller to decide how the `user_code` should be formatted.
           :type user_code_generator: Callable[[], str]
           :return: A tuple of three 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.
           :rtype: tuple

           The response contains the following parameters:

           device_code
              **REQUIRED.** The device verification code.

           user_code
              **REQUIRED.** The end-user verification code.

           verification_uri
              **REQUIRED.** The end-user verification URI on the authorization server.
              The URI should be short and easy to remember as end users will be asked
              to manually type it into their user agent.

           verification_uri_complete
              **OPTIONAL.** A verification URI that includes the `user_code` (or
              other information with the same function as the `user_code`), which is
              designed for non-textual transmission.

           expires_in
              **REQUIRED.** The lifetime in seconds of the `device_code` and `user_code`.

           interval
              **OPTIONAL.** The minimum amount of time in seconds that the client
              SHOULD wait between polling requests to the token endpoint. If no
              value is provided, clients MUST use 5 as the default.

           **For example:**

              .. code-block:: http

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

                 {
                   "device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS",
                   "user_code": "WDJB-MJHT",
                   "verification_uri": "https://example.com/device",
                   "verification_uri_complete":
                       "https://example.com/device?user_code=WDJB-MJHT",
                   "expires_in": 1800,
                   "interval": 5
                 }

           .. _`Section-3.2`: https://www.rfc-editor.org/rfc/rfc8628#section-3.2
           z6Pre resource owner authorization validation ok for %r.)r   r   r   device_coder   r      )
r   r3   logdebugr   r   r   r   r   r   )	r   urihttp_methodbodyr,   r(   r   datar   s	            r   $create_device_authorization_responsez@DeviceAuthorizationEndpoint.create_device_authorization_response   s    J #{D':227;		JGT262J2JD,,.P^P`	 $ 5 5//")+	
 ==$#}}D %)$B$B9$M!$0ID,-c!!r   )i  NNN)POSTNN)__name__
__module____qualname____doc__r   r!   r   propertyr   r   r   r   r   r3   r=    r   r   r
   r
      s    " "&59$ &tfck2$6       & & %// %//b %:>X" %X"r   r
   )rB   loggingtypingr   oauthlib.commonr   r   oauthlib.oauth2.rfc6749r   &oauthlib.oauth2.rfc6749.endpoints.baser   r   	getLoggerr?   r7   r
   rD   r   r   <module>rK      s?      3 *
 g!R", R"r   