o
    h                     @   sT   d dl mZ d dlmZ d dlmZmZmZ G dd deZe	eZ
e	eZdS )    )app_settings)get_adapter)OAuth2AdapterOAuth2CallbackViewOAuth2LoginViewc                   @   s6   e Zd ZdZdZdZdZdZdd Zde	fd	d
Z
dS )BitbucketOAuth2Adapterbitbucket_oauth2z.https://bitbucket.org/site/oauth2/access_tokenz+https://bitbucket.org/site/oauth2/authorizez"https://api.bitbucket.org/2.0/userz)https://api.bitbucket.org/2.0/user/emailsc                 K   sP   t   j| jd|jid}| }tjr | | }r ||d< | 	 
||S )Naccess_tokenparamsemail)r   get_requests_sessiongetprofile_urltokenjsonr   QUERY_EMAIL	get_emailget_providersociallogin_from_response)selfrequestappr   kwargsresp
extra_datar    r   m/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/bitbucket_oauth2/views.pycomplete_login   s   z%BitbucketOAuth2Adapter.complete_loginreturnc              
   C   s|   t   j| jd|jid}| dg }d}z|d d}dd |D }|d d}W |S  tttfy=   Y |S w )	z-Fetches email address from email API endpointr	   r
   values r   r   c                 S   s   g | ]
}| d dr|qS )
is_primaryF)r   ).0er   r   r   
<listcomp>(   s    z4BitbucketOAuth2Adapter.get_email.<locals>.<listcomp>)	r   r   r   
emails_urlr   r   
IndexError	TypeErrorKeyError)r   r   r   emailsr   primary_emailsr   r   r   r      s    z BitbucketOAuth2Adapter.get_emailN)__name__
__module____qualname__provider_idaccess_token_urlauthorize_urlr   r&   r   strr   r   r   r   r   r   
   s    r   N)allauth.socialaccountr   allauth.socialaccount.adapterr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r   r   adapter_viewoauth_loginoauth_callbackr   r   r   r   <module>   s    
%