U
    >i                     @   s`   d dl m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 )    )app_settings)get_adapter)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView)get_request_paramc                   @   sX   e Zd ZdZejei ZeddZd	eZ
d	eZd	eZdd Zd	d
 ZdS )MailcowAdapterZmailcowZSERVERzhttps://hosted.mailcow.dez{0}/oauth/tokenz{0}/oauth/authorizez{0}/oauth/profilec                 K   s(   t |d}| |j|}|  ||S )Ncode)r   get_user_infotokenget_providerZsociallogin_from_response)selfrequestZappr   kwargsr	   
extra_data r   Q/tmp/pip-unpacked-wheel-upujnpc2/allauth/socialaccount/providers/mailcow/views.pycomplete_login   s    
zMailcowAdapter.complete_loginc                 C   s,   t   j| j||dd}|  | S )N)access_tokenr	   )params)r   Zget_requests_sessiongetprofile_urlraise_for_statusjson)r   r   r	   respr   r   r   r
      s    
 zMailcowAdapter.get_user_infoN)__name__
__module____qualname__Zprovider_idr   Z	PROVIDERSr   settingsserverformatZaccess_token_urlZauthorize_urlr   r   r
   r   r   r   r   r      s   


r   N)Zallauth.socialaccountr   Zallauth.socialaccount.adapterr   Z,allauth.socialaccount.providers.oauth2.viewsr   r   r   Zallauth.utilsr   r   Zadapter_viewZoauth2_loginZoauth2_callbackr   r   r   r   <module>   s   
