U
    ÔÉ>it  ã                   @   sR   d dl mZ d dlmZ d dlmZ d dlmZ eejƒZ	e	j
Z
G dd„ dƒZdS )é    )Úimport_module)Úurlparse)Úsettings)Úpatch_vary_headersc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚLoginSessionaT  Some providers sometimes POST their responses, which due to
    CORS/Samesite-cookie rules means that this request cannot access the session
    as its session cookie is unavailable.

    We work around this by storing the response in a separate, temporary session
    and redirecting to a different endpoint that can pick up the flow.
    c                 C   sR   || _ || _|| _t||dƒ| _| jdkrN|j |¡}t|ƒ| _t||| jƒ dS )z8
        Prepares an provider specific session.
        N)	ÚrequestÚattribute_nameÚcookie_nameÚgetattrÚstoreZCOOKIESÚgetÚSessionStoreÚsetattr)Úselfr   r   r	   Úsession_key© r   úB/tmp/pip-unpacked-wheel-upujnpc2/allauth/socialaccount/sessions.pyÚ__init__   s    

zLoginSession.__init__c              	   C   sh   t |dƒ | j ¡  i }ttddƒ}|r0||d< |j| j| jjfddtjt	|j
ƒjtjddœ|—Ž dS )z4
        Save the session and set a cookie.
        )ÚCookieZSESSION_COOKIE_SAMESITENÚsamesite)Zmax_ageÚexpiresÚdomainÚpathÚsecureÚhttponly)r   r   Úsaver
   r   Ú
set_cookier	   r   ZSESSION_COOKIE_DOMAINr   Úurlr   ZSESSION_COOKIE_SECURE)r   ÚresponseÚkwargsr   r   r   r   r   "   s&    

þ
÷
özLoginSession.savec                 C   s   | j  ¡  d S )N)r   Údelete)r   r   r   r   r    9   s    zLoginSession.deleteN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r   r   r   r   r      s   r   N)Ú	importlibr   Úurllib.parser   Zdjango.confr   Zdjango.utils.cacher   ZSESSION_ENGINEZenginer   r   r   r   r   r   Ú<module>   s   
