U
    ZcL
                     @   sL   d dl Z d dl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)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_idZredirect_uriscopeZresponse_typestatez%s?%s)consumer_keyZcallback_urlr	   r
   updater   sortedr   )selfZauthorization_urlZextra_paramsparamsZsorted_paramsparam r   q/var/www/html/crackeverytest/cet_env/lib/python3.8/site-packages/allauth/socialaccount/providers/feishu/client.pyget_redirect_url   s    

z#FeishuOAuth2Client.get_redirect_urlc                 C   s`   | j | jd}| | | j}tjd||d}|  | }|rJd|krXtd|j	 |d S )N)r   Z
app_secretZPOST)dataapp_access_tokenz%Error retrieving app access token: %s)
r   Zconsumer_secret_strip_empty_keysapp_access_token_urlrequests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r6|}d }|rF|rF||d< tj| j||t|ddid}|  | }|rd|ksd	|d krt	d
|j
 |d S )NZauthorization_code)Z
grant_typer   r   GETZcode_verifierzContent-Typezapplication/json)r   r   headersr   r   z!Error retrieving access token: %s)r   r   Zaccess_token_urlZaccess_token_methodr   r   r   dumpsr   r   r   )r   r   Zpkce_code_verifierr   r   r   r   r   r   r   r   get_access_token5   s:    


z#FeishuOAuth2Client.get_access_token)N)__name__
__module____qualname__r   r   r   r#   r   r   r   r   r      s
   r   )
r   r   collectionsr   Zdjango.utils.httpr   Z-allauth.socialaccount.providers.oauth2.clientr   r   r   r   r   r   r   <module>   s
   