U
    Z!ct                     @   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   ZQUERY_EMAIL	get_emailget_providerZsociallogin_from_response)selfrequestZappr   kwargsresp
extra_data r   z/var/www/html/crackeverytest/cet_env/lib/python3.8/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}dzVz.|d d}dd	 |D }|d d}W n" tttfk
r~   Y W  dS X W 5 |  S X  )
z-Fetches email address from email API endpointr	   r
   values Nr   r   c                 S   s   g | ]}| d dr|qS )Z
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   Zemailsr   Zprimary_emailsr   r   r   r      s    z BitbucketOAuth2Adapter.get_emailN)__name__
__module____qualname__r   idZprovider_idZaccess_token_urlZauthorize_urlr   r!   r   r   r   r   r   r   r      s   r   )r   Zallauth.socialaccountr   Z,allauth.socialaccount.providers.oauth2.viewsr   r   r   Zproviderr   r   Zadapter_viewZoauth_loginZoauth_callbackr   r   r   r   <module>   s   
