
    !<i                         d dl mZ ddlmZ ddlmZ ddlmZ ddlmZ  G d de          Z	 G d	 d
          Z
 G d d          ZdS )    )default_json_headers   )InvalidRequestError)Hookable)hooked)OAuth2Requestc                   l     e Zd ZdgZdZeZdef fdZe	d             Z
	 	 	 	 	 ddZd Zd	 Zd
 Z xZS )	BaseGrantclient_secret_basicNrequestc                     t                                                       d | _        d | _        || _        || _        d S N)super__init__promptredirect_urir   server)selfr   r   	__class__s      /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/authlib/oauth2/rfc6749/grants/base.pyr   zBaseGrant.__init__   s:         c                     | j         j        S r   )r   clientr   s    r   r   zBaseGrant.client   s    |""r   Tc                 h    || j         }| j                            | j        j        |||||          S )N)r   
grant_typeuserscope
expires_ininclude_refresh_token)
GRANT_TYPEr   generate_tokenr   r   )r   r   r   r   r   r    s         r   r"   zBaseGrant.generate_token!   sG     J{))<&!!"7 * 
 
 	
r   c                     | j                             | j        | j                  }| j                             d||            |S )a  Authenticate client with the given methods for token endpoint.

        For example, the client makes the following HTTP request using TLS:

        .. code-block:: http

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

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

        Default available methods are: "none", "client_secret_basic" and
        "client_secret_post".

        :return: client
        after_authenticate_client)r   grant)r   authenticate_clientr   TOKEN_ENDPOINT_AUTH_METHODSsend_signal)r   r   s     r   "authenticate_token_endpoint_clientz,BaseGrant.authenticate_token_endpoint_client4   sK    ( 00L$:
 
 	 ;FRVWWWr   c                 B    | j                             || j                  S )z%A method to save token into database.)r   
save_tokenr   )r   tokens     r   r+   zBaseGrant.save_tokenN   s    {%%eT\:::r   c                 X    | j         j        j        }| j                            |          S )zAValidate if requested scope is supported by Authorization Server.)r   payloadr   r   validate_requested_scope)r   r   s     r   r/   z"BaseGrant.validate_requested_scopeR   s%    $*{33E:::r   )NNNNT)__name__
__module____qualname__r'   r!   r   TOKEN_RESPONSE_HEADERr   r   propertyr   r"   r)   r+   r/   __classcell__)r   s   @r   r
   r
   	   s        #8"9 J 1       # # X#
 "
 
 
 
&  4; ; ;; ; ; ; ; ; ;r   r
   c                   @    e Zd ZdgZdZedefd            Zd Zd Z	dS )TokenEndpointMixinPOSTNr   c                 H    |j         j        | j        k    o|j        | j        v S r   )r.   r   r!   methodTOKEN_ENDPOINT_HTTP_METHODSclsr   s     r   check_token_endpointz'TokenEndpointMixin.check_token_endpoint_   s+     O&#.8 B#"AA	
r   c                     t                      r   NotImplementedErrorr   s    r   validate_token_requestz)TokenEndpointMixin.validate_token_requestf       !###r   c                     t                      r   r@   r   s    r   create_token_responsez(TokenEndpointMixin.create_token_responsei   rC   r   )
r0   r1   r2   r;   r!   classmethodr   r>   rB   rE    r   r   r7   r7   X   sf        #)( J
= 
 
 
 [
$ $ $$ $ $ $ $r   r7   c                       e Zd Z e            ZdZedefd            Ze	defd            Z
e	defd            Zed             Zd Zdefd	Zd
S )AuthorizationEndpointMixinFr   c                 (    |j         j        | j        v S r   )r.   response_typeRESPONSE_TYPESr<   s     r   check_authorization_endpointz7AuthorizationEndpointMixin.check_authorization_endpointq   s    ,0BBBr   c                    | j         j        rH|                    | j         j                  st          d| j         j         d          | j         j        S |                                }|st          d| j         j                  |S )NzRedirect URI z is not supported by client.z"Missing 'redirect_uri' in request.state)r.   r   check_redirect_urir   get_default_redirect_urirP   )r   r   r   s      r   #validate_authorization_redirect_uriz>AuthorizationEndpointMixin.validate_authorization_redirect_uriu   s    ?' 	 ,,W_-IJJ )^GO$@^^^   ?//!::<<L )8@U     r   c                     | j         j        }g d}|D ]H}t          |                    |g                     dk    rt	          d| d| j         j                  IdS )zFor the Authorization Endpoint, request and response parameters MUST NOT be included
        more than once. Per `Section 3.1`_.

        .. _`Section 3.1`: https://tools.ietf.org/html/rfc6749#section-3.1
        )rK   	client_idr   r   rP      z
Multiple 'z' in request.rO   N)r.   datalistlengetr   rP   )r   rW   
parametersparams       r   &validate_no_multiple_request_parameterzAAuthorizationEndpointMixin.validate_no_multiple_request_parameter   s     ?+UUU
 	 	E8<<r**++a//)5555W_=R    0	 	r   c                 <    |                                  }|| _        |S r   )validate_authorization_requestr   )r   r   s     r   validate_consent_requestz3AuthorizationEndpointMixin.validate_consent_request   s!    ::<<(r   c                     t                      r   r@   r   s    r   r^   z9AuthorizationEndpointMixin.validate_authorization_request   rC   r   r   c                     t                      r   r@   )r   r   
grant_users      r   create_authorization_responsez8AuthorizationEndpointMixin.create_authorization_response   rC   r   N)r0   r1   r2   setrL   ERROR_RESPONSE_FRAGMENTrF   r   rM   staticmethodrS   r\   r   r_   r^   strrc   rG   r   r   rI   rI   m   s        SUUN#C= C C C [C  ]       \      \   V
$ $ $$# $ $ $ $ $ $r   rI   N)authlib.constsr   errorsr   hooksr   r   requestsr   r
   r7   rI   rG   r   r   <module>rl      s    / / / / / / ( ( ( ( ( (             $ $ $ $ $ $L; L; L; L; L; L; L; L;^$ $ $ $ $ $ $ $*1$ 1$ 1$ 1$ 1$ 1$ 1$ 1$ 1$ 1$r   