U
    >i2                     @   s`   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 deZ
ee
Zee
ZdS )    )get_adapter)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView)TikTokOAuth2Client)TikTokScopec                   @   s4   e Zd ZdZdZdZdZeZdZ	dd Z
dd	 Zd
S )TikTokOAuth2AdapterZtiktokz+https://open.tiktokapis.com/v2/oauth/token/z)https://www.tiktok.com/v2/auth/authorize/z)https://open.tiktokapis.com/v2/user/info/,c                 C   sP   g }t jj|   kr&|dddg7 }t jj|   krF|ddg7 }d|S )NZopen_idZdisplay_nameZ
avatar_urlusernameZprofile_deep_linkr	   )r   Zuser_info_basicvalueget_providerZ	get_scopeZuser_info_profilejoin)selffields r   P/tmp/pip-unpacked-wheel-upujnpc2/allauth/socialaccount/providers/tiktok/views.pyget_query_fields   s    z$TikTokOAuth2Adapter.get_query_fieldsc           
      K   sj   d|j  |jd}d|  i}t  j| j||d}|  | }|di d}	| 	 
||	S )NzBearer )Authorizationz	Client-IDr   )headersparamsdatauser)tokenZ	client_idr   r   Zget_requests_sessiongetprofile_urlraise_for_statusjsonr   Zsociallogin_from_response)
r   requestZappr   kwargsr   r   responser   Z	user_infor   r   r   complete_login   s    

  z"TikTokOAuth2Adapter.complete_loginN)__name__
__module____qualname__Zprovider_idZaccess_token_urlZauthorize_urlr   r   Zclient_classZscope_delimiterr   r    r   r   r   r   r      s   r   N)Zallauth.socialaccount.adapterr   Z,allauth.socialaccount.providers.oauth2.viewsr   r   r   Z-allauth.socialaccount.providers.tiktok.clientr   Z,allauth.socialaccount.providers.tiktok.scoper   r   Zadapter_viewZoauth2_loginZoauth2_callbackr   r   r   r   <module>   s   $
