a
    Qx_;                     @   s\   d dl Z d dlmZ d dlmZ d dlmZmZmZ G dd deZ	e
e	Ze
e	ZdS )    N)app_settings)AmazonCognitoProvider)OAuth2AdapterOAuth2CallbackViewOAuth2LoginViewc                   @   sZ   e Zd ZejZdZedd Zedd Z	edd Z
edd	 Zed
d Zdd ZdS )AmazonCognitoOAuth2Adapterz8"DOMAIN" key is missing in Amazon Cognito configuration.c                 C   s   t j| ji S )N)r   Z	PROVIDERSgetprovider_idself r   l/var/www/html/Ranjet/env/lib/python3.9/site-packages/allauth/socialaccount/providers/amazon_cognito/views.pysettings   s    z#AmazonCognitoOAuth2Adapter.settingsc                 C   s"   | j d}|d u rt| j|S )NZDOMAIN)r   r   
ValueErrorDOMAIN_KEY_MISSING_ERROR)r   domainr   r   r   r      s    
z!AmazonCognitoOAuth2Adapter.domainc                 C   s   d | jS )Nz{}/oauth2/tokenformatr   r
   r   r   r   access_token_url"   s    z+AmazonCognitoOAuth2Adapter.access_token_urlc                 C   s   d | jS )Nz{}/oauth2/authorizer   r
   r   r   r   authorize_url&   s    z(AmazonCognitoOAuth2Adapter.authorize_urlc                 C   s   d | jS )Nz{}/oauth2/userInfor   r
   r   r   r   profile_url*   s    z&AmazonCognitoOAuth2Adapter.profile_urlc                 K   s:   dd |i}tj| j|d}|  |  || S )NZAuthorizationz	Bearer {})headers)r   requestsr   r   Zraise_for_statusget_providerZsociallogin_from_responsejson)r   requestZappZaccess_tokenkwargsr   
extra_datar   r   r   complete_login.   s
    
z)AmazonCognitoOAuth2Adapter.complete_loginN)__name__
__module____qualname__r   idr	   r   propertyr   r   r   r   r   r   r   r   r   r   r      s   




r   )r   Zallauth.socialaccountr   Z7allauth.socialaccount.providers.amazon_cognito.providerr   Z,allauth.socialaccount.providers.oauth2.viewsr   r   r   r   Zadapter_viewZoauth2_loginZoauth2_callbackr   r   r   r   <module>   s   *
