U
    ÔÉ>ià  ã                   @   s€   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 G dd	„ d	eƒZeƒ ZG d
d„ deƒZeƒ ZdS )é    N)ÚHttpRequest)ÚAuthBase)Úget_authorization_credential)Úapp_settings)Úauthenticate_by_x_session_token)Úvalidate_access_tokenc                   @   sB   e Zd ZU dZdZeed< edœdd„Zee	j
e dœdd	„Zd
S )ÚXSessionTokenAuthzt
    This security class uses the X-Session-Token that django-allauth
    is using for authentication purposes.
    ÚapiKeyÚopenapi_type©Úrequestc                 C   s&   |   |¡}|r"t|ƒ}|r"|d S d S )Nr   )Úget_session_tokenr   )Úselfr   ÚtokenZuser_session© r   úK/tmp/pip-unpacked-wheel-upujnpc2/allauth/headless/contrib/ninja/security.pyÚ__call__   s    
zXSessionTokenAuth.__call__)r   Úreturnc                 C   s   |j  d¡S )z×
        Returns the session token for the given request, by looking up the
        ``X-Session-Token`` header. Override this if you want to extract the token
        from e.g. the ``Authorization`` header.
        zX-Session-Token)ÚheadersÚget)r   r   r   r   r   r      s    z#XSessionTokenAuth.get_session_tokenN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚstrÚ__annotations__r   r   ÚtypingÚOptionalr   r   r   r   r   r      s   
r   c                   @   s(   e Zd ZU dZeed< edœdd„ZdS )ÚJWTTokenAuthr	   r
   r   c                 C   s>   t |tjƒ}|d krd S t|ƒ}|d kr,d S |\}}||_|S )N)r   r   ZJWT_AUTHORIZATION_HEADER_SCHEMEr   Úuser)r   r   r   Zuser_payloadr   Úpayloadr   r   r   r   -   s     ÿzJWTTokenAuth.__call__N)r   r   r   r
   r   r   r   r   r   r   r   r   r   )   s   
r   )r   Zdjango.httpr   Zninja.security.baser   Zallauth.core.internal.httpkitr   Zallauth.headlessr   Z$allauth.headless.internal.sessionkitr   Z/allauth.headless.tokens.strategies.jwt.internalr   r   Zx_session_token_authr   Zjwt_token_authr   r   r   r   Ú<module>   s   