
    )Jf
                     6   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e	          Z G d de          Z G d dee          Z G 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                   H    e Zd Zej        ZdZdZdZdZ	e
d             Z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                     |                                                                  }|                    d| j                  }|S )NAUTHORIZE_URL)get_providerget_settingsgetauthorization_url)selfsettingsurls      o/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/allauth/socialaccount/providers/feishu/views.pyauthorize_urlz!FeishuOAuth2Adapter.authorize_url   s:    $$&&3355ll?D,BCC
    c                    t                                                                          | j        dd|j        z   d          }|                                 |                                }|d         dk    rt          d|j        z            |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_datas          r   complete_loginz"FeishuOAuth2Adapter.complete_login#   s    MM!!##S"$6%.%<     	 	YY[[
f""9DLHIII'
  ""<<WjQQQr   N)__name__
__module____qualname__r   idprovider_idr   access_token_urlapp_access_token_urlr"   propertyr   r-    r   r   r   r      se         #KJPM  KM  X
R R R R Rr   r   c                       e Zd Zd ZdS )FeishuOAuth2ClientMixinc           	      T   t          | j        j        dz             }| j        j        pt          j        }t          |||          }| j                                        }|                    |          }t          ||j
        |j        | j        j        | j        j        ||          }|S )N	_callback)protocol)r   adapterr2   redirect_uri_protocolr   DEFAULT_HTTP_PROTOCOLr
   r   	get_scoper   	client_idsecretaccess_token_methodr3   )r   r(   r)   callback_urlr;   providerscopeclients           r   
get_clientz"FeishuOAuth2ClientMixin.get_client9   s    t|7+EFFL.T,2T 	 *'<(SSS<,,..""7++#MJL,L)
 
 r   N)r.   r/   r0   rG   r6   r   r   r8   r8   8   s#            r   r8   c                       e Zd ZdS )FeishuOAuth2LoginViewNr.   r/   r0   r6   r   r   rI   rI   M           Dr   rI   c                       e Zd ZdS )FeishuOAuth2CallbackViewNrJ   r6   r   r   rM   rM   Q   rK   r   rM   N)django.urlsr   allauth.accountr   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r	   allauth.utilsr
   rF   r   rD   r   r   objectr8   rI   rM   adapter_viewoauth2_loginoauth2_callbackr6   r   r   <module>rX      s          ( ( ( ( ( ( 5 5 5 5 5 5 E E E E E E         
 - , , , , , & & & & & & $ $ $ $ $ $"R "R "R "R "R- "R "R "RJ    f   *	 	 	 	 	3_ 	 	 		 	 	 	 	68J 	 	 	 %112EFF*778KLLr   