o
    Gh_  ã                   @   s4   d dl mZ d dlmZmZmZ d dlZdd„ ZdS )é    )Újsonify)Úcreate_access_tokenÚjwt_requiredÚget_jwt_identityNc                 C   sN   d| j d< d| j d< | jddgd�dd	„ ƒ}| jd
dgd�tƒ dd„ ƒƒ}d S )Nzsuper-secretZJWT_SECRET_KEYi  ZJWT_ACCESS_TOKEN_EXPIRESz
/api/loginÚPOST)Úmethodsc                  S   sš   t j d¡} t j d¡}dt d ¡ ¡ ¡ dœ}| r|s$tddiƒdfS t | ¡ ¡ ¡ }| |d krE||d krEt| d�}t|d	�d
fS tddiƒdfS )NÚusernameÚpasswordZadmin)r   r	   ÚerrorzMissing credentialsi�  )Úidentity)Úaccess_tokenéÈ   zInvalid credentialsi‘  )	ÚrequestÚjsonÚgetÚhashlibÚsha256ÚencodeÚ	hexdigestr   r   )r   r	   Z	test_userZ	hashed_pwr   © r   úCC:\Users\shubh\Videos\agent\agent_preprod\modules\authentication.pyÚlogin
   s   þ
zconfigure_auth.<locals>.loginz/api/protectedÚGETc                  S   s   t ƒ } t| d�dfS )N)Zlogged_in_asr   )r   r   )Úcurrent_userr   r   r   Ú	protected!   s   z!configure_auth.<locals>.protected)ÚconfigÚrouter   )Úappr   r   r   r   r   Úconfigure_auth   s   


r   )Úflaskr   Zflask_jwt_extendedr   r   r   r   r   r   r   r   r   Ú<module>   s    