o
    ÒèFhá  ã                   @   sH   d dl mZ d dlmZmZ d dlmZ ddlmZ G dd„ deƒZ	dS )	é    )Úurlsafe_b64decode)ÚBaseAuthenticationÚget_authorization_header)ÚAuthenticationFailedé   )Ú	AuthTokenc                   @   s,   e Zd Zdd„ Zd	defdd„Zdd„ ZdS )
ÚAuthTokenAuthenticationc                 C   sŒ   t |ƒ ¡ }|r|d  ¡ dkrdS t|ƒdkrd}t|ƒ‚t|ƒdkr*d}t|ƒ‚zt|d ƒ}W n ty?   d}t|ƒ‚w |  ||¡S )zS
        Authenticate the request and return a two-tuple of (user, token).
        r   s   tokenNr   z-invalid auth header, No credentials provided.é   úinvalid auth token)r   ÚsplitÚlowerÚlenr   r   Ú
ValueErrorÚauthenticate_credentials)ÚselfÚrequestÚauthÚmsgÚtoken© r   úL/var/www/html/loop/nvenv/lib/python3.10/site-packages/rest_authtoken/auth.pyÚauthenticate
   s    þz$AuthTokenAuthentication.authenticateNr   c                 C   s0   t  |¡}|du rtdƒ‚|jstdƒ‚||fS )zK
        Authenticate the token with optional request for context.
        Nr
   )r   Úget_user_for_tokenr   Ú	is_active)r   r   r   Úuserr   r   r   r   "   s   
z0AuthTokenAuthentication.authenticate_credentialsc                 C   s   dS )NÚTokenr   )r   r   r   r   r   Úauthenticate_header0   s   z+AuthTokenAuthentication.authenticate_header)N)Ú__name__Ú
__module__Ú__qualname__r   Úbytesr   r   r   r   r   r   r   	   s    r   N)
Úbase64r   Úrest_framework.authenticationr   r   Úrest_framework.exceptionsr   Úmodelsr   r   r   r   r   r   Ú<module>   s
    