o
    Lf
                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ ddlmZ dd	lmZ G d
d de	ZG dd deZG dd deeZG dd dee
ZeeZeeZdS )    )reverse)app_settings)get_adapter)OAuth2Error)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView)build_absolute_uri   )FeishuOAuth2Client)FeishuProviderc                   @   s6   e Zd ZejZdZdZdZdZ	e
dd Zdd Zd	S )
FeishuOAuth2Adapterz0https://open.feishu.cn/open-apis/authen/v1/indexz7https://open.feishu.cn/open-apis/authen/v1/access_tokenzChttps://open.feishu.cn/open-apis/auth/v3/app_access_token/internal/z4https://open.feishu.cn/open-apis/authen/v1/user_infoc                 C   s   |    }|d| j}|S )NAUTHORIZE_URL)get_providerget_settingsgetauthorization_url)selfsettingsurl r   m/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/socialaccount/providers/feishu/views.pyauthorize_url   s   z!FeishuOAuth2Adapter.authorize_urlc                 K   sd   t   j| jdd|j dd}|  | }|d dkr&td|j |d }| 	 
||S )	Nzapplication/jsonzBearer )zContent-TypeAuthorization)headerscoder   zError retrieving code: %sdata)r   get_requests_sessionr   user_info_urltokenraise_for_statusjsonr   contentr   sociallogin_from_response)r   requestappr   kwargsresp
extra_datar   r   r   complete_login#   s   z"FeishuOAuth2Adapter.complete_loginN)__name__
__module____qualname__r   idprovider_idr   access_token_urlapp_access_token_urlr   propertyr   r)   r   r   r   r   r      s    
r   c                   @   s   e Zd Zdd ZdS )FeishuOAuth2ClientMixinc                 C   sd   t | jjd }| jjptj}t|||d}| j }||}t	||j
|j| jj| jj||}|S )N	_callback)protocol)r   adapterr.   redirect_uri_protocolr   DEFAULT_HTTP_PROTOCOLr	   r   	get_scoper   	client_idsecretaccess_token_methodr/   )r   r$   r%   callback_urlr4   providerscopeclientr   r   r   
get_client9   s    

	z"FeishuOAuth2ClientMixin.get_clientN)r*   r+   r,   r@   r   r   r   r   r2   8   s    r2   c                   @      e Zd ZdS )FeishuOAuth2LoginViewNr*   r+   r,   r   r   r   r   rB   M       rB   c                   @   rA   )FeishuOAuth2CallbackViewNrC   r   r   r   r   rE   Q   rD   rE   N)django.urlsr   allauth.accountr   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r   allauth.utilsr	   r?   r   r=   r   r   objectr2   rB   rE   adapter_viewoauth2_loginoauth2_callbackr   r   r   r   <module>   s   %
