o
    gfh
                     @   s   d Z ddlmZ zddlZW n ey-   zddlZW n ey*   ddlmZ Y nw Y nw ddlmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZ d	ZG d
d de
ZG dd deZdeiZdS )z
BrowserID support
    )	urlencodeN)
simplejson)authenticate)SocialAuthBackendBaseAuth)logdsa_urlopen)
AuthFailedAuthMissingParameterz)https://verifier.login.persona.org/verifyc                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
BrowserIDBackendz BrowserID authentication backend	browseridc                 C   s   |d S )zUse BrowserID email as IDemail )selfdetailsresponser   r   _/var/www/html/humari/django-venv/lib/python3.10/site-packages/social_auth/backends/browserid.pyget_user_id   s   zBrowserIDBackend.get_user_idc                 C   s$   |d }| ddd |ddddS )z3Return user details, BrowserID only provides Email.r   @   r    )usernamer   fullname
first_name	last_name)split)r   r   r   r   r   r   get_user_details!   s   z!BrowserIDBackend.get_user_detailsc                 C   s   |d |d dS )zReturn users extra dataaudienceissuer)r   r   r   )r   useruidr   r   r   r   r   
extra_data/   s   zBrowserIDBackend.extra_dataN)__name__
__module____qualname____doc__namer   r   r!   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZeZdd ZdS )BrowserIDAuthzBrowserID authenticationc                 O   s   d| j vr
t| dt| j d | j d}zttt|d}W n t	y3   t
dddd Y dS w |dd	krDt
d
d t| |d| d|| jjdi t|i |S )z3Completes loging process, must return user instance	assertion)r(   r   )dataerrorz(Could not load user data from BrowserID.T)exc_infostatusfailuredebugzAuthentication failed.authr   N)r)   r
   r   requestget_hostr   loadr   BROWSER_ID_SERVER
ValueErrorr   getr	   updateAUTH_BACKENDr&   r   )r   argskwargsr)   r   r   r   r   auth_complete<   s0   


zBrowserIDAuth.auth_completeN)r"   r#   r$   r%   r   r7   r:   r   r   r   r   r'   8   s    r'   r   )r%   urllibr   jsonr   ImportErrordjango.utilsdjango.contrib.authr   social_auth.backendsr   r   social_auth.utilsr   r   social_auth.exceptionsr	   r
   r3   r   r'   BACKENDSr   r   r   r   <module>   s*    #