
    >i                         S 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
  SSKJr  SSKr " S S	\5      r " S
 S\	5      r " S S\5      rS rg)z1Custom JWT authentication to handle UUID user IDs    )JWTAuthentication)InvalidToken
TokenError)TokenRefreshSerializer)RefreshTokenAccessToken)UserNc                       \ rS rSrSrS rSrg)UUIDJWTAuthentication
   z6JWT Authentication that properly handles UUID user IDsc                     UR                  S5      nU(       d  [        S5      e[        U[        5      (       a   [        R
                  " U5      n [        R                  R                  US9nU$ ! [        [        4 a    [        S5      ef = f! [        R                   a    [        S5      ef = f! [         a    e [         a  n[        S[        U5       35      eSnAff = f)z+
Override to properly handle UUID user IDs
user_id3Token contained no recognizable user identification+Token contained invalid user identificationidUser not foundz-Token contained invalid user identification: N)getr   
isinstancestruuidUUID
ValueErrorAttributeErrorr	   objectsDoesNotExistr   	Exception)selfvalidated_tokenr   useres        %D:\TimeStamps\worktimeapp\jwt_auth.pyget_userUUIDJWTAuthentication.get_user   s    	Y%)))4G"#XYY '3''V"ii0G
5||''7'3 K #N3 V&'TUUV $$ 5"#3445  	 	Y!NsSTvhWXX	Ys@   8B3 A1 B /B3 1BB3  B00B3 3C#CC# N)__name__
__module____qualname____firstlineno____doc__r#   __static_attributes__r%       r"   r   r   
   s    @Yr,   r   c                   F   ^  \ rS rSrSr\U 4S j5       r\S 5       rSr	U =r
$ )UUIDRefreshToken*   z'RefreshToken that handles UUID user IDsc                 &   > [         TU ]  U5      nU$ )z+Override to ensure UUID is properly handled)superfor_user)clsr    token	__class__s      r"   r2   UUIDRefreshToken.for_user-   s      &r,   c                    U R                  S5      nU(       d  [        S5      e[        U[        5      (       a   [        R
                  " U5      n [        R                  R                  US9n[        R                  " U5      nU R                  R                  5        H  u  pEUS;  d  M  XSU'   M     U$ ! [        [        4 a    [        S5      ef = f! [        R                   a    [        S5      ef = f)z9Override access_token property to handle UUID user lookupr   r   r   r   r   )
token_typeexpiatjti)r   r   r   r   r   r   r   r   r	   r   r   r   r2   payloaditems)r   r   r    accessclaimvalues         r"   access_tokenUUIDRefreshToken.access_token3   s     ((9%TUU gs##R))G,
	1<<##w#/D
 %%d+ !LL..0LE?? %u 1
 ' / R"#PQQR    	1/00	1s   B5 C 5C C4r%   )r&   r'   r(   r)   r*   classmethodr2   propertyrA   r+   __classcell__)r5   s   @r"   r.   r.   *   s,    1 
  r,   r.   c                   "    \ rS rSrSr\rS rSrg)UUIDTokenRefreshSerializerU   z<Token refresh serializer that properly handles UUID user IDsc                    U R                  US   5      n UR                  5         UR                  S5      nU(       aJ  [        U[        5      (       a   [        R                  " U5      n [        R                  R                  US9  0 nUR                  5         UR                  5         UR!                  5         [	        U5      US'   [	        UR"                  5      US'   U$ ! [         a  n[        [	        U5      5      eS nAff = f! [        [        4 a    [        S5      ef = f! [        R                   a    [        S5      ef = f)Nrefreshr   r   r   r   r>   )token_classverifyr   r   r   r   r   r   r   r   r   r	   r   r   set_jtiset_expset_iatrA   )r   attrsrJ   r!   r   datas         r"   validate#UUIDTokenRefreshSerializer.validateY   s%   ""5#34	'NN
 ++i('3''V"ii0G5  G ,
 g,YW112X5  	's1v&&	' #N3 V&'TUUV
 $$ 5"#3445s/   C" D +D' "
D,D  DD$' Er%   N)	r&   r'   r(   r)   r*   r.   rK   rR   r+   r%   r,   r"   rG   rG   U   s    F"K r,   rG   c                  (    SSK Jn    " S SU 5      nU$ )zHGet UUID-aware token refresh view (lazy import to avoid circular import)r   )TokenRefreshViewc                       \ rS rSrSr\rSrg)9get_uuid_token_refresh_view.<locals>.UUIDTokenRefreshView   z2Token refresh view that uses UUID-aware serializerr%   N)r&   r'   r(   r)   r*   rG   serializer_classr+   r%   r,   r"   UUIDTokenRefreshViewrW      s    @5r,   rZ   )rest_framework_simplejwt.viewsrU   )rU   rZ   s     r"   get_uuid_token_refresh_viewr\   |   s    ?6/ 6  r,   )r*   'rest_framework_simplejwt.authenticationr   #rest_framework_simplejwt.exceptionsr   r   $rest_framework_simplejwt.serializersr   rest_framework_simplejwt.tokensr   r   user.modelsr	   r   r   r.   rG   r\   r%   r,   r"   <module>rb      sJ    7 E H G E  Y- Y@(| (V$!7 $N r,   