o
    	whQ                     @   s8   d dl Z d dlZd dlmZ dd Zdd Zdd ZdS )	    N)settingsc                 C   s<   | j tj tjdd tj d}tj|tjdd}|S )N
   daysuser_idexpiatHS256)	algorithmiddatetimeutcnow	timedeltajwtencoder   
SECRET_KEY)useraccess_token_payloadaccess_token r   9/var/www/html/DRIVERZZ_DRIVER_APIS/authentication/auth.pygenerate_access_token   s   r   c                 C   sF   | j tj tjdd tj d}tj|tjdtjddd}|S )Nr   r   r   r
   )r   lifetimer   )r   refresh_token_payloadrefresh_tokenr   r   r   generate_refresh_token   s   r   c                 C   s~   | j d}|s
d S z|dd }tj|tjdd}|d W S  tjy*   Y d S  tjj	y5   Y d S  t
y>   Y d S w )NAuthorization    r
   )
algorithmsr   )headersgetsplitr   decoder   r   ExpiredSignatureError
exceptionsInvalidSignatureError
IndexError)requestauthorization_headerr   payloadr   r   r   verify_token   s   
r-   )r   r   django.confr   r   r   r-   r   r   r   r   <module>   s    