o
    Lf
                     @   sP   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 G dd deZ
dS )    N)OrderedDict)	urlencode)get_adapter)OAuth2ClientOAuth2Errorc                   @   s*   e Zd ZdZdd Zdd Zd	ddZdS )
FeishuOAuth2ClientzChttps://open.feishu.cn/open-apis/auth/v3/app_access_token/internal/c                 C   s^   | j | j| jdd}| jr| j|d< || t }t|D ]}|| ||< qd|t|f S )Ncode)app_idredirect_uriscoperesponse_typestatez%s?%s)consumer_keycallback_urlr   r   updater   sortedr   )selfauthorization_urlextra_paramsparamssorted_paramsparam r   n/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/socialaccount/providers/feishu/client.pyget_redirect_url   s   

z#FeishuOAuth2Client.get_redirect_urlc                 C   sf   | j | jd}| | | j}t  jd||d}|  | }|r(d|vr/t	d|j
 |d S )N)r	   
app_secretPOST)dataapp_access_tokenz%Error retrieving app access token: %s)r   consumer_secret_strip_empty_keysapp_access_token_urlr   get_requests_sessionrequestraise_for_statusjsonr   content)r   r   urlrespaccess_tokenr   r   r   r   #   s   
z#FeishuOAuth2Client.app_access_tokenNc                 C   s   d||   d}d }| | | j}| jdkr|}d }|r#|r#||d< t  j| j||t|ddid}|	  | }|rJd|vsJd	|d vrQt
d
|j |d S )Nauthorization_code)
grant_typer   r   GETcode_verifierzContent-Typezapplication/json)r   r   headersr   r)   z!Error retrieving access token: %s)r   r    access_token_urlaccess_token_methodr   r"   r#   r%   dumpsr$   r   r&   )r   r   pkce_code_verifierr   r   r'   r(   r)   r   r   r   get_access_token4   s<   

z#FeishuOAuth2Client.get_access_token)N)__name__
__module____qualname__r!   r   r   r3   r   r   r   r   r      s    r   )r%   collectionsr   django.utils.httpr   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   r   r   r   r   r   r   <module>   s   