K i[ddlZddlmZmZmZmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZmZdd lmZmZmZ dd lmZGd d eeZGd deZGddeeZGddeZGddeeZGddeZ GddeZ!GddeeZ"GddeeZ#GddeZ$Gdd eZ%Gd!d"eeZ&Gd#d$e&Z'Gd%d&e&Z(Gd'd(e&Z)Gd)d*e&Z*Gd+d,eZ+Gd-d.eZ,Gd/d0eZ-Gd1d2eZ.Gd3d4eeZ/Gd5d6eZ0Gd7d8eZ1Gd9d:eZ2Gd;dv..rc#K|jddr@|j|jd}| td|j |y|j |jdyw)N oauth_tokenr"r#r$)r%r&r'r(r)authorize_redirectrr+s rr-zOAuth1ClientLoginHandler.getAsz   ]D 144 MM-85D|// KK  %%$-- 2N%OOsA5A7c|jddr td|tddk7rtd|ztdS) Nfail_in_get_userzfailing in get_useruiop5678rKzincorrect access token %rfoo@example.com)email)r%r(rO)r access_tokens r_oauth_get_user_futurez/OAuth1ClientLoginHandler._oauth_get_user_futureMsK   / 612 2 4F6: :7,FG G+,,rN) r/r0r1rrPr r2r-r]r3rrr=r=7s?S / ]] P P ]]--rr=c4eZdZdZej dZy)!OAuth1ClientLoginCoroutineHandlerzDReplaces OAuth1ClientLoginCoroutineHandler's get() with a coroutine.c#K|jddr |jy|j y#t$r/}|jd|j d|zYd}~yd}~wwxYww)NrSzgot exception: %s)r%r&r( set_statusr8rT)res rr-z%OAuth1ClientLoginCoroutineHandler.getYsm   ]D 1 41133 ))+ +  4$ .233 4s+A7<A7 A4%A/*A7/A44A7N)r/r0r1__doc__r r2r-r3rrr_r_VsN]] , ,rr_ceZdZdZdZdZy)$OAuth1ClientRequestParametersHandlerc||_yN)rB)rrFs rrz/OAuth1ClientRequestParametersHandler.initializehs %rctddSrHrNr9s rrPz:OAuth1ClientRequestParametersHandler._oauth_consumer_tokenkrQrcx|jdtddtd}|j|y)Nzhttp://www.example.com/api/asdfrXrYrKbar)foo) parameters)_oauth_request_parametersrOr8)rparamss rr-z(OAuth1ClientRequestParametersHandler.getns9// - VF +0  6rN)r/r0r1rrPr-r3rrrfrfgs&/rrfceZdZdZy)OAuth1ServerRequestTokenHandlerc&|jdy)Nz(oauth_token=zxcv&oauth_token_secret=1234r8r9s rr-z#OAuth1ServerRequestTokenHandler.getx =>rNr/r0r1r-r3rrrqrqw?rrqceZdZdZy)OAuth1ServerAccessTokenHandlerc&|jdy)Nz(oauth_token=uiop&oauth_token_secret=5678rsr9s rr-z"OAuth1ServerAccessTokenHandler.get}rtrNrur3rrrxrx|rvrrxceZdZdZdZy)OAuth2ClientLoginHandlerc0|jd|_y)Nz/oauth2/server/authorize)rrDrs rrz#OAuth2ClientLoginHandler.initializes$(LL1K$L!rc,|j}|Jyrh)rT)rr,s rr-zOAuth2ClientLoginHandler.gets%%'{{rN)r/r0r1rr-r3rrr{r{s Mrr{c6eZdZdZej dZy)FacebookClientLoginHandlerc|jd|_|jd|_|jd|_y)Nz/facebook/server/authorize/facebook/server/access_tokenz/facebook/server)rrDrE_FACEBOOK_BASE_URLrs rrz%FacebookClientLoginHandler.initializes8$(LL1M$N!'+||4S'T$"&,,/A"Brc#zK|jddrj|j|jj|jd|jd|jd}|j |y|j |jj|jdddiyw)Ncodefacebook_api_keyfacebook_secret) redirect_uri client_id client_secretrscopezread_stream,offline_access)rr extra_params)r%r&requestfull_urlr'r8rTrUs rr-zFacebookClientLoginHandler.gets   VT *44!\\224--(:;"mm,=>&&v. 5D JJt   # #!\\224--(:;%'CD $ sB9B;Nr.r3rrrrs C  ]]rrceZdZdZy) FacebookServerAccessTokenHandlerc<|jtddy)NrIir\ expires_in)r8rOr9s rr-z$FacebookServerAccessTokenHandler.gets 4V=>rNrur3rrrrrvrrceZdZdZy)FacebookServerMeHandlerc&|jdy)Nz{}rsr9s rr-zFacebookServerMeHandler.gets 4rNrur3rrrrsrrceZdZdZdZy)TwitterClientHandlerc|jd|_|jd|_|jd|_|jd|_|jd|_y)Nr?/twitter/server/access_tokenr@z/twitter/server/authenticatez /twitter/api)rrCrErD_OAUTH_AUTHENTICATE_URL_TWITTER_BASE_URLrs rrzTwitterClientHandler.initializes[(, 5S(T%'+||4R'S$$(LL1K$L!'+||4R'S$!%n!=rc |jdS)Nr")r'r9s rget_auth_http_clientz)TwitterClientHandler.get_auth_http_clients}}]++rN)r/r0r1rrr3rrrrs >,rrc0eZdZejdZy)TwitterClientLoginHandlerc#K|jddr1|j}| td|j|y|j ywNrSr$)r%r&r(r)rTrUs rr-zTwitterClientLoginHandler.getsU   ]D 14466D|// KK  %%''AANr/r0r1r r2r-r3rrrrs]]((rrc0eZdZejdZy) TwitterClientAuthenticateHandlerc#K|jddr1|j}| td|j|y|j ywr)r%r&r(r)r*rUs rr-z$TwitterClientAuthenticateHandler.getsU   ]D 14466D|// KK  ((**rNrr3rrrrs ]]++rrc0eZdZejdZy)%TwitterClientLoginGenCoroutineHandlerc#K|jddr$|j}|j|y|jyw)NrS)r%r&r)rTrUs rr-z)TwitterClientLoginGenCoroutineHandler.getsD   ]D 14466D KK ))+ +sA A Nrr3rrrrs]],,rrc0eZdZejdZy)TwitterClientShowUserHandlerc#K |jd|jdztdd}|j|y#t$r%|j d|jdYywxYww) Nz/users/show/%snamehjklvbnmrKr\zerror from twitter request)twitter_requestr%rOr)r rbrresponses rr-z TwitterClientShowUserHandler.gets{ "!11 4#4#4V#<<!fV<2H KK !  6 OOC KK4 5  6s'A92AA9+A63A95A66A9Nrr3rrrrs]]""rrceZdZdZy)TwitterServerAccessTokenHandlerc&|jdy)Nz8oauth_token=hjkl&oauth_token_secret=vbnm&screen_name=foorsr9s rr-z#TwitterServerAccessTokenHandler.gets MNrNrur3rrrrsOrrceZdZdZy)TwitterServerShowUserHandlerc|dk(r tdd|jjvsJd|jjvsJd|jjvsJ|jddk(sJ|jdd k(sJ|jd d k(sJ|jd d k(sJ|j t ||j y)Nerrorr oauth_nonceoauth_timestampoauth_signatureoauth_consumer_keytest_twitter_consumer_keyoauth_signature_method HMAC-SHA1 oauth_version1.0rSr screen_namer)rr argumentsr%r8rO capitalize)rrs rr-z TwitterServerShowUserHandler.gets ' !C.  6 6666 DLL$:$:::: DLL$:$::::  !56:UUUU  !9:kIII  1U:::  /6999 4Kk6L6L6NOPrNrur3rrrrs QrrceZdZdZy)%TwitterServerVerifyCredentialsHandlercd|jjvsJd|jjvsJd|jjvsJ|jddk(sJ|jddk(sJ|jdd k(sJ|jd d k(sJ|jt d d y)NrrrrrrrrrrSrrlFoor)rrr%r8rOr9s rr-z)TwitterServerVerifyCredentialsHandler.gets 6 6666 DLL$:$:::: DLL$:$::::  !56:UUUU  !9:kIII  1U:::  /6999 4E67rNrur3rrrrs8rrceZdZdZdZdZdZdZdZdZ e je dud d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZy)AuthTestc^tdtt|fdtt|dfdttdfdtt|d fd t t|d fd ttd fd t t|fd tt|fdtt|fdtt|fdtt|fdtt|fdtfdtfdtfdtfdt fdt"fdt$fdt&fg|j(ddddS)N/openid/client/loginr/oauth10/client/loginr)rrF/oauth10/client/request_params)rF/oauth10a/client/loginz1.0az /oauth10a/client/login_coroutine/oauth10a/client/request_params/oauth2/client/login/facebook/client/login/twitter/client/login/twitter/client/authenticate#/twitter/client/login_gen_coroutinez/twitter/client/show_userrr?rArz/facebook/server/merz"/twitter/api/users/show/(.*)\.jsonz-/twitter/api/account/verify_credentials\.jsonrtest_twitter_consumer_secrettest_facebook_api_keytest_facebook_secret)r"twitter_consumer_keytwitter_consumer_secretrr)rrrOr=rfr_r{rrrrrr5rqrxrrrrrr"r9s rget_appzAuthTest.get_appsd()A4T?S+,dE2 58' -,dF3 75dF3 68( ()A4T?S)+EtQUW(*CTt_U24dO :9dO 00dO /0OP/1PQ.0NO02RS&(?@/1PQ68TUD9m: v((!<$B42AA A rc|jdd}|j|jd|jd|jdy)NrFfollow_redirects.z/openid/server/authenticate?Locationfetch assertEqualrassertInheadersrs rtest_openid_redirectzAuthTest.test_openid_redirectUsC::4u:M , 4h6F6Fz6RSrc|jd}|jt|j}|j |ddy)Nz/openid/client/login?openid.mode=blah&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.value.email=foo@example.comr[rZrrethrowr bodyrrrparseds rtest_openid_get_userzAuthTest.test_openid_get_userZsF:: 5  X]]+ *;?X]]+  45v>  .7 mV, '0rc|jdd}|j|jd|j|jdj d|jd|jdv|jdy) NrFrrrrrr)rrrrrrrs rtest_oauth10a_redirectzAuthTest.test_oauth10a_redirects::6:O ,    Z ( 1 1;   6 - .   \ * rNzmock package not presentc>tjjtd5}t d|_t td5|jdd}ddd|jjddddy#1swY.xYw#1swYyxYw)Nr-boomzUncaught exceptionrFrr) rpatchobjectrqr( side_effectrr rrr)rr-rs rtest_oauth10a_redirect_errorz%AuthTest.test_oauth10a_redirect_errors ZZ  > F 1#'/CO7$89 X::&>QV:W X   X]]C 0  1 1 X X 1 1s#!BB$BB BBc|jdddi}|jt|j}|j |dd|j |dt dd y) Nz'/oauth10a/client/login?oauth_token=zxcvrrrr[rZr\rXrYrKrrs rtest_oauth10a_get_userzAuthTest.test_oauth10a_get_usersn:: 5GH  X]]+ *;< /&1PQrc |jd}|jt|j}|j |dd|j |dd|j d||j d|y)NrrrIrSrXrrrrs r test_oauth10a_request_parametersz)AuthTest.test_oauth10a_request_parametersss::?@X]]+  45v>  .7 mV, '0rcf|jdddi}|j|jdy)NzG/oauth10a/client/login_coroutine?oauth_token=zxcv&fail_in_get_user=truerrrra)rrrrs r*test_oauth10a_get_user_coroutine_exceptionz3AuthTest.test_oauth10a_get_user_coroutine_exceptions7:: UGH  ,rc|jdd}|j|jd|jd|jdy)NrFrrz/oauth2/server/authorize?rrrs rtest_oauth2_redirectzAuthTest.test_oauth2_redirectsC::4u:M , 183C3CJ3OPrc~|jdd}|j|jd|jd|jdv|jdd}|j|jdt |j }|j|d d |j|d d y) NrFrrz/facebook/server/authorize?rz /facebook/client/login?code=1234r\rIsession_expires3600)rrrrrr r)rrr+s rtest_facebook_loginzAuthTest.test_facebook_logins::6:O , 59I9I*9UUV:: .  ,8==) n-v6 /0&9rc|j|d}|j|jd|j|jdj d|j d|jd|jdy)NFrrrrrrr)rurlrs rbase_twitter_redirectzAuthTest.base_twitter_redirects}::cE:: ,    Z ( 1 1;  6   \ *   \ * rc&|jdy)Nrrr9s rtest_twitter_redirectzAuthTest.test_twitter_redirects ""#:;rc&|jdy)Nrrr9s r#test_twitter_redirect_gen_coroutinez,AuthTest.test_twitter_redirect_gen_coroutines ""#HIrc2|jdd}|j|jd|j|jdj d|jd|j d|jd|jdy) NrFrrrz-/twitter/server/authenticate?oauth_token=zxcvrrrrs r"test_twitter_authenticate_redirectz+AuthTest.test_twitter_authenticate_redirects::::GH   &J(W rc|jd}|j|jd|j|jdy)Nz$/twitter/client/show_user?name=errorrserror from twitter request)rrrrrs rtest_twitter_show_user_errorz%AuthTest.test_twitter_show_user_error s:::DE , (EFr)r/r0r1rrrrrrrunittestskipIfrr r rrrrrrr r"r%r)r+r3rrrrsB HT =  R1  X__TT\#=>1?1R1-Q : <J  * Grrc6eZdZdZej dZy)GoogleLoginHandlerc||_|jd|_|jd|_|jd|_y)N /client/login/google/oauth2/authorize/google/oauth2/token)rr_OAUTH_REDIRECT_URIrDrErs rrzGoogleLoginHandler.initializes> #'<<#@ $(LL1K$L!'+||4J'K$rc#nK|jdd}|i|j|j|}|j|jj d|d}|d|d<|j |y|j|j|jddddgdd d i yw) Nr/google/oauth2/userinfor\r google_oauthrLprofiler[promptselect_account)rrr response_typer) r%r&r4oauth2_requestrrr8rTr')rraccessr+s rr-zGoogleLoginHandler.gets  .  66t7O7OQUVVF,, !!";<#N3-D $*.#9D JJt   # #!55--7> '*$&(89 $ sB3B5Nr.r3rrr/r/s L  ]]rr/ceZdZdZy)GoogleOAuth2AuthorizeHandlercpd}|jt|jdt|y)Nfake-authorization-coder)r)redirectr r%rO)rrs rr-z GoogleOAuth2AuthorizeHandler.get0s)( j!2!2>!BDdOTUrNrur3rrr?r?/sVrr?ceZdZdZy)GoogleOAuth2TokenHandlercX|jddk(sJ|jdddy)NrrAfake-access-tokenz never-expiresrr%r)r9s rr:zGoogleOAuth2TokenHandler.post7s0  (,EEEE 0 P rNr;r3rrrDrD6s rrDceZdZdZy)GoogleOAuth2UserinfoHandlercX|jddk(sJ|jdddy)Nr\rFrrZ)rr[rGr9s rr-zGoogleOAuth2UserinfoHandler.get@s.  04GGGG U->?@rNrur3rrrIrI?sArrIceZdZdZdZy)GoogleOAuth2Testcptdtt|fdtfdtfdt fgddd S) Nr1rr2r3r6fake_google_client_idfake_google_client_secretrK)r7)rr/rOr?rDrIr9s rrzGoogleOAuth2Test.get_appGsM!"4doF+-IJ')AB*,GH  /5  rcx|jd}|jddddt|jy)Nr1rrZrF)rr[r\)rassertDictEqualr rrs rtest_google_loginz"GoogleOAuth2Test.test_google_loginWs:::o. * 3   &  rN)r/r0r1rrRr3rrrLrLFs   rrL)4r, tornado.authrrrrrrtornado.escaper tornador tornado.httpclientr tornado.httputilr tornado.logr tornado.testingrr tornado.webrrrr ImportErrorrr5r=r_rfrqrxr{rrrrrrrrrrrrr/r?rDrIrLr3rrr\s '.'8>> ~{$$n$-~z->,(@," >:  ?n? ?^? ~{1C0?~? n ,>< , ( 4 ( +'; + ,,@ ,"#7"&OnO Q> Q 8N 8~G ~GB):<V>V ~ A.A ( Y DsE''E21E2