U
    g                     @   s2  d 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eddd	Zeeed
ddZedddZeedddZeeedddZeedddZeedddZeeedddZeeedddZeeedd d!Zeeed"d#d$Zeeed"d%d&Zeeedd'd(Zeed)d*d+Zd,S )-a  
These are the default methods implementations that are used in this extension.
All of these can be updated on an app by app basis using the JWTManager
loader decorators. For further information, check out the following links:

http://flask-jwt-extended.readthedocs.io/en/latest/changing_default_behavior.html
http://flask-jwt-extended.readthedocs.io/en/latest/tokens_from_complex_object.html
    )
HTTPStatus)Any)jsonify)ResponseReturnValue)config)userdatareturnc                 C   s   i S )z
    By default, we add no additional claims to the access tokens.

    :param userdata: data passed in as the ```identity``` argument to the
                     ```create_access_token``` and ```create_refresh_token```
                     functions
     r   r	   r	   H/tmp/pip-unpacked-wheel-qm6yk1_p/flask_jwt_extended/default_callbacks.py"default_additional_claims_callback   s    r   )jwt_headersjwt_datar   c                 C   s   dS )NFr	   )r   r   r	   r	   r   default_blocklist_callback   s    r   )r   c                 C   s   i S )aG  
    By default header typically consists of two parts: the type of the token,
    which is JWT, and the signing algorithm being used, such as HMAC SHA256
    or RSA. But we don't set the default header here we set it as empty which
    further by default set while encoding the token
    :return: default we set None here
    r	   )default_headersr	   r	   r   default_jwt_headers_callback!   s    r   c                 C   s   | S )a)  
    By default, we use the passed in object directly as the jwt identity.
    See this for additional info:

    :param userdata: data passed in as the ```identity``` argument to the
                     ```create_access_token``` and ```create_refresh_token```
                     functions
    r	   r
   r	   r	   r   default_user_identity_callback,   s    	r   )_expired_jwt_header_expired_jwt_datar   c                 C   s   t tjditjfS )z
    By default, if an expired token attempts to access a protected endpoint,
    we return a generic error message with a 401 status
    zToken has expiredr   r   error_msg_keyr   UNAUTHORIZED)r   r   r	   r	   r   default_expired_token_callback8   s    r   )error_stringr   c                 C   s   t tj| itjfS )z
    By default, if an invalid token attempts to access a protected endpoint, we
    return the error string for why it is not valid with a 422 status code

    :param error_string: String indicating why the token is invalid
    )r   r   r   r   UNPROCESSABLE_ENTITYr   r	   r	   r   default_invalid_token_callbackB   s    r   c                 C   s   t tj| itjfS )z
    By default, if a protected endpoint is accessed without a JWT, we return
    the error string indicating why this is unauthorized, with a 401 status code

    :param error_string: String indicating why this request is unauthorized
    r   r   r	   r	   r   default_unauthorized_callbackO   s    r   )
jwt_headerr   r   c                 C   s   t tjditjfS )z
    By default, if a non-fresh jwt is used to access a ```fresh_jwt_required```
    endpoint, we return a general error message with a 401 status code
    zFresh token requiredr   r   r   r	   r	   r   "default_needs_fresh_token_callbackY   s    r    c                 C   s   t tjditjfS )z
    By default, if a revoked token is used to access a protected endpoint, we
    return a general error message with a 401 status code
    zToken has been revokedr   r   r	   r	   r   default_revoked_token_callbackf   s    r!   )_jwt_headerr   r   c                 C   s(   |t j }t jd| i}t|tjfS )z
    By default, if a user_lookup callback is defined and the callback
    function returns None, we return a general error message with a 401
    status code
    zError loading the user )r   Zidentity_claim_keyr   r   r   r   )r"   r   identityresultr	   r	   r   "default_user_lookup_error_callbacks   s    
r%   )r"   	_jwt_datar   c                 C   s   dS )zG
    By default, we do not do any verification of the user claims.
    Tr	   r"   r&   r	   r	   r   #default_token_verification_callback   s    r(   c                 C   s   t tjditjfS )zz
    By default, if the user claims verification failed, we return a generic
    error message with a 400 status code
    zUser claims verification failed)r   r   r   r   BAD_REQUESTr'   r	   r	   r   *default_token_verification_failed_callback   s    r*   c                 C   s   t jS )z
    By default, the decode key specified via the JWT_SECRET_KEY or
    JWT_PUBLIC_KEY settings will be used to decode all tokens
    )r   Z
decode_keyr   r	   r	   r   default_decode_key_callback   s    r+   )r#   r   c                 C   s   t jS )z
    By default, the encode key specified via the JWT_SECRET_KEY or
    JWT_PRIVATE_KEY settings will be used to encode all tokens
    )r   Z
encode_key)r#   r	   r	   r   default_encode_key_callback   s    r,   N)__doc__httpr   typingr   Zflaskr   Zflask.typingr   Zflask_jwt_extended.configr   dictr   boolr   r   r   r   strr   r   r    r!   r%   r(   r*   r+   r,   r	   r	   r	   r   <module>   sD    
    