o
    b|	                     @   sd   d dl Z 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 dd	lmZ G d
d deZdS )    N)OAuth1Error)ResourceProtector)JsonResponse)settings   )exists_nonce_in_cache   )parse_request_headersc                   @   s>   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdddZdS )r   c                 C   sN   || _ || _ttdi }|dg }|rt|ttfr|| _|dd| _	d S )NZAUTHLIB_OAUTH1_PROVIDERZsignature_methodsZnonce_expires_iniQ )
client_modeltoken_modelgetattrr   get
isinstancelisttupleZSUPPORTED_SIGNATURE_METHODS_nonce_expires_in)selfr
   r   configmethods r   t/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/integrations/django_oauth1/resource_protector.py__init__   s   zResourceProtector.__init__c                 C   s,   z	| j jj|dW S  | j jy   Y d S w )N)	client_id)r
   objectsr   DoesNotExist)r   r   r   r   r   get_client_by_id   s
   z"ResourceProtector.get_client_by_idc                 C   s2   z| j jj|j|jdW S  | j jy   Y d S w )N)r   Zoauth_token)r   r   r   r   tokenr   )r   requestr   r   r   get_token_credential   s   z&ResourceProtector.get_token_credentialc                 C   s   t ||| jS N)r   r   )r   noncer   r   r   r   exists_nonce%   s   zResourceProtector.exists_noncec                 C   sB   |j dv r|j }nd }t|}| }| |j |||}|jS )N)POSTPUT)methodr"   dictr	   Zget_raw_uriZvalidate_request
credential)r   r   bodyheadersurlreqr   r   r   acquire_credential(   s   
z$ResourceProtector.acquire_credentialNc                    s    fdd}|S )Nc                    s   t   fdd}|S )Nc              
      s~   z
 | }|| _W n) ty3 } zt| }t||jd}d|d< d|d< |W  Y d }~S d }~ww  | g|R i |S )N)statuszno-storezCache-Controlzno-cacheZPragma)r+   Zoauth1_credentialr   r%   get_bodyr   status_code)r   argskwargsr&   errorr'   resp)fr   r   r   	decorated5   s   

z>ResourceProtector.__call__.<locals>.wrapper.<locals>.decorated)	functoolswraps)r3   r4   r   )r3   r   wrapper4   s   z+ResourceProtector.__call__.<locals>.wrapperr   )r   realmr8   r   r7   r   __call__3   s   zResourceProtector.__call__r   )	__name__
__module____qualname__r   r   r   r!   r+   r:   r   r   r   r   r   
   s    	r   )r5   Zauthlib.oauth1.errorsr   Zauthlib.oauth1r   Z_ResourceProtectorZdjango.httpr   Zdjango.confr   r    r   Zdjango_helpersr	   r   r   r   r   <module>   s    