
    g\>                        U d dl mZ d dl mZ 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 d d	lmZ d d
lmZ  ed       Zeed<   defdZdefdZdefdZdee   fdZdefdZ	 d*dedee   dedefdZ	 	 	 	 d+dededee   fdZ	 	 	 d,dedee   fdZdedefdZdedee   fdZdedefdZ	 d-ded eddfd!Z 	 	 d-ded"ed#ee!   d$ee   ddf
d%Z"d.ded$ee   ddfd&Z#d.ded$ee   ddfd'Z$d.ded$ee   ddfd(Z%defd)Z&y)/    )Any)OptionalN)g)Response)
LocalProxy)config)get_jwt_manager)ExpiresDelta)Freshc                      t               S Nget_current_user     X/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/flask_jwt_extended/utils.py<lambda>r      s    '7'9r   current_userreturnc                  L    t        j                  dd      } | t        d      | S )a=  
    In a protected endpoint, this will return the python dictionary which has
    the payload of the JWT that is accessing the endpoint. If no JWT is present
    due to ``jwt_required(optional=True)``, an empty dictionary is returned.

    :return:
        The payload (claims) of the JWT in the current request
    _jwt_extended_jwtNUYou must call `@jwt_required()` or `verify_jwt_in_request()` before using this methodr   getRuntimeError)decoded_jwts    r   get_jwtr      s5     %%+T2K'
 	
 r   c                  L    t        j                  dd      } | t        d      | S )a3  
    In a protected endpoint, this will return the python dictionary which has
    the header of the JWT that is accessing the endpoint. If no JWT is present
    due to ``jwt_required(optional=True)``, an empty dictionary is returned.

    :return:
        The headers of the JWT in the current request
    _jwt_extended_jwt_headerNr   r   )decoded_headers    r   get_jwt_headerr!   $   s5     UU5t<N'
 	
 r   c                  R    t               j                  t        j                  d      S )a  
    In a protected endpoint, this will return the identity of the JWT that is
    accessing the endpoint. If no JWT is present due to
    ``jwt_required(optional=True)``, ``None`` is returned.

    :return:
        The identity of the JWT in the current request
    N)r   r   r   identity_claim_keyr   r   r   get_jwt_identityr$   6   s     9==22D99r   c                  .    t        j                  dd      S )a  
    In a protected endpoint, this will return the "location" at which the JWT
    that is accessing the endpoint was found--e.g., "cookies", "query-string",
    "headers", or "json". If no JWT is present due to ``jwt_required(optional=True)``,
    None is returned.

    :return:
        The location of the JWT in the current request; e.g., "cookies",
        "query-string", "headers", or "json"
    _jwt_extended_jwt_locationN)r   r   r   r   r   get_jwt_request_locationr'   B   s     55-t44r   c                  f    t                t        j                  dd      } | t        d      | d   S )a  
    In a protected endpoint, this will return the user object for the JWT that
    is accessing the endpoint.

    This is only usable if :meth:`~flask_jwt_extended.JWTManager.user_lookup_loader`
    is configured. If the user loader callback is not being used, this will
    raise an error.

    If no JWT is present due to ``jwt_required(optional=True)``, ``None`` is returned.

    :return:
        The current user object for the JWT in the current request
    _jwt_extended_jwt_userNzHYou must provide a `@jwt.user_lookup_loader` callback to use this methodloaded_user)r   r   r   r   )jwt_user_dicts    r   r   r   P   s?     IEE2D9M
 	
 ''r   encoded_token
csrf_valueallow_expiredc                 <    t               }|j                  | ||      S )a  
    Returns the decoded token (python dict) from an encoded JWT. This does all
    the checks to ensure that the decoded token is valid before returning it.

    This will not fire the user loader callbacks, save the token for access
    in protected endpoints, checked if a token is revoked, etc. This is puerly
    used to ensure that a JWT is valid.

    :param encoded_token:
        The encoded JWT to decode.

    :param csrf_value:
        Expected CSRF double submit value (optional).

    :param allow_expired:
        If ``True``, do not raise an error if the JWT is expired.  Defaults to ``False``

    :return:
        Dictionary containing the payload of the JWT decoded JWT.
    )r	   _decode_jwt_from_config)r,   r-   r.   jwt_managers       r   decode_tokenr2   h   s!    . "#K..}j-XXr   identityfreshexpires_deltac                 D    t               }|j                  ||||| d      S )a  
    Create a new access token.

    :param identity:
        The identity of this token. This must either be a string, or you must have
        defined :meth:`~flask_jwt_extended.JWTManager.user_identity_loader` in order
        to convert the object you passed in into a string.

    :param fresh:
        If this token should be marked as fresh, and can thus access endpoints
        protected with ``@jwt_required(fresh=True)``. Defaults to ``False``.

        This value can also be a ``datetime.timedelta``, which indicate
        how long this token will be considered fresh.

    :param expires_delta:
        A ``datetime.timedelta`` for how long this token should last before it
        expires. Set to False to disable expiration. If this is None, it will use
        the ``JWT_ACCESS_TOKEN_EXPIRES`` config value (see :ref:`Configuration Options`)

    :param additional_claims:
        Optional. A hash of claims to include in the access token.  These claims are
        merged into the default claims (exp, iat, etc) and claims returned from the
        :meth:`~flask_jwt_extended.JWTManager.additional_claims_loader` callback.
        On conflict, these claims take precedence.

    :param headers:
        Optional. A hash of headers to include in the access token. These headers
        are merged into the default headers (alg, typ) and headers returned from
        the :meth:`~flask_jwt_extended.JWTManager.additional_headers_loader`
        callback. On conflict, these headers take precedence.

    :return:
        An encoded access token
    accessclaimsr5   r4   headersr3   
