o
    gëfe  ã                   @   sÜ   d Z ddlmZ zddlZW n ey-   zddlZW n ey*   ddlmZ Y nw Y nw ddlmZ ddl	m
Z
 ddl	mZ ddlmZ d	Zd
e Zd
e Zde Zde ZG dd„ deƒZG dd„ de
ƒZdeiZdS )aŸ  
Dailymotion OAuth2 support.

This adds support for Dailymotion OAuth service. An application must
be registered first on dailymotion and the settings DAILYMOTION_CONSUMER_KEY
and DAILYMOTION_CONSUMER_SECRET must be defined with the corresponding
values.

User screen name is used to generate username.

By default account id is stored in extra_data field, check OAuthBackend
class for details on how to extend it.
é    )Ú	HTTPErrorN)Ú
simplejson)Údsa_urlopen)Ú
BaseOAuth2)ÚSocialAuthBackend)ÚAuthCanceledzapi.dailymotion.comzhttps://%s/oauth/tokenzhttps://%s/oauth/authorizezhttps://%s/me/?access_token=c                   @   s*   e Zd ZdZdZdgZdd„ Zdd„ ZdS )	ÚDailymotionBackendz(Dailymotion OAuth authentication backendÚdailymotion)Úidr
   c                 C   s   |d S )z%Use dailymotion username as unique idÚusername© )ÚselfÚdetailsÚresponser   r   úi/var/www/html/humari/django-venv/lib/python3.10/site-packages/social_auth/backends/contrib/dailymotion.pyÚget_user_id.   s   zDailymotionBackend.get_user_idc                 C   s   d|d iS )Nr   Ú
screennamer   )r   r   r   r   r   Úget_user_details2   s   z#DailymotionBackend.get_user_detailsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚ
EXTRA_DATAr   r   r   r   r   r   r   )   s    r   c                       sJ   e Zd ZdZeZeZeZ	e
ZdZdZdd„ Z‡ fdd„Zdd	d
„Z‡  ZS )ÚDailymotionAuthz+Dailymotion OAuth2 authentication mechanismÚDAILYMOTION_OAUTH2_KEYÚDAILYMOTION_OAUTH2_SECRETc              	   O   s6   zt t| ƒ ¡ }t |¡W S  ttfy   Y dS w )zReturn user data providedN)r   ÚDAILYMOTION_CHECK_AUTHÚreadr   ÚloadsÚ
ValueErrorr   )r   Úaccess_tokenÚargsÚkwargsÚdatar   r   r   Ú	user_data@   s   ÿzDailymotionAuth.user_datac                    s(   d| j v r	t| ƒ‚tt| ƒj|i |¤ŽS )z2Completes login process, must return user instanceÚdenied)r$   r   Úsuperr   Úauth_complete)r   r"   r#   ©Ú	__class__r   r   r(   H   s   
zDailymotionAuth.auth_completeNc                 C   s   |pi }|S ©Nr   )r   ÚtokenÚurlÚextra_paramsr   r   r   Úoauth_requestO   s   zDailymotionAuth.oauth_requestr+   )r   r   r   r   ÚDAILYMOTION_AUTHORIZATION_URLÚAUTHORIZATION_URLÚDAILYMOTION_REQUEST_TOKEN_URLÚREQUEST_TOKEN_URLÚDAILYMOTION_ACCESS_TOKEN_URLÚACCESS_TOKEN_URLr   ÚAUTH_BACKENDÚSETTINGS_KEY_NAMEÚSETTINGS_SECRET_NAMEr%   r(   r/   Ú__classcell__r   r   r)   r   r   6   s    r   r	   )r   Úurllib2r   Újsonr   ÚImportErrorÚdjango.utilsÚsocial_auth.utilsr   Úsocial_auth.backendsr   r   Úsocial_auth.exceptionsr   ÚDAILYMOTION_SERVERr2   r4   r0   r   r   r   ÚBACKENDSr   r   r   r   Ú<module>   s6    ÿ€ýÿ ÿ