o
    &zht  ã                   @   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   sV   || _ || _|| _t||dƒ| _| jdu r)|j |¡}t|ƒ| _t||| jƒ dS dS )z8
        Prepares an provider specific session.
        N)	ÚrequestÚattribute_nameÚcookie_nameÚgetattrÚstoreÚCOOKIESÚgetÚSessionStoreÚsetattr)Úselfr   r   r	   Úsession_key© r   úY/var/www/html/kangema/venv/lib/python3.10/site-packages/allauth/socialaccount/sessions.pyÚ__init__   s   

ýzLoginSession.__init__c              	   C   sh   t |dƒ | j ¡  i }ttddƒ}|r||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.
        )ÚCookieÚSESSION_COOKIE_SAMESITENÚsamesite)Úmax_ageÚexpiresÚdomainÚpathÚsecureÚhttponly)r   r   Úsaver
   r   Ú
set_cookier	   r   ÚSESSION_COOKIE_DOMAINr   Úurlr   Ú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   Údjango.confr   Údjango.utils.cacher   ÚSESSION_ENGINEÚenginer   r   r   r   r   r   Ú<module>   s    
