o
    Tpi  ã                   @   sL   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ dd„ Z	dd„ Z
dS )	é    N©Úwraps)ÚrequestÚjsonify)ÚConfigc                 C   s    t  tj ¡ ¡ ¡ }t | |¡S )N)ÚhashlibÚsha256r   ÚAPI_SECRET_KEYÚencodeÚ	hexdigestÚhmacÚcompare_digest)ÚtokenÚexpected_token© r   ú/var/www/ultranav/auth.pyÚvalidate_token   s   r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                     s\   t j d¡}|stddiƒdfS | d¡r|dd … }t|ƒs'tddiƒdfS ˆ | i |¤ŽS )NÚAuthorizationÚerrorzMissing authorization tokeni‘  zBearer é   zInvalid authorization token)r   ÚheadersÚgetr   Ú
startswithr   )ÚargsÚkwargsr   ©Úfr   r   Údecorated_function   s   
z(require_auth.<locals>.decorated_functionr   )r   r   r   r   r   Úrequire_auth   s   r   )r   r   Ú	functoolsr   Úflaskr   r   Úconfigr   r   r   r   r   r   r   Ú<module>   s    