
     h                         d dl mZ d dlmZ d dlmZmZ ddlm	Z	m
Z
mZ ddlmZ ej        Z eej        eef          sefZd eD             Z G d d	ej                  Z G d
 de          ZeZd ZdS )    )get_user_model)gettext_lazy)HTTP_HEADER_ENCODINGauthentication   )AuthenticationFailedInvalidToken
TokenError)api_settingsc                 B    h | ]}|                     t                    S  )encoder   ).0hs     c/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/rest_framework_simplejwt/authentication.py	<setcomp>r      s%    TTTQ!((#788TTT    c                   N     e Zd ZdZdZdZ fdZd Zd Zd Z	d Z
d	 Zd
 Z xZS )JWTAuthenticationzy
    An authentication plugin that authenticates requests through a JSON web
    token provided in a request header.
    apizapplication/jsonc                 `     t                      j        |i | t                      | _        d S N)super__init__r   
user_model)selfargskwargs	__class__s      r   r   zJWTAuthentication.__init__   s0    $)&)))(**r   c                     |                      |          }|d S |                     |          }|d S |                     |          }|                     |          |fS r   )
get_headerget_raw_tokenget_validated_tokenget_user)r   requestheader	raw_tokenvalidated_tokens        r   authenticatezJWTAuthentication.authenticate   se    ))>4&&v..	4229==}}_-->>r   c                 N    d                     t          d         | j                  S )Nz{} realm="{}"r   )formatAUTH_HEADER_TYPESwww_authenticate_realm)r   r%   s     r   authenticate_headerz%JWTAuthentication.authenticate_header*   s(    %%a '
 
 	
r   c                     |j                             t          j                  }t	          |t
                    r|                    t                    }|S )zc
        Extracts the header containing the JSON web token from the given
        request.
        )METAgetr   AUTH_HEADER_NAME
isinstancestrr   r   )r   r%   r&   s      r   r!   zJWTAuthentication.get_header0   sE    
 !!,"?@@fc"" 	9]]#788Fr   c                     |                                 }t          |          dk    rdS |d         t          vrdS t          |          dk    rt          t	          d          d          |d         S )zm
        Extracts an unvalidated JSON web token from the given "Authorization"
        header value.
        r   N   z<Authorization header must contain two space-delimited valuesbad_authorization_headercoder   )splitlenAUTH_HEADER_TYPE_BYTESr   _)r   r&   partss      r   r"   zJWTAuthentication.get_raw_token=   sz    
 u::??481114u::??&PQQ/   
 Qxr   c                    g }t           j        D ]T}	  ||          c S # t          $ r8}|                    |j        |j        |j        d         d           Y d}~Md}~ww xY wt          t          d          |d          )zk
        Validates an encoded JSON web token and returns a validated token
        wrapper object.
        r   )token_class
token_typemessageNz(Given token not valid for any token type)detailmessages)	r   AUTH_TOKEN_CLASSESr
   append__name__rA   r   r	   r=   )r   r'   rD   	AuthTokenes        r   r#   z%JWTAuthentication.get_validated_tokenT   s    
 %8 
	 
	I	 y+++++   '0'9&/&:#$6!9         FGG$ 
 
 	
s   

A!.AA!c                 x   	 |t           j                 }n*# t          $ r t          t	          d                    w xY w	  | j        j        j        di t           j        |i}n1# | j        j	        $ r t          t	          d          d          w xY w|j        st          t	          d          d          |S )zU
        Attempts to find and return a user using the given validated token.
        3Token contained no recognizable user identificationzUser not founduser_not_foundr8   zUser is inactiveuser_inactiver   )r   USER_ID_CLAIMKeyErrorr	   r=   r   objectsr1   USER_ID_FIELDDoesNotExistr   	is_active)r   r(   user_idusers       r   r$   zJWTAuthentication.get_userm   s    	Y%l&@AGG 	Y 	Y 	Yq!VWWXXX	Y	S.4?*.WW,2Lg1VWWDD+ 	S 	S 	S&q)9':':AQRRRR	S ~ 	T&q);'<'<?SSSSs    '< #A$ $.B)rG   
__module____qualname____doc__r-   
media_typer   r)   r.   r!   r"   r#   r$   __classcell__)r   s   @r   r   r      s         
 ##J+ + + + +? ? ?
 
 
    .
 
 
2      r   r   c                       e Zd ZdZd ZdS )JWTStatelessUserAuthenticationz
    An authentication plugin that authenticates requests through a JSON web
    token provided in a request header without performing a database lookup to obtain a user instance.
    c                 ~    t           j        |vrt          t          d                    t          j        |          S )zg
        Returns a stateless user object which is backed by the given validated
        token.
        rK   )r   rN   r	   r=   TOKEN_USER_CLASS)r   r(   s     r   r$   z'JWTStatelessUserAuthentication.get_user   s<    
 %_<< q!VWWXXX,_===r   N)rG   rV   rW   rX   r$   r   r   r   r\   r\      s-         

> 
> 
> 
> 
>r   r\   c                     | d uo| j         S r   )rS   )rU   s    r    default_user_authentication_ruler`      s     t..r   N)django.contrib.authr   django.utils.translationr   r=   rest_frameworkr   r   
exceptionsr   r	   r
   settingsr   r,   r3   listtupler<   BaseAuthenticationr   r\   JWTTokenUserAuthenticationr`   r   r   r   <module>rj      s5   . . . . . . 6 6 6 6 6 6 ? ? ? ? ? ? ? ? F F F F F F F F F F " " " " " " 2 z,04-@@ -*,TTBSTTT n n n n n9 n n nb> > > > >%6 > > >& < / / / / /r   