
    Uњh                         S r SSKJrJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SSKJrJr  S	 r " S
 S\5      r " S S5      r " S S5      rg)z
Parts derived from socialregistration and authorized by: alen, pinda
Inspired by:
    http://github.com/leah/python-oauth/blob/master/oauth/example/client.py
    http://github.com/facebook/tornado/blob/master/tornado/auth.py
    )	parse_qslurlparse)HttpResponseRedirect)	urlencode)gettext)get_adapter)OAuth1)build_absolute_uriget_request_paramc                 ,    [        U 5      R                  $ )z
Returns a prefix for the token to store in the session so we can hold
more than one single oauth provider's access key in the session.

Example:

    The request token url ``http://twitter.com/oauth/request_token``
    returns ``twitter.com``

)r   netloc)urls    gD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/socialaccount/providers/oauth/client.pyget_token_prefixr      s     C=    c                       \ rS rSrSrg)
OAuthError!    N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r   !   s    r   r   c                   @    \ rS rSr  S
S jrS rS rS rS rS r	S	r
g)OAuthClient%   Nc	                     Xl         X@l        XPl        X l        X0l        Xpl        X`l        Xl        / U l        S U l	        S U l
        g N)requestrequest_token_urlaccess_token_urlconsumer_keyconsumer_secret
parameterscallback_urlprovidererrorsrequest_tokenaccess_token)	selfr    r#   r$   r!   r"   r&   r%   r'   s	            r   __init__OAuthClient.__init__&   sH     !2 0(.$( ! r   c                    U R                   GcQ  0 nU R                  (       a  UR                  U R                  5        [        U R                  U R
                  5      US'   U R                  S-   [        U5      -   n[        U R                  U R                  S9n[        5       R                  5       R                  X#S9nUR                  S;  a6  [        [!        S5      [#        U R                  5      UR$                  4-  5      e['        [)        UR$                  5      5      U l         U R                   U R                  R*                  S[#        U R                  5      -  '   U R                   $ )zr
Obtain a temporary request token to authorize an access token and to
sign the request to obtain the access token
oauth_callback?)client_secretr   auth      zKInvalid response while obtaining request token from "%s". Response was: %s.oauth_%s_request_token)r)   r%   updater
   r    r&   r!   r   r	   r#   r$   r   get_requests_sessionpoststatus_coder   _r   textdictr   session)r+   
get_paramsrt_urloauthresponses        r   _get_request_tokenOAuthClient._get_request_tokenB   s?   
 %J!!$//2+=d//,J'( ++c1Ij4IIF4,,D<P<PQE"}99;@@V@XH##:5 8 ((>(>?O	P  "&i&>!?D "" LL  (+;D<R<R+SS !!!r   c                    U R                   Gc-  U R                  5       n[        U R                  U R                  US   US   S9nU R
                  n[        U R                  S5      nU(       a  US-   [        SU05      -   n[        5       R                  5       R                  X2S9nUR                  S;  a*  [        [        S5      [        U R                   5      -  5      e[#        [%        UR&                  5      5      U l         U R                   U R                  R(                  S	[        U R                   5      -  '   U R                   $ )
zJ
Obtain the access token to access private resources at the API
endpoint.
oauth_tokenoauth_token_secretr1   resource_owner_keyresource_owner_secretoauth_verifierr0   r2   r4   z8Invalid response while obtaining access token from "%s".oauth_%s_access_token)r*   _get_rt_from_sessionr	   r#   r$   r"   r   r    r   r   r9   r:   r;   r   r<   r   r!   r>   r   r=   r?   )r+   r)   rB   at_urlrL   rC   s         r   get_access_tokenOAuthClient.get_access_token_   s5   
 $ 557M!!"22#0#?&34H&I	E **F /t||=MNN#	3C^2T(UU"}99;@@V@XH##:5 ST&t'='=>?  !%Yx}}%= >D !! LL  '*:4;Q;Q*RR    r   c                      U R                   R                  S[        U R                  5      -     $ ! [         a+    [        [        S5      [        U R                  5      -  5      ef = f)zK
Returns the request token cached in the session by
``_get_request_token``
r7   z No request token saved for "%s".r    r?   r   r!   KeyErrorr   r<   r+   s    r   rN    OAuthClient._get_rt_from_session   sl    
	<<''(+;D<R<R+SS   	45"4#9#9:; 		   .1 5A&c                      U R                  5         U R                  5         g! [         a2  nU R                  R	                  UR
                  S   5         S nAgS nAff = f)Nr   FT)rN   rP   r   r(   appendargs)r+   es     r   is_validOAuthClient.is_valid   sS    	%%'!!#   	KKqvvay)	s    # 
A(AAc                     U R                  5       nUS   U R                  R                  U R                  5      S.nUR	                  U5        US-   [        U5      -   n[        U5      $ )zu
Returns a ``HttpResponseRedirect`` object to redirect the user
to the URL the OAuth provider handles authorization.
rG   )rG   r/   r0   )rD   r    r
   r&   r8   r   r   )r+   authorization_urlextra_paramsr)   paramsr   s         r   get_redirectOAuthClient.get_redirect   sf    
 //1(7"ll==d>O>OP
 	l##%	&(99#C((r   )r*   r"   r&   r#   r$   r(   r%   r'   r    r)   r!   )NN)r   r   r   r   r,   rD   rP   rN   r\   rb   r   r   r   r   r   r   %   s)     !8":!B)r   r   c                   .    \ rS rSrSrS rS rSS jrSrg)	OAuth   z
Base class to perform oauth signed requests from access keys saved
in a user's session. See the ``OAuthTwitter`` class below for an
example.
c                 4    Xl         X l        X0l        X@l        g r   )r    r#   
secret_keyr!   )r+   r    r#   rh   r!   s        r   r,   OAuth.__init__   s    ($!2r   c                      U R                   R                  S[        U R                  5      -     $ ! [         a+    [        [        S5      [        U R                  5      -  5      ef = f)zD
Get the saved access token for private resources from the session.
rM   zNo access token saved for "%s".rS   rU   s    r   _get_at_from_sessionOAuth._get_at_from_session   sl    	<<'''*:4;Q;Q*RR   	34"4#9#9:; 	rW   Nc                 P   U R                  5       n[        U R                  U R                  US   US   S9n[	        [        5       R                  5       UR                  5       5      " XXCS9nUR                  S:w  a*  [        [        S5      [        U R                  5      -  5      eU$ )zV
Request a API endpoint at ``url`` with ``params`` being either the
POST or GET data.
rG   rH   rI   )r3   headersra   r5   z'No access to private resources at "%s".)rk   r	   r#   rh   getattrr   r9   lowerr;   r   r<   r   r!   )r+   r   methodra   rn   r*   rB   rC   s           r   queryOAuth.query   s    
 002//+M:"./C"D	
 ;===?PW
 3&;<"4#9#9:; 
 r   )r#   r    r!   rh   )GETNN)	r   r   r   r   __doc__r,   rk   rr   r   r   r   r   re   re      s    3r   re   N)ru   urllib.parser   r   django.httpr   django.utils.httpr   django.utils.translationr   r<   allauth.socialaccount.adapterr   1allauth.socialaccount.providers.oauth.oauth1_authr	   allauth.utilsr
   r   r   	Exceptionr   r   re   r   r   r   <module>r~      sI    - , ' 1 5 D ? 	 	) )D0 0r   