
    f#	                         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  G d	 d
e	      Z ej"                  e      Z e
j"                  e      Zy)    )reverse)app_settings)get_adapter)OAuth2Error)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView)build_absolute_uri   )FeishuOAuth2Clientc                   <    e Zd ZdZdZdZdZdZed        Z	d Z
d Zy	)
FeishuOAuth2Adapterfeishuz0https://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                 z    | j                         j                         }|j                  d| j                        }|S )NAUTHORIZE_URL)get_providerget_settingsgetauthorization_url)selfsettingsurls      g/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/socialaccount/providers/feishu/views.pyauthorize_urlz!FeishuOAuth2Adapter.authorize_url   s4    $$&335ll?D,B,BC
    c                 R   t               j                         j                  | j                  dd|j                  z   d      }|j                          |j                         }|d   dk7  rt        d|j                  z        |d   }| j                         j                  ||      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    M!!#S""$6%.%<   	 	YY[
f"9DLLHII'
  "<<WjQQr   c                     t        | j                  dz         }| j                  xs t        j                  }t        |||      }t        ||j                  |j                  | j                  | j                  |      }|S )N	_callback)protocol)r   provider_idredirect_uri_protocolr   DEFAULT_HTTP_PROTOCOLr
   r   	client_idsecretaccess_token_methodaccess_token_url)r   r(   r)   callback_urlr0   clients         r   
get_clientzFeishuOAuth2Adapter.get_client4   sr    t//+=>--S1S1S)'<(S#MMJJ$$!!
 r   N)__name__
__module____qualname__r1   r   r7   app_access_token_urlr"   propertyr   r-   r:    r   r   r   r      s@    KJPM  KM 
R(r   r   N)django.urlsr   allauth.accountr   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r	   allauth.utilsr
   r9   r   r   adapter_viewoauth2_loginoauth2_callbackr@   r   r   <module>rJ      sY     ( 5 E 
 - &0- 0f ,++,?@1$112EFr   