o
    ˷et                     @   s\   d dl Z d dlmZ d dlmZmZmZ ddlmZ G dd deZ	e
e	Ze
e	ZdS )    N)app_settings)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView   )BitbucketOAuth2Providerc                   @   s2   e Zd ZejZdZdZdZdZ	dd Z
dd Zd	S )
BitbucketOAuth2Adapterz.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   sL   t j| jd|jid}| }tjr|ds| ||d< |  	||S )Naccess_tokenparamsemail)
requestsgetprofile_urltokenjsonr   QUERY_EMAIL	get_emailget_providersociallogin_from_response)selfrequestappr   kwargsresp
extra_data r   m/var/www/ideatree/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/bitbucket_oauth2/views.pycomplete_login   s
   z%BitbucketOAuth2Adapter.complete_loginc              
   C   s   t j| jd|jid}| dg }d}z(z|d d}dd |D }|d d}W W |S  tttfy=   Y W |S w |     Y S )	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   
emails_urlr   r   
IndexError	TypeErrorKeyError)r   r   r   emailsr   primary_emailsr   r   r   r      s   z BitbucketOAuth2Adapter.get_emailN)__name__
__module____qualname__r   idprovider_idaccess_token_urlauthorize_urlr   r%   r   r   r   r   r   r   r      s    r   )r   allauth.socialaccountr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r   providerr   r   adapter_viewoauth_loginoauth_callbackr   r   r   r   <module>   s    
