o
    Df                     @   s2   d dl mZ 	dddZdddZ	dd	d
ZdS )    )TemporaryCredentialtemporary_credential:c                    sl    fdd} fdd} fdd} fdd}|  d	| |  d
| |  d| |  d| dS )zRegister temporary credential related hooks to authorization server.

    :param authorization_server: AuthorizationServer instance
    :param cache: Cache instance
    :param key_prefix: key prefix for temporary credential
    c                    s8   | d  }|| d< |r|| d<  j || dd t| S )Noauth_token	client_idoauth_callbackQ timeout)setr   )tokenr   redirect_urikeycache
key_prefix `/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/integrations/flask_oauth1/cache.pycreate_temporary_credential   s   zHregister_temporary_credential_hooks.<locals>.create_temporary_credentialc                    s*   | sd S |  }  |}|rt|S d S N)getr   )r   r   valuer   r   r   get_temporary_credential   s   
zEregister_temporary_credential_hooks.<locals>.get_temporary_credentialc                    s   | r|  }  | d S d S r   )delete)r   r   r   r   r   delete_temporary_credential   s   zHregister_temporary_credential_hooks.<locals>.delete_temporary_credentialc                    s4   |    }|| d< | | d<  j|| dd | S )Noauth_verifieruser_idr   r   )get_oauth_tokenget_user_idr
   )
credential
grant_userverifierr   r   r   r   create_authorization_verifier#   s
   zJregister_temporary_credential_hooks.<locals>.create_authorization_verifierr   r   r   r!   N)register_hook)authorization_serverr   r   r   r   r   r!   r   r   r   #register_temporary_credential_hooks   s    		r$   nonce:r   c                    s    fdd}|S )zCreate an ``exists_nonce`` function that can be used in hooks and
    resource protector.

    :param cache: Cache instance
    :param key_prefix: key prefix for temporary credential
    :param expires: Expire time for nonce
    c                    sH    |  d| d| }|r| d| }  |} j|dd |S )N-   r   )hasr
   )nonce	timestampr   r   r   rvr   expiresr   r   r   exists_nonce<   s   
z.create_exists_nonce_func.<locals>.exists_noncer   )r   r   r-   r.   r   r,   r   create_exists_nonce_func4   s   r/   c                 C   s   t |||}| d| dS )zRegister nonce related hooks to authorization server.

    :param authorization_server: AuthorizationServer instance
    :param cache: Cache instance
    :param key_prefix: key prefix for temporary credential
    :param expires: Expire time for nonce
    r.   N)r/   r"   )r#   r   r   r-   r.   r   r   r   register_nonce_hooksF   s   	r0   N)r   )r%   r   )authlib.oauth1r   r$   r/   r0   r   r   r   r   <module>   s    

0