o
    ©D®f	  ã                   @   s^   d dl Z ddlmZmZmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZmZ G dd„ dƒZdS )é    Né   )ÚSIGNATURE_HMAC_SHA1ÚSIGNATURE_PLAINTEXTÚSIGNATURE_RSA_SHA1)Úverify_hmac_sha1Úverify_plaintextÚverify_rsa_sha1)ÚInvalidRequestErrorÚMissingRequiredParameterErrorÚUnsupportedSignatureMethodErrorÚInvalidNonceErrorÚInvalidSignatureErrorc                   @   sR   e Zd ZeeeeeeiZ	egZ
dZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ ZdS )Ú
BaseServeri,  c                 C   s   || j |< dS )aÅ  Extend signature method verification.

        :param name: A string to represent signature method.
        :param verify: A function to verify signature.

        The ``verify`` method accept ``OAuth1Request`` as parameter::

            def verify_custom_method(request):
                # verify this request, return True or False
                return True

            Server.register_signature_method('custom-name', verify_custom_method)
        N)ÚSIGNATURE_METHODS)ÚclsÚnameÚverify© r   ú[/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/oauth1/rfc5849/base_server.pyÚregister_signature_method   s   z$BaseServer.register_signature_methodc              	   C   s´   |j  d¡}|j  d¡}|jtkr|s|sdS |stdƒ‚zt|ƒ}|dk r*tdƒ‚| jr:t ¡ | | jkr:tdƒ‚W n t	t
fyH   tdƒ‚w |sOtdƒ‚|  ||¡rXtƒ ‚dS )zzValidate ``oauth_timestamp`` and ``oauth_nonce`` in HTTP request.

        :param request: OAuth1Request instance
        Úoauth_timestampÚoauth_nonceNr   zInvalid "oauth_timestamp" value)Úoauth_paramsÚgetÚsignature_methodr   r
   Úintr	   ÚEXPIRY_TIMEÚtimeÚ
ValueErrorÚ	TypeErrorÚexists_noncer   )ÚselfÚrequestÚ	timestampÚnoncer   r   r   Úvalidate_timestamp_and_nonce/   s,   
€ÿÿz'BaseServer.validate_timestamp_and_noncec                 C   sX   |j }|s	tdƒ‚|| jvrtƒ ‚|jstdƒ‚| j |¡}|s#tƒ ‚||ƒs*tƒ ‚dS )zhValidate ``oauth_signature`` from HTTP request.

        :param request: OAuth1Request instance
        Úoauth_signature_methodÚoauth_signatureN)r   r
   ÚSUPPORTED_SIGNATURE_METHODSr   Ú	signaturer   r   r   )r!   r"   Úmethodr   r   r   r   Úvalidate_oauth_signatureQ   s   
ÿz#BaseServer.validate_oauth_signaturec                 C   ó   t ƒ ‚)zŒGet client instance with the given ``client_id``.

        :param client_id: A string of client_id
        :return: Client instance
        ©ÚNotImplementedError)r!   Ú	client_idr   r   r   Úget_client_by_idg   s   zBaseServer.get_client_by_idc                 C   r,   )a	  The nonce value MUST be unique across all requests with the same
        timestamp, client credentials, and token combinations.

        :param nonce: A string value of ``oauth_nonce``
        :param request: OAuth1Request instance
        :return: Boolean
        r-   )r!   r$   r"   r   r   r   r    o   s   zBaseServer.exists_nonceN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r(   r   Úclassmethodr   r%   r+   r0   r    r   r   r   r   r      s    ý
"r   )r   r)   r   r   r   r   r   r   Úerrorsr	   r
   r   r   r   r   r   r   r   r   Ú<module>   s
    	