o
    &zh}                     @   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 d dl	m
Z
 d dlmZ d dlmZ G d	d
 d
e
ZG dd deZegZdS )    N)EmailAddress)get_adapter)QUERY_EMAILAppleOAuth2Adapter)ProviderAccount)OAuth2Error)OAuth2Providerc                       s   e Zd Z fddZ  ZS )AppleAccountc                    s   | j jd}|r| ds|S | j jdpi }|ds%|dr<|d p*d d|d p1d }| }|r<|S t  S )Nemailz@privaterelay.appleid.comname	firstNamelastName  )account
extra_datagetlowerendswithstripsuperto_str)selfr   r   	full_name	__class__ i/var/www/html/kangema/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/apple/provider.pyr      s   
zAppleAccount.to_str)__name__
__module____qualname__r   __classcell__r   r   r   r   r
      s    r
   c                   @   sP   e Zd ZdZdZeZeZdZ	dd Z
dd Zdd	 Zd
d Zdd Zdd ZdS )AppleProviderappleAppleTc                 C   s   t |d S )Nsub)str)r   datar   r   r   extract_uid#   s   zAppleProvider.extract_uidc                 C   s@   d| di}| d}|r| dd|d< | dd|d< |S )Nr   r   r   r   
first_namer   	last_name)r   )r   r(   fieldsr   r   r   r   extract_common_fields&   s   
z#AppleProvider.extract_common_fieldsc                 C   sJ   g }| d}| d}t|tr| dk}|r#|t||dd |S )Nr   email_verifiedtrueT)r   verifiedprimary)r   
isinstancer'   r   appendr   )r   r(   retr   r0   r   r   r   extract_email_addresses1   s   


z%AppleProvider.extract_email_addressesc                 C   s   dg}t r
|d |S )Nr   r   )r   r3   )r   scopesr   r   r   get_default_scopeA   s   
zAppleProvider.get_default_scopec              
   C   st   ddl m} |d}|st dz|| |}W n ttjfy1 } zt d|d }~ww | 	||}|S )Nr   r   id_tokeninvalid_token)
+allauth.socialaccount.providers.apple.viewsr   r   r   validation_errorget_verified_identity_datar   requestsRequestExceptionsociallogin_from_response)r   requesttokenr   r8   identity_dataeloginr   r   r   verify_tokenG   s   
zAppleProvider.verify_tokenc                 C   s   dd | j jdD S )Nc                 S   s   g | ]}|  qS r   )r   ).0audr   r   r   
<listcomp>W   s    z*AppleProvider.get_auds.<locals>.<listcomp>,)app	client_idsplit)r   r   r   r   get_audsV   s   zAppleProvider.get_audsN)r   r    r!   idr   r
   account_classr   oauth2_adapter_classsupports_token_authenticationr)   r-   r5   r7   rE   rM   r   r   r   r   r#      s    r#   )r=   allauth.account.modelsr   allauth.socialaccount.adapterr   "allauth.socialaccount.app_settingsr   r:   r   $allauth.socialaccount.providers.baser   -allauth.socialaccount.providers.oauth2.clientr   /allauth.socialaccount.providers.oauth2.providerr	   r
   r#   provider_classesr   r   r   r   <module>   s    
>