o
    &zhs                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZmZ e eZG d
d dZG dd dZG dd deeZG dd deZdS )    N)reverselogin_not_required)get_adapter)complete_social_loginrender_authentication_error)SocialLoginSocialToken)	AuthError)BaseLoginView)OAuthClient
OAuthErrorc                   @   s2   e Zd ZeZdd Zdd Zdd Zd
dd	ZdS )OAuthAdapterc                 C   s
   || _ d S N)request)selfr    r   f/var/www/html/kangema/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/oauth/views.py__init__   s   
zOAuthAdapter.__init__c                 C   s   t )z0
        Returns a SocialLogin instance
        )NotImplementedError)r   r   appr   r   r   complete_login   s   zOAuthAdapter.complete_loginc                 C   s(   t | j}|j| j| jd}|| jS )N)provider)r   r   get_appprovider_idget_provider)r   adapterr   r   r   r   r       s   
zOAuthAdapter.get_providerNc              
   C   sJ   |   }|j}i }|rd||d< | j||j|j| j| j|||d}|S )N scope)
parametersr   )r   r   joinclient_class	client_idsecretrequest_token_urlaccess_token_url)r   r   callback_urlr   r   r   r   clientr   r   r   _get_client%   s    
zOAuthAdapter._get_clientr   )	__name__
__module____qualname__r   r!   r   r   r   r(   r   r   r   r   r      s    r   c                   @   s   e Zd Zedd ZdS )	OAuthViewc                    s   t  fdd}|S )Nc                    s.    }| |_  | |_|j| g|R i |S r   )r   r   dispatch)r   argskwargsr   r   clsr   r   view;   s   
z$OAuthView.adapter_view.<locals>.viewr   )r1   r   r2   r   r0   r   adapter_view9   s   zOAuthView.adapter_viewN)r)   r*   r+   classmethodr3   r   r   r   r   r,   8   s    r,   c                   @      e Zd Zdd ZdS )OAuthLoginViewc                 C   s   | j  }|S r   )r   r   )r   r   r   r   r   r   F   s   
zOAuthLoginView.get_providerN)r)   r*   r+   r   r   r   r   r   r6   E       r6   c                   @   r5   )OAuthCallbackViewc              
   C   s   | j  }t| j jd }| j ||}| s/d|jv r!tj}ntj	}t
||||| ddS |j}z/| }t|d |ddd}|jrI||_| j j||||d	}	||	_t||	_t||	W S  tyz }
 zt
|||
d
W  Y d}
~
S d}
~
ww )z
        View to handle final steps of OAuth based authentication where the user
        gets redirected back to from the service provider
        	_callbackdenied)oauth_clientcallback_view)errorextra_contextoauth_tokenoauth_token_secret )tokentoken_secret)response)	exceptionN)r   r   r   r   r(   is_validGETr
   	CANCELLEDUNKNOWNr   r   get_access_tokenr	   getpkr   rB   r   unstash_statestater   r   )r   r   r   login_done_urlr'   r=   r   access_tokenrB   loginer   r   r   r-   L   sD   

	
zOAuthCallbackView.dispatchN)r)   r*   r+   r-   r   r   r   r   r8   K   r7   r8   )loggingdjango.urlsr   #allauth.account.internal.decoratorsr   allauth.socialaccount.adapterr   allauth.socialaccount.helpersr   r   allauth.socialaccount.modelsr   r	   .allauth.socialaccount.providers.base.constantsr
   *allauth.socialaccount.providers.base.viewsr   ,allauth.socialaccount.providers.oauth.clientr   r   	getLoggerr)   loggerr   r,   r6   r8   r   r   r   r   <module>   s    
$