o
    ˷e                     @   s\   d dl Z d dlmZ d dlmZmZmZ ddlmZ G dd deZ	e
e	Ze
e	ZdS )    N)OAuth2Error)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView   )TwitchProviderc                   @   s&   e Zd ZejZdZdZdZdd Z	dS )TwitchOAuth2Adapterz!https://id.twitch.tv/oauth2/tokenz%https://id.twitch.tv/oauth2/authorizez!https://api.twitch.tv/helix/usersc                 K   s   d |j|jd}tj| j|d}| }|jdkr/|dd}|dd}	td||	f z
|d	g d
 }
W n t	yF   td| w d|
vrQtd|
 | 
 ||
S )Nz	Bearer {})Authorizationz	Client-ID)headersi  error messagezTwitch API Error: %s (%s)datar   z Invalid data from Twitch API: %sid)formattoken	client_idrequestsgetprofile_urljsonstatus_coder   
IndexErrorget_providersociallogin_from_response)selfrequestappr   kwargsr
   responser   r   r   	user_info r!   c/var/www/ideatree/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/twitch/views.pycomplete_login   s"   

z"TwitchOAuth2Adapter.complete_loginN)
__name__
__module____qualname__r   r   provider_idaccess_token_urlauthorize_urlr   r#   r!   r!   r!   r"   r      s    r   )r   -allauth.socialaccount.providers.oauth2.clientr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r   providerr   r   adapter_viewoauth2_loginoauth2_callbackr!   r!   r!   r"   <module>   s    
