
     h                         d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ ej        Zej        Z G d d	e          Z G d
 de          ZdS )    N)get_user_model)
smart_text)ugettext)
exceptions)BaseAuthenticationget_authorization_header)api_settingsc                       e Zd ZdZd Zd ZdS )BaseJSONWebTokenAuthenticationzG
    Token based authentication using the JSON Web Token standard.
    c                    |                      |          }|dS 	 t          |          }n# t          j        $ r$ t	          d          }t          j        |          t          j        $ r$ t	          d          }t          j        |          t          j        $ r t          j                    w xY w| 	                    |          }||fS )z
        Returns a two-tuple of `User` and token if a valid signature has been
        supplied using JWT-based authentication.  Otherwise returns `None`.
        NzSignature has expired.zError decoding signature.)
get_jwt_valuejwt_decode_handlerjwtExpiredSignature_r   AuthenticationFailedDecodeErrorInvalidTokenErrorauthenticate_credentials)selfrequest	jwt_valuepayloadmsgusers         ]/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/rest_framework_jwt/authentication.pyauthenticatez+BaseJSONWebTokenAuthentication.authenticate   s    
 &&w//	4		4(33GG# 	7 	7 	7,--C1#666 	7 	7 	7/00C1#666$ 	4 	4 	41333	4 ,,W55i  s
   + BB0c                 x   t                      }t          |          }|s#t          d          }t          j        |          	 |j                            |          }n1# |j        $ r$ t          d          }t          j        |          w xY w|j        s#t          d          }t          j        |          |S )zV
        Returns an active user that matches the payload's user id and email.
        zInvalid payload.zInvalid signature.zUser account is disabled.)	r   jwt_get_username_from_payloadr   r   r   objectsget_by_natural_keyDoesNotExist	is_active)r   r   Userusernamer   r   s         r   r   z7BaseJSONWebTokenAuthentication.authenticate_credentials/   s     099 	7&''C1#666	7<228<<DD  	7 	7 	7())C1#666	7 ~ 	7/00C1#666s   A .BN)__name__
__module____qualname____doc__r   r        r   r   r      s<         ! ! !0    r+   r   c                   "    e Zd ZdZdZd Zd ZdS )JSONWebTokenAuthenticationz
    Clients should authenticate by passing the token key in the "Authorization"
    HTTP header, prepended with the string specified in the setting
    `JWT_AUTH_HEADER_PREFIX`. For example:

        Authorization: JWT eyJhbGciOiAiSFMyNTYiLCAidHlwIj
    apic                 *   t          |                                          }t          j                                        }|s2t          j        r$|j                            t          j                  S d S t          |d                                                   |k    rd S t          |          dk    r#t          d          }t          j        |          t          |          dk    r#t          d          }t          j        |          |d         S )Nr      z6Invalid Authorization header. No credentials provided.   zKInvalid Authorization header. Credentials string should not contain spaces.)r   splitr	   JWT_AUTH_HEADER_PREFIXlowerJWT_AUTH_COOKIECOOKIESgetr   lenr   r   r   )r   r   authauth_header_prefixr   s        r   r   z(JSONWebTokenAuthentication.get_jwt_valueQ   s    '006688)@FFHH 	+ I**<+GHHH4d1gmmoo&&*<<<4t99>>LMMC1#666YY]] 1 2 2C1#666Awr+   c                 L    d                     t          j        | j                  S )z
        Return a string to be used as the value of the `WWW-Authenticate`
        header in a `401 Unauthenticated` response, or `None` if the
        authentication scheme should return `403 Permission Denied` responses.
        z{0} realm="{1}")formatr	   r3   www_authenticate_realm)r   r   s     r   authenticate_headerz.JSONWebTokenAuthentication.authenticate_headerg   s      !''(KTMhiiir+   N)r&   r'   r(   r)   r=   r   r>   r*   r+   r   r-   r-   G   sI          #  ,j j j j jr+   r-   )r   django.contrib.authr   django.utils.encodingr   django.utils.translationr   r   rest_frameworkr   rest_framework.authenticationr   r   rest_framework_jwt.settingsr	   JWT_DECODE_HANDLERr    JWT_PAYLOAD_GET_USERNAME_HANDLERr   r   r-   r*   r+   r   <module>rG      s   



 . . . . . . , , , , , , 2 2 2 2 2 2 % % % % % %        5 4 4 4 4 4 "4  , M 2 2 2 2 2%7 2 2 2j&j &j &j &j &j!? &j &j &j &j &jr+   