o
    gf                     @   s   d dl Z d dlmZmZ d dlmZ zd dlZW n ey7   zd dlZW n ey4   d dl	mZ Y nw Y nw d dl
mZmZ d dlmZ d dlmZ G dd	 d	eZG d
d deZdeiZdS )    N)Request	HTTPError)	urlencode)
simplejson)
BaseOAuth2OAuthBackend)dsa_urlopen)AuthTokenErrorc                   @   s(   e Zd ZdZdZddgZdZdd ZdS )	AmazonBackendz$Amazon OAuth2 authentication backendamazon)user_idr   )postal_coder   r   c                 C   sT   | dpd}d}d}|rd|v r| ddd\}}n|}|| d|||dS )z'Return user details from amazon accountname     email)usernamer   fullname
first_name	last_name)getsplit)selfresponser   r   r    r   \/var/www/html/humari/django-venv/lib/python3.10/site-packages/social_auth/backends/amazon.pyget_user_details   s   zAmazonBackend.get_user_detailsN)__name__
__module____qualname____doc__r   
EXTRA_DATAID_KEYr   r   r   r   r   r
      s    r
   c                   @   sR   e Zd ZdZdZeZdZdZdZ	dZ
dZdgZed	d
 Zdd Zedd ZdS )
AmazonAuthzAmazon OAuth2 supportFzhttp://www.amazon.com/ap/oaz$https://api.amazon.com/auth/o2/tokenAMAZON_APP_IDAMAZON_API_SECRETAMAZON_EXTENDED_PERMISSIONSprofilec                 C   s<   |  |}||d< t| jt||  d}| t| S )Nredirect_uri)dataheaders)refresh_token_paramsr   ACCESS_TOKEN_URLr   auth_headersprocess_refresh_token_responser   read)clstokenr)   r*   requestr   r   r   refresh_token7   s   
zAmazonAuth.refresh_tokenc                 O   sx   d| }zt tt|}W n ty   Y dS  ty#   t| w d|v r:|d d |d d |d d d}|S )z*Grab user profile information from amazon.z6https://www.amazon.com/ap/user/profile?access_token=%sNProfile
CustomerIdNamePrimaryEmail)r   r   r   )r   loadr   r   
ValueErrorr   r	   )r   access_tokenargskwargsurlr   r   r   r   	user_data@   s    


zAmazonAuth.user_datac                 C   s   ddt d|    iS )NAuthorizationzBasic %sz%s:%s)base64urlsafe_b64encodeget_key_and_secret)r1   r   r   r   r.   S   s   
zAmazonAuth.auth_headersN)r   r   r    r!   REDIRECT_STATEr
   AUTH_BACKENDAUTHORIZATION_URLr-   SETTINGS_KEY_NAMESETTINGS_SECRET_NAMESCOPE_VAR_NAMEDEFAULT_SCOPEclassmethodr4   r?   r.   r   r   r   r   r$   ,   s    
r$   r   )rA   urllib2r   r   urllibr   jsonr   ImportErrordjango.utilssocial_auth.backendsr   r   social_auth.utilsr   social_auth.exceptionsr	   r
   r$   BACKENDSr   r   r   r   <module>   s(    1