token_typer	   _encode_jwt_from_config)r3   r4   r5   additional_claimsadditional_headersr1   s         r   create_access_tokenr@      s7    T "#K.. #" /  r   c                 D    t               }|j                  ||d|| d      S )a  
    Create a new refresh token.

    :param identity:
        The identity of this token. This must either be a string, or you must have
        defined :meth:`~flask_jwt_extended.JWTManager.user_identity_loader` in order
        to convert the object you passed in into a string.

    :param expires_delta:
        A ``datetime.timedelta`` for how long this token should last before it expires.
        Set to False to disable expiration. If this is None, it will use the
        ``JWT_REFRESH_TOKEN_EXPIRES`` config value (see :ref:`Configuration Options`)

    :param additional_claims:
        Optional. A hash of claims to include in the refresh token. These claims are
        merged into the default claims (exp, iat, etc) and claims returned from the
        :meth:`~flask_jwt_extended.JWTManager.additional_claims_loader` callback.
        On conflict, these claims take precedence.

    :param headers:
        Optional. A hash of headers to include in the refresh token. These headers
        are merged into the default headers (alg, typ) and headers returned from the
        :meth:`~flask_jwt_extended.JWTManager.additional_headers_loader` callback.
        On conflict, these headers take precedence.

    :return:
        An encoded refresh token
    Frefreshr8   r<   )r3   r5   r>   r?   r1   s        r   create_refresh_tokenrC      s7    D "#K.. #" /  r   c                 ,    t        j                  |       S )z
    Returns the Headers of an encoded JWT without verifying the signature of the JWT.

    :param encoded_token:
        The encoded JWT to get the Header from.

    :return:
        JWT header parameters as python dict()
    )jwtget_unverified_headerr,   s    r   get_unverified_jwt_headersrH      s     $$]33r   c                 6    t        |       j                  d      S )z
    Returns the JTI (unique identifier) of an encoded JWT

    :param encoded_token:
        The encoded JWT to get the JTI from.

    :return:
        The JTI (unique identifier) of a JWT, if it is present.
    jti)r2   r   rG   s    r   get_jtirK      s     &**511r   c                 "    t        |       }|d   S )z
    Returns the CSRF double submit token from an encoded JWT.

    :param encoded_token:
        The encoded JWT

    :return:
        The CSRF double submit token (string)
    csrf)r2   )r,   tokens     r   get_csrf_tokenrO      s     'E=r   responseencoded_access_tokenc           
      .   | j                  t        j                  ||xs t        j                  t        j                  d|xs t        j
                  t        j                  t        j                         t        j                  rt        j                  r| j                  t        j                  t        |      |xs t        j                  t        j                  d|xs t        j
                  t        j                  t        j                         yyy)a  
    Modifiy a Flask Response to set a cookie containing the access JWT.
    Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
    (see :ref:`Configuration Options`)

    :param response:
        A Flask Response object.

    :param encoded_access_token:
        The encoded access token to set in the cookies.

    :param max_age:
        The max age of the cookie. If this is None, it will use the
        ``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
        will be ignored. Values should be the number of seconds (as an integer).

    :param domain:
        The domain of the cookie. If this is None, it will use the
        ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
        will be ignored.
    Tvaluemax_agesecurehttponlydomainpathsamesiteFN)
