o
    h                     @   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 d dlmZ d dlmZ G d	d
 d
ZG dd de	ZG dd deZegZdS )    N)EmailAddress)get_adapter)QUERY_EMAIL)
AuthActionProviderAccount)GoogleOAuth2Adapter)OAuth2Error)OAuth2Providerc                   @   s   e Zd ZdZdZdS )ScopeemailprofileN)__name__
__module____qualname__EMAILPROFILE r   r   f/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/google/provider.pyr
      s    r
   c                   @   s    e Zd ZdZdd Zdd ZdS )GoogleAccounta  
    The account data can be in two formats. One, originating from
    the /v2/userinfo endpoint:

        {'email': 'john.doe@gmail.com',
         'given_name': 'John',
         'id': '12345678901234567890',
         'locale': 'en',
         'name': 'John',
         'picture': 'https://lh3.googleusercontent.com/a/code',
         'verified_email': True}

    The second, which is the payload of the id_token:

        {'at_hash': '-someHASH',
         'aud': '123-pqr.apps.googleusercontent.com',
         'azp': '123-pqr.apps.googleusercontent.com',
         'email': 'john.doe@gmail.com',
         'email_verified': True,
         'exp': 1707297277,
         'given_name': 'John',
         'iat': 1707293677,
         'iss': 'https://accounts.google.com',
         'locale': 'en',
         'name': 'John',
         'picture': 'https://lh3.googleusercontent.com/a/code',
         'sub': '12345678901234567890'}
    c                 C      | j jdS )Nlinkaccount
extra_datagetselfr   r   r   get_profile_url/      zGoogleAccount.get_profile_urlc                 C   r   )Npicturer   r   r   r   r   get_avatar_url2   r   zGoogleAccount.get_avatar_urlN)r   r   r   __doc__r   r    r   r   r   r   r      s    r   c                       sX   e Zd ZdZdZeZeZdZ	dd Z
 fddZdd	 Zd
d Zdd Zdd Z  ZS )GoogleProvidergoogleGoogleTc                 C   s   t jg}tr|t j |S )N)r
   r   r   appendr   )r   scoper   r   r   get_default_scope=   s   z GoogleProvider.get_default_scopec                    s$   t  ||}|tjkrd|d< |S )Nzselect_account consentprompt)superget_auth_params_from_requestr   REAUTHENTICATE)r   requestactionret	__class__r   r   r*   C   s   
z+GoogleProvider.get_auth_params_from_requestc                 C   s   d|v r|d S |d S )Nsubidr   r   datar   r   r   extract_uidI   s   zGoogleProvider.extract_uidc                 C   s    t |d|d|ddS )Nr   family_name
given_name)r   	last_name
first_name)dictr   r3   r   r   r   extract_common_fieldsN   s
   z$GoogleProvider.extract_common_fieldsc                 C   sB   g }| d}|rt| dp| d}|t||dd |S )Nr   email_verifiedverified_emailT)r   verifiedprimary)r   boolr%   r   )r   r4   r.   r   r>   r   r   r   extract_email_addressesU   s   
z&GoogleProvider.extract_email_addressesc              
   C   sx   ddl m} |d}|st dz
|j| j|d}W n ttj	fy3 } zt d|d }~ww | 
||}|S )Nr   )viewsid_tokeninvalid_token)app
credential)&allauth.socialaccount.providers.googlerB   r   r   validation_error_verify_and_decoderE   r   requestsRequestExceptionsociallogin_from_response)r   r,   tokenrB   rF   identity_dataeloginr   r   r   verify_token]   s   

zGoogleProvider.verify_token)r   r   r   r2   namer   account_classr   oauth2_adapter_classsupports_token_authenticationr'   r*   r5   r;   rA   rQ   __classcell__r   r   r/   r   r"   6   s    r"   )rJ   allauth.account.modelsr   allauth.socialaccount.adapterr   "allauth.socialaccount.app_settingsr   $allauth.socialaccount.providers.baser   r   ,allauth.socialaccount.providers.google.viewsr   -allauth.socialaccount.providers.oauth2.clientr   /allauth.socialaccount.providers.oauth2.providerr	   r
   r   r"   provider_classesr   r   r   r   <module>   s    %
7