
    ([f                     x    d dl mZ ddlmZ ddlmZ  G d d          Z G d d          Z G d	 d
          ZdS )    )default_json_headers   )OAuth2Request)InvalidRequestErrorc                   h    e Zd ZdgZdZeZdefdZe	d             Z
	 	 ddZd Zd	 Zd
 Zd Zd ZdS )	BaseGrantclient_secret_basicNrequestc                     d | _         d | _        || _        || _        t	                      t	                      t	                      t	                      d| _        d S )N)$after_validate_authorization_requestafter_validate_consent_requestafter_validate_token_requestprocess_token)promptredirect_urir
   serverset_hooks)selfr
   r   s      V/var/www/piapp/venv/lib/python3.11/site-packages/authlib/oauth2/rfc6749/grants/base.py__init__zBaseGrant.__init__   sM     47EE.1ee,/EE UU	
 
    c                     | j         j        S N)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#   sE    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_client0   sS    ( 00L$:< <' 	  	' 	' 	' r   c                 B    | j                             || j                  S )z%A method to save token into database.)r   
save_tokenr
   )r   tokens     r   r-   zBaseGrant.save_tokenK   s    {%%eT\:::r   c                 h    | j         j        }| j         j        }| j                            ||          S )zAValidate if requested scope is supported by Authorization Server.)r
   r    stater   validate_requested_scope)r   r    r0   s      r   r1   z"BaseGrant.validate_requested_scopeO   s.    ""{33E5AAAr   c                     || j         vrt          d|| j                   | j         |                             |           d S )NzHook type %s is not in %s.)r   
ValueErroradd)r   	hook_typehooks      r   register_hookzBaseGrant.register_hookU   sL    DK''9&5 5 5I""4(((((r   c                 >    | j         |         D ]} || g|R i | d S r   )r   )r   r5   argskwargsr6   s        r   execute_hookzBaseGrant.execute_hook[   sE    K	* 	( 	(DD''''''''	( 	(r   )NNNNT)__name__
__module____qualname__r)   r#   r   TOKEN_RESPONSE_HEADERr   r   propertyr   r$   r+   r-   r1   r7   r;    r   r   r   r      s        #8"9 J 1

 

 

 

 

 # # X# @D>B
 
 
 
  6; ; ;B B B) ) )( ( ( ( (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                 >    |j         | j        k    o|j        | j        v S r   )r   r#   methodTOKEN_ENDPOINT_HTTP_METHODSclsr
   s     r   check_token_endpointz'TokenEndpointMixin.check_token_endpointg   s(    !S^3 A~!@@	Ar   c                     t                      r   NotImplementedErrorr   s    r   validate_token_requestz)TokenEndpointMixin.validate_token_requestl       !###r   c                     t                      r   rL   r   s    r   create_token_responsez(TokenEndpointMixin.create_token_responseo   rO   r   )
r<   r=   r>   rG   r#   classmethodr   rJ   rN   rQ   rA   r   r   rC   rC   `   sk        #)( JA= A A A [A$ $ $$ $ $ $ $r   rC   c                   v    e Zd Z e            ZdZedefd            Ze	defd            Z
d Zd ZdefdZd	S )
AuthorizationEndpointMixinFr
   c                     |j         | j        v S r   )response_typeRESPONSE_TYPESrH   s     r   check_authorization_endpointz7AuthorizationEndpointMixin.check_authorization_endpointw   s    $(:::r   c                     | j         r@|                    | j                   st          d| j          d| j                  | j         S |                                }|st          d| j                  |S )NzRedirect URI z is not supported by client.)r0   z"Missing "redirect_uri" in request.)r   check_redirect_urir   r0   get_default_redirect_uri)r
   r   r   s      r   #validate_authorization_redirect_uriz>AuthorizationEndpointMixin.validate_authorization_redirect_uri{   s     	 ,,W-ABB ))VG$8VVV!-) ) ) ) ''!::<<L ))8!-) ) ) )  r   c                 h    |                                  }|                     d|           || _        d S )Nr   )validate_authorization_requestr;   r   )r   r   s     r   validate_consent_requestz3AuthorizationEndpointMixin.validate_consent_request   s8    ::<<:LIII(r   c                     t                      r   rL   r   s    r   r^   z9AuthorizationEndpointMixin.validate_authorization_request   rO   r   r   c                     t                      r   rL   )r   r   
grant_users      r   create_authorization_responsez8AuthorizationEndpointMixin.create_authorization_response   rO   r   N)r<   r=   r>   r   rW   ERROR_RESPONSE_FRAGMENTrR   r   rX   staticmethodr\   r_   r^   strrc   rA   r   r   rT   rT   s   s        SUUN#;= ; ; ; [;  ]       \ ) ) )
$ $ $$# $ $ $ $ $ $r   rT   N)	authlib.constsr   requestsr   errorsr   r   rC   rT   rA   r   r   <module>rj      s    / / / / / / $ $ $ $ $ $ ( ( ( ( ( (W( W( W( W( W( W( W( W(t$ $ $ $ $ $ $ $&!$ !$ !$ !$ !$ !$ !$ !$ !$ !$r   