o
    b                     @   s@   d Z ddlZddlmZ ddlmZmZmZ G dd deZ	dS )	z
    authlib.oauth2.rfc6750.validator
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Validate Bearer Token for in request, scope and token.
    N   )scope_to_list   )InvalidRequestErrorInvalidTokenErrorInsufficientScopeErrorc                   @   sN   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdddZ	dddZ
dS )BearerTokenValidatorZbearerNc                 C   s
   || _ d S Nrealm)selfr    r   _/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/oauth2/rfc6750/validator.py__init__   s   
zBearerTokenValidator.__init__c                 C      t  )a_  A method to query token from database with the given token string.
        Developers MUST re-implement this method. For instance::

            def authenticate_token(self, token_string):
                return get_token_from_database(token_string)

        :param token_string: A string to represent the access_token.
        :return: token
        NotImplementedError)r   token_stringr   r   r   authenticate_token      
z'BearerTokenValidator.authenticate_tokenc                 C   r   )a  Check if the HTTP request is valid or not.  Developers MUST
        re-implement this method.  For instance, your server requires a
        "X-Device-Version" in the header::

            def request_invalid(self, request):
                return 'X-Device-Version' in request.headers

        Usually, you don't have to detect if the request is valid or not,
        you can just return a ``False``.

        :param request: instance of HttpRequest
        :return: Boolean
        r   )r   requestr   r   r   request_invalid#   s   z$BearerTokenValidator.request_invalidc                 C   r   )a(  Check if this token is revoked. Developers MUST re-implement this
        method. If there is a column called ``revoked`` on the token table::

            def token_revoked(self, token):
                return token.revoked

        :param token: token instance
        :return: Boolean
        r   )r   tokenr   r   r   token_revoked3   r   z"BearerTokenValidator.token_revokedc                 C   s   |  }|sdS |t k S )NF)Zget_expires_attime)r   r   Z
expires_atr   r   r   token_expired?   s   z"BearerTokenValidator.token_expiredANDc                 C   sr   |sdS t | }|sdS t|}tt |}|dkr"|| S |dkr+||@  S t|r5||| S td)NFTr   ORzInvalid operator value)r   	get_scopeset
issupersetcallable
ValueError)r   r   scopeoperatorZtoken_scopesZresource_scopesr   r   r   scope_insufficientE   s   
z'BearerTokenValidator.scope_insufficientc                 C   sv   |  |rt | |}|st| jd| |r t| jd| |r+t| jd| |||r9t|	 ||S )Nr
   )
r   r   r   r   r   r   r   r%   r   r   )r   r   r#   r   Zscope_operatorr   r   r   r   __call__W   s   



zBearerTokenValidator.__call__r	   )r   )__name__
__module____qualname__Z
TOKEN_TYPEr   r   r   r   r   r%   r&   r   r   r   r   r      s    

r   )
__doc__r   Zrfc6749.utilr   errorsr   r   r   objectr   r   r   r   r   <module>   s
    