set_cookier   access_cookie_namecookie_max_agecookie_securecookie_domainaccess_cookie_pathcookie_samesitecookie_csrf_protectcsrf_in_cookiesaccess_csrf_cookie_namerO   access_csrf_cookie_path)rP   rQ   rU   rX   s       r   set_access_cookiesrf     s    4 !!"0600##---&&''  	 !!f&<&<** !564v44''1V11//++ 	 		
 '=!r   encoded_refresh_tokenrU   rX   c           
      .   | j                  t        j                  ||xs t        j                  t        j                  d|xs t        j
                  t        j                  t        j                         t        j                  rt        j                  r| j                  t        j                  t        |      |xs t        j                  t        j                  d|xs t        j
                  t        j                  t        j                         yyy)a  
    Modifiy a Flask Response to set a cookie containing the refresh JWT.
    Also sets the corresponding CSRF cookies if ``JWT_CSRF_IN_COOKIES`` is ``True``
    (see :ref:`Configuration Options`)

    :param response:
        A Flask Response object.

    :param encoded_refresh_token:
        The encoded refresh token to set in the cookies.

    :param max_age:
        The max age of the cookie. If this is None, it will use the
        ``JWT_SESSION_COOKIE`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``max-age`` and the JWT_SESSION_COOKIE option
        will be ignored. Values should be the number of seconds (as an integer).

    :param domain:
        The domain of the cookie. If this is None, it will use the
        ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
        will be ignored.
    TrS   FN)r[   r   refresh_cookie_namer]   r^   r_   refresh_cookie_pathra   rb   rc   refresh_csrf_cookie_namerO   refresh_csrf_cookie_path)rP   rg   rU   rX   s       r   set_refresh_cookiesrm   ?  s    : ""#0600##---''''  	 !!f&<&<++ !674v44''1V1100++ 	 		
 '=!r   c                 4    t        | |       t        | |       y)z
    Modifiy a Flask Response to delete the cookies containing access or refresh
    JWTs.  Also deletes the corresponding CSRF cookies if applicable.

    :param response:
        A Flask Response object
    N)unset_access_cookiesunset_refresh_cookiesrP   rX   s     r   unset_jwt_cookiesrr   t  s     6*(F+r   c           
         | j                  t        j                  ddt        j                  d|xs t        j                  t        j
                  t        j                         t        j                  rut        j                  rd| j                  t        j                  ddt        j                  d|xs t        j                  t        j                  t        j                         yyy)a  
    Modifiy a Flask Response to delete the cookie containing an access JWT.
    Also deletes the corresponding CSRF cookie if applicable.

    :param response:
        A Flask Response object

    :param domain:
        The domain of the cookie. If this is None, it will use the
        ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
        will be ignored.
     r   TrT   expiresrV   rW   rX   rY   rZ   FN)r[   r   r\   r^   r_   r`   ra   rb   rc   rd   re   rq   s     r   ro   ro     s     !!##---&&''  	 !!f&<&<**''1V11//++ 	 		
 '=!r   c           
         | j                  t        j                  ddt        j                  d|xs t        j                  t        j
                  t        j                         t        j                  rut        j                  rd| j                  t        j                  ddt        j                  d|xs t        j                  t        j                  t        j                         yyy)a  
    Modifiy a Flask Response to delete the cookie containing a refresh JWT.
    Also deletes the corresponding CSRF cookie if applicable.

    :param response:
        A Flask Response object

    :param domain:
        The domain of the cookie. If this is None, it will use the
        ``JWT_COOKIE_DOMAIN`` option (see :ref:`Configuration Options`). Otherwise,
        it will use this as the cookies ``domain`` and the JWT_COOKIE_DOMAIN option
        will be ignored.
    rt   r   Tru   FN)r[   r   ri   r^   r_   rj   ra   rb   rc   rk   rl   rq   s     r   rp   rp     s     ""##---''''  	 !!f&<&<++''1V1100++ 	 		
 '=!r   c                      dt               iS )Nr   r   r   r   r   current_user_context_processorry     s    ,.//r   )NF)FNNN)NNN)NNr   )'typingr   r   rE   flaskr   r   werkzeug.localr   flask_jwt_extended.configr   !flask_jwt_extended.internal_utilsr	   flask_jwt_extended.typingr
   r   r   __annotations__dictr   r!   r$   strr'   r   boolr2   r@   rC   rH   rK   rO   rf   intrm   rr   ro   rp   ry   r   r   r   <module>r      s     
   % , = 2 + 9:c : $ $	:# 	:5(3- 5(# (2 QVYY$,SMYIMY	Y: ,0222 L)2n -1	**L)*Z
4c 
4d 
4
23 
28C= 
2# #  IM/
/
.1/
	/
j " 	2
2
2
 c]2
 SM	2

 
2
j	, 	,(3- 	,4 	,#
8 #
Xc] #
d #
L#
H #
hsm #
t #
L0 0r   