o
    Lff                     @   s   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	 d dl
mZmZmZ dd ZG d	d
 d
eZeeZeeZdS )    )context)app_settings)get_adapter)GitLabProvider)OAuth2Error)OAuth2AdapterOAuth2CallbackViewOAuth2LoginViewc                 C   s   | j dkr| j}td| z|  }W n ty"   td| j w | j dks,d|v rI|ddp4| j }|ddp@|dd}td	||f d
|vrStd| |S )Ni  z Invalid data from GitLab API: %rz Invalid JSON from GitLab API: %ri  error error_descriptionmessagezGitLab error: %s (%s)id)status_codecontentr   json
ValueErrortextget)responsemsgdatar
   desc r   m/var/www/html/humari/django-venv/lib/python3.10/site-packages/allauth/socialaccount/providers/gitlab/views.py_check_errors   s   
r   c                   @   sN   e Zd ZejZdZdZdd Ze	dd Z
e	dd Ze	d	d
 Zdd ZdS )GitLabOAuth2Adapterzhttps://gitlab.comv4c                 C   sL   t j| ji }|d| j}t jtj| jd}|j	d|}| | S )N
GITLAB_URL)provider
gitlab_url)
r   	PROVIDERSr   provider_idprovider_default_urlr   get_appr   requestsettings)selfpathr&   r    appr   r   r   
_build_url1   s
   zGitLabOAuth2Adapter._build_urlc                 C   
   |  dS )Nz/oauth/tokenr*   r'   r   r   r   access_token_url9      
z$GitLabOAuth2Adapter.access_token_urlc                 C   r+   )Nz/oauth/authorizer,   r-   r   r   r   authorize_url=   r/   z!GitLabOAuth2Adapter.authorize_urlc                 C   s   |  d| j dS )Nz/api/z/user)r*   provider_api_versionr-   r   r   r   profile_urlA   s   zGitLabOAuth2Adapter.profile_urlc                 C   s4   t   j| jd|jid}t|}|  ||S )Naccess_token)params)r   get_requests_sessionr   r2   tokenr   get_providersociallogin_from_response)r'   r%   r)   r6   r   r   r   r   r   complete_loginE   s   z"GitLabOAuth2Adapter.complete_loginN)__name__
__module____qualname__r   r   r"   r#   r1   r*   propertyr.   r0   r2   r9   r   r   r   r   r   ,   s    


r   N)allauth.corer   allauth.socialaccountr   allauth.socialaccount.adapterr   /allauth.socialaccount.providers.gitlab.providerr   -allauth.socialaccount.providers.oauth2.clientr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r	   r   r   adapter_viewoauth2_loginoauth2_callbackr   r   r   r   <module>   s   
#