
    -h                        % S SK JrJr  S SKJr  S SKJr  S SKJr	  S SK
JrJr  S SKJr  SSKJrJrJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R6                  r\" \R6                  \\45      (       d  \4r\ V s1 sH  o R?                  \5      iM     sn r \!\"   \#S'   \" S\\5      r$ " S S\RJ                  5      r& " S S\&5      r'\'r(S\$S\)4S jr*gs  sn f )    )OptionalTypeVar)get_user_model)AbstractBaseUser)gettext_lazy)HTTP_HEADER_ENCODINGauthentication)Request   )AuthenticationFailedInvalidToken
TokenError)	TokenUser)api_settings)Token)get_md5_hash_passwordAUTH_HEADER_TYPE_BYTESAuthUserc                      ^  \ rS rSrSrSrSrSU 4S jjrS\S\	\
\\4      4S jrS\S\4S	 jrS\S\4S
 jrS\S\	\   4S jrS\S\4S jrS\S\4S jrSrU =r$ )JWTAuthentication   zm
An authentication plugin that authenticates requests through a JSON web
token provided in a request header.
apizapplication/jsonreturnc                 D   > [         TU ]  " U0 UD6  [        5       U l        g N)super__init__r   
user_model)selfargskwargs	__class__s      b/var/www/html/Ai_home/venv/lib/python3.13/site-packages/rest_framework_simplejwt/authentication.pyr   JWTAuthentication.__init__$   s    $)&)(*    requestc                     U R                  U5      nUc  g U R                  U5      nUc  g U R                  U5      nU R                  U5      U4$ r   )
get_headerget_raw_tokenget_validated_tokenget_user)r   r&   header	raw_tokenvalidated_tokens        r#   authenticateJWTAuthentication.authenticate(   sU    )>&&v.	229=}}_->>r%   c                 H    SR                  [        S   U R                  5      $ )Nz{} realm="{}"r   )formatAUTH_HEADER_TYPESwww_authenticate_realm)r   r&   s     r#   authenticate_header%JWTAuthentication.authenticate_header5   s&    %%a ''
 	
r%   c                     UR                   R                  [        R                  5      n[	        U[
        5      (       a  UR                  [        5      nU$ )zK
Extracts the header containing the JSON web token from the given
request.
)METAgetr   AUTH_HEADER_NAME
isinstancestrencoder   )r   r&   r,   s      r#   r(   JWTAuthentication.get_header;   s?    
 !!,"?"?@fc""]]#78Fr%   r,   c                     UR                  5       n[        U5      S:X  a  gUS   [        ;  a  g[        U5      S:w  a  [        [	        S5      SS9eUS   $ )zU
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lenr   r   _)r   r,   partss      r#   r)   JWTAuthentication.get_raw_tokenH   s\    
 u:?811u:?&PQ/ 
 Qxr%   r-   c                    / n[         R                   H  n U" U5      s  $    [        [        S5      US.5      e! [         aA  nUR                  UR                  UR
                  UR                  S   S.5         SnAMm  SnAff = f)zS
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__rK   r    r   rF   )r   r-   rN   	AuthTokenes        r#   r*   %JWTAuthentication.get_validated_token_   s    
 %88I	 ++ 9 FG$
 	
  '0'9'9&/&:&:#$66!9 s   :
B6B  Br.   c                     U[         R                     n U R
                  R                  R                  " S
0 [         R                  U0D6n[         R                  (       a$  UR                  (       d  [        [	        S5      SS9e[         R                  (       aI  UR                  [         R                  5      [        UR                   5      :w  a  [        [	        S5      S	S9eU$ ! [         a  n[        [	        S5      5      UeSnAff = f! U R
                  R                   a  n[        [	        S5      SS9UeSnAff = f)zE
Attempts to find and return a user using the given validated token.
3Token contained no recognizable user identificationNzUser not founduser_not_foundrB   zUser is inactiveuser_inactivez%The user's password has been changed.password_changed )r   USER_ID_CLAIMKeyErrorr   rF   r   objectsr9   USER_ID_FIELDDoesNotExistr   CHECK_USER_IS_ACTIVE	is_activeCHECK_REVOKE_TOKENREVOKE_TOKEN_CLAIMr   password)r   r.   user_idrS   users        r#   r+   JWTAuthentication.get_userx   s   	%l&@&@AG	??**..W,2L2Lg1VWD ,,T^^&q);'<?SS**""//&t}}56 +=>EW  /  	GH	 ++ 	&"#*:	s.   C% 6D %
D	/DD	D?&D::D?)r   )r   N)rQ   
__module____qualname____firstlineno____doc__r4   
media_typer   r
   r   tupler   r   r/   r<   r5   bytesr(   r)   r*   r+   __static_attributes____classcell__)r"   s   @r#   r   r      s    
 ##J+?G ?x9O0P ?
7 
s 
' e E huo .
U 
u 
2 (  r%   r   c                   *    \ rS rSrSrS\S\4S jrSrg)JWTStatelessUserAuthentication   z
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.
r.   r   c                 ~    [         R                  U;  a  [        [        S5      5      e[         R                  " U5      $ )zO
Returns a stateless user object which is backed by the given validated
token.
rV   )r   r[   r   rF   TOKEN_USER_CLASS)r   r.   s     r#   r+   'JWTStatelessUserAuthentication.get_user   s6    
 %%_< q!VWXX,,_==r%   rZ   N)	rQ   rh   ri   rj   rk   r   r   r+   ro   rZ   r%   r#   rr   rr      s    

> 
>( 
>r%   rr   rf   r   c                 h    U S L=(       a(    [         R                  (       + =(       d    U R                  $ r   )r   r`   ra   )rf   s    r#    default_user_authentication_rulerx      s+     t ---?r%   N)+typingr   r   django.contrib.authr   django.contrib.auth.modelsr   django.utils.translationr   rF   rest_frameworkr   r	   rest_framework.requestr
   
exceptionsr   r   r   modelsr   settingsr   tokensr   utilsr   r3   r;   listrm   r=   r   setrn   __annotations__r   BaseAuthenticationr   rr   JWTTokenUserAuthenticationboolrx   )hs   0r#   <module>r      s    $ $ . 7 6 ? * F F  "  ( 22 ,004-@@*, ->&,=qHH!",=& E
  :/;z99 zz>%6 >& < 
8 
 
u&s   9C