o
    Lf                     @   sT   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
 G dd de	ZdS )	    )HTTPBasicAuth)	parse_qsl)	urlencode)get_adapter)OAuth2ClientOAuth2Errorc                   @   s   e Zd Zdd ZdddZdS )NotionOAuth2Clientc                 C   s2   | j | jddd}| jr| j|d< d|t|f S )Ncodeuser)	client_idscoperesponse_typeownerstatez%s?%s)consumer_keyr   r   r   )selfauthorization_urlextra_paramsparams r   n/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/socialaccount/providers/notion/client.pyget_redirect_url   s   
z#NotionOAuth2Client.get_redirect_urlNc                 C   s   t   j| j| jt| j| j|dd| jd}d }|j	dv r6z|
 }W n ty5   tt|j}Y nw |r<d|vrCtd|j |S )Nauthorization_code)r	   
grant_type)authjsonheaders)      access_tokenz!Error retrieving access token: %s)r   get_requests_sessionrequestaccess_token_methodaccess_token_urlr   r   consumer_secretr   status_coder   
ValueErrordictr   textr   content)r   r	   pkce_code_verifierrespr   r   r   r   get_access_token   s(   
z#NotionOAuth2Client.get_access_token)N)__name__
__module____qualname__r   r,   r   r   r   r   r      s    r   N)requests.authr   urllib.parser   django.utils.httpr   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   r   r   r   r   r   r   <module>   s    