<s> from __future__ import absolute_import , division , print_function , with_statement <EOL> from tornado . auth import OpenIdMixin , OAuthMixin , OAuth2Mixin , TwitterMixin , AuthError , GoogleOAuth2Mixin , FacebookGraphMixin <EOL> from tornado . concurrent import Future <EOL> from tornado . escape import json_decode <EOL> from tornado import gen <EOL> from tornado . httputil import url_concat <EOL> from tornado . log import gen_log <EOL> from tornado . testing import AsyncHTTPTestCase , ExpectLog <EOL> from tornado . web import RequestHandler , Application , asynchronous , HTTPError <EOL> class OpenIdClientLoginHandler ( RequestHandler , OpenIdMixin ) : <EOL> def initialize ( self , test ) : <EOL> self . _OPENID_ENDPOINT = test . get_url ( '<STR_LIT>' ) <EOL> @ asynchronous <EOL> def get ( self ) : <EOL> if self . get_argument ( '<STR_LIT>' , None ) : <EOL> self . get_authenticated_user ( <EOL> self . on_user , http_client = self . settings [ '<STR_LIT>' ] ) <EOL> return <EOL> res = self . authenticate_redirect ( ) <EOL> assert isinstance ( res , Future ) <EOL> assert res . done ( ) <EOL> def on_user ( self , user ) : <EOL> if user is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . finish ( user ) <EOL> class OpenIdServerAuthenticateHandler ( RequestHandler ) : <EOL> def post ( self ) : <EOL> if self . get_argument ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . write ( '<STR_LIT>' ) <EOL> class OAuth1ClientLoginHandler ( RequestHandler , OAuthMixin ) : <EOL> def initialize ( self , test , version ) : <EOL> self . _OAUTH_VERSION = version <EOL> self . _OAUTH_REQUEST_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_AUTHORIZE_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_ACCESS_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> def _oauth_consumer_token ( self ) : <EOL> return dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) <EOL> @ asynchronous <EOL> def get ( self ) : <EOL> if self . get_argument ( '<STR_LIT>' , None ) : <EOL> self . get_authenticated_user ( <EOL> self . on_user , http_client = self . settings [ '<STR_LIT>' ] ) <EOL> return <EOL> res = self . authorize_redirect ( http_client = self . settings [ '<STR_LIT>' ] ) <EOL> assert isinstance ( res , Future ) <EOL> def on_user ( self , user ) : <EOL> if user is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . finish ( user ) <EOL> def _oauth_get_user ( self , access_token , callback ) : <EOL> if self . get_argument ( '<STR_LIT>' , None ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if access_token != dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) : <EOL> raise Exception ( "<STR_LIT>" % access_token ) <EOL> callback ( dict ( email = '<STR_LIT>' ) ) <EOL> class OAuth1ClientLoginCoroutineHandler ( OAuth1ClientLoginHandler ) : <EOL> """<STR_LIT>""" <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> if self . get_argument ( '<STR_LIT>' , None ) : <EOL> try : <EOL> yield self . get_authenticated_user ( ) <EOL> except Exception as e : <EOL> self . set_status ( <NUM_LIT> ) <EOL> self . write ( "<STR_LIT>" % e ) <EOL> else : <EOL> yield self . authorize_redirect ( ) <EOL> class OAuth1ClientRequestParametersHandler ( RequestHandler , OAuthMixin ) : <EOL> def initialize ( self , version ) : <EOL> self . _OAUTH_VERSION = version <EOL> def _oauth_consumer_token ( self ) : <EOL> return dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> params = self . _oauth_request_parameters ( <EOL> '<STR_LIT>' , <EOL> dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) , <EOL> parameters = dict ( foo = '<STR_LIT:bar>' ) ) <EOL> self . write ( params ) <EOL> class OAuth1ServerRequestTokenHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> class OAuth1ServerAccessTokenHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> class OAuth2ClientLoginHandler ( RequestHandler , OAuth2Mixin ) : <EOL> def initialize ( self , test ) : <EOL> self . _OAUTH_AUTHORIZE_URL = test . get_url ( '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> res = self . authorize_redirect ( ) <EOL> assert isinstance ( res , Future ) <EOL> assert res . done ( ) <EOL> class FacebookClientLoginHandler ( RequestHandler , FacebookGraphMixin ) : <EOL> def initialize ( self , test ) : <EOL> self . _OAUTH_AUTHORIZE_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_ACCESS_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _FACEBOOK_BASE_URL = test . get_url ( '<STR_LIT>' ) <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> if self . get_argument ( "<STR_LIT:code>" , None ) : <EOL> user = yield self . get_authenticated_user ( <EOL> redirect_uri = self . request . full_url ( ) , <EOL> client_id = self . settings [ "<STR_LIT>" ] , <EOL> client_secret = self . settings [ "<STR_LIT>" ] , <EOL> code = self . get_argument ( "<STR_LIT:code>" ) ) <EOL> self . write ( user ) <EOL> else : <EOL> yield self . authorize_redirect ( <EOL> redirect_uri = self . request . full_url ( ) , <EOL> client_id = self . settings [ "<STR_LIT>" ] , <EOL> extra_params = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> class FacebookServerAccessTokenHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> class FacebookServerMeHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . write ( '<STR_LIT:{}>' ) <EOL> class TwitterClientHandler ( RequestHandler , TwitterMixin ) : <EOL> def initialize ( self , test ) : <EOL> self . _OAUTH_REQUEST_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_ACCESS_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_AUTHORIZE_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _TWITTER_BASE_URL = test . get_url ( '<STR_LIT>' ) <EOL> def get_auth_http_client ( self ) : <EOL> return self . settings [ '<STR_LIT>' ] <EOL> class TwitterClientLoginHandler ( TwitterClientHandler ) : <EOL> @ asynchronous <EOL> def get ( self ) : <EOL> if self . get_argument ( "<STR_LIT>" , None ) : <EOL> self . get_authenticated_user ( self . on_user ) <EOL> return <EOL> self . authorize_redirect ( ) <EOL> def on_user ( self , user ) : <EOL> if user is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . finish ( user ) <EOL> class TwitterClientLoginGenEngineHandler ( TwitterClientHandler ) : <EOL> @ asynchronous <EOL> @ gen . engine <EOL> def get ( self ) : <EOL> if self . get_argument ( "<STR_LIT>" , None ) : <EOL> user = yield self . get_authenticated_user ( ) <EOL> self . finish ( user ) <EOL> else : <EOL> self . authorize_redirect ( ) <EOL> class TwitterClientLoginGenCoroutineHandler ( TwitterClientHandler ) : <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> if self . get_argument ( "<STR_LIT>" , None ) : <EOL> user = yield self . get_authenticated_user ( ) <EOL> self . finish ( user ) <EOL> else : <EOL> yield self . authorize_redirect ( ) <EOL> class TwitterClientShowUserHandler ( TwitterClientHandler ) : <EOL> @ asynchronous <EOL> @ gen . engine <EOL> def get ( self ) : <EOL> response = yield gen . Task ( self . twitter_request , <EOL> '<STR_LIT>' % self . get_argument ( '<STR_LIT:name>' ) , <EOL> access_token = dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) ) <EOL> if response is None : <EOL> self . set_status ( <NUM_LIT> ) <EOL> self . finish ( '<STR_LIT>' ) <EOL> else : <EOL> self . finish ( response ) <EOL> class TwitterClientShowUserFutureHandler ( TwitterClientHandler ) : <EOL> @ asynchronous <EOL> @ gen . engine <EOL> def get ( self ) : <EOL> try : <EOL> response = yield self . twitter_request ( <EOL> '<STR_LIT>' % self . get_argument ( '<STR_LIT:name>' ) , <EOL> access_token = dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) ) <EOL> except AuthError as e : <EOL> self . set_status ( <NUM_LIT> ) <EOL> self . finish ( str ( e ) ) <EOL> return <EOL> assert response is not None <EOL> self . finish ( response ) <EOL> class TwitterServerAccessTokenHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> class TwitterServerShowUserHandler ( RequestHandler ) : <EOL> def get ( self , screen_name ) : <EOL> if screen_name == '<STR_LIT:error>' : <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT:1.0>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> self . write ( dict ( screen_name = screen_name , name = screen_name . capitalize ( ) ) ) <EOL> class TwitterServerVerifyCredentialsHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert '<STR_LIT>' in self . request . arguments <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT:1.0>' <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> self . write ( dict ( screen_name = '<STR_LIT:foo>' , name = '<STR_LIT>' ) ) <EOL> class AuthTest ( AsyncHTTPTestCase ) : <EOL> def get_app ( self ) : <EOL> return Application ( <EOL> [ <EOL> ( '<STR_LIT>' , OpenIdClientLoginHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , OAuth1ClientLoginHandler , <EOL> dict ( test = self , version = '<STR_LIT:1.0>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> OAuth1ClientRequestParametersHandler , <EOL> dict ( version = '<STR_LIT:1.0>' ) ) , <EOL> ( '<STR_LIT>' , OAuth1ClientLoginHandler , <EOL> dict ( test = self , version = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> OAuth1ClientLoginCoroutineHandler , <EOL> dict ( test = self , version = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> OAuth1ClientRequestParametersHandler , <EOL> dict ( version = '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , OAuth2ClientLoginHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , FacebookClientLoginHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , TwitterClientLoginHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , TwitterClientLoginGenEngineHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , TwitterClientLoginGenCoroutineHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , TwitterClientShowUserHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , TwitterClientShowUserFutureHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , OpenIdServerAuthenticateHandler ) , <EOL> ( '<STR_LIT>' , OAuth1ServerRequestTokenHandler ) , <EOL> ( '<STR_LIT>' , OAuth1ServerAccessTokenHandler ) , <EOL> ( '<STR_LIT>' , FacebookServerAccessTokenHandler ) , <EOL> ( '<STR_LIT>' , FacebookServerMeHandler ) , <EOL> ( '<STR_LIT>' , TwitterServerAccessTokenHandler ) , <EOL> ( r'<STR_LIT>' , TwitterServerShowUserHandler ) , <EOL> ( r'<STR_LIT>' , TwitterServerVerifyCredentialsHandler ) , <EOL> ] , <EOL> http_client = self . http_client , <EOL> twitter_consumer_key = '<STR_LIT>' , <EOL> twitter_consumer_secret = '<STR_LIT>' , <EOL> facebook_api_key = '<STR_LIT>' , <EOL> facebook_secret = '<STR_LIT>' ) <EOL> def test_openid_redirect ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in response . headers [ '<STR_LIT>' ] ) <EOL> def test_openid_get_user ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed [ "<STR_LIT:email>" ] , "<STR_LIT>" ) <EOL> def test_oauth10_redirect ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( response . headers [ '<STR_LIT>' ] . endswith ( <EOL> '<STR_LIT>' ) ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in response . headers [ '<STR_LIT>' ] , <EOL> response . headers [ '<STR_LIT>' ] ) <EOL> def test_oauth10_get_user ( self ) : <EOL> response = self . fetch ( <EOL> '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed [ '<STR_LIT:email>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) ) <EOL> def test_oauth10_request_parameters ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in parsed ) <EOL> self . assertTrue ( '<STR_LIT>' in parsed ) <EOL> def test_oauth10a_redirect ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( response . headers [ '<STR_LIT>' ] . endswith ( <EOL> '<STR_LIT>' ) ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in response . headers [ '<STR_LIT>' ] , <EOL> response . headers [ '<STR_LIT>' ] ) <EOL> def test_oauth10a_get_user ( self ) : <EOL> response = self . fetch ( <EOL> '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed [ '<STR_LIT:email>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , dict ( key = '<STR_LIT>' , secret = '<STR_LIT>' ) ) <EOL> def test_oauth10a_request_parameters ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in parsed ) <EOL> self . assertTrue ( '<STR_LIT>' in parsed ) <EOL> def test_oauth10a_get_user_coroutine_exception ( self ) : <EOL> response = self . fetch ( <EOL> '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> def test_oauth2_redirect ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( '<STR_LIT>' in response . headers [ '<STR_LIT>' ] ) <EOL> def test_facebook_login ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( '<STR_LIT>' in response . headers [ '<STR_LIT>' ] ) <EOL> response = self . fetch ( '<STR_LIT>' , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT:200> ) <EOL> def base_twitter_redirect ( self , url ) : <EOL> response = self . fetch ( url , follow_redirects = False ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertTrue ( response . headers [ '<STR_LIT>' ] . endswith ( <EOL> '<STR_LIT>' ) ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in response . headers [ '<STR_LIT>' ] , <EOL> response . headers [ '<STR_LIT>' ] ) <EOL> def test_twitter_redirect ( self ) : <EOL> self . base_twitter_redirect ( '<STR_LIT>' ) <EOL> def test_twitter_redirect_gen_engine ( self ) : <EOL> self . base_twitter_redirect ( '<STR_LIT>' ) <EOL> def test_twitter_redirect_gen_coroutine ( self ) : <EOL> self . base_twitter_redirect ( '<STR_LIT>' ) <EOL> def test_twitter_get_user ( self ) : <EOL> response = self . fetch ( <EOL> '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response . rethrow ( ) <EOL> parsed = json_decode ( response . body ) <EOL> self . assertEqual ( parsed , <EOL> { u'<STR_LIT>' : { u'<STR_LIT:key>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT:foo>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' } , <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT:foo>' , <EOL> u'<STR_LIT:username>' : u'<STR_LIT:foo>' } ) <EOL> def test_twitter_show_user ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> response . rethrow ( ) <EOL> self . assertEqual ( json_decode ( response . body ) , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_twitter_show_user_error ( self ) : <EOL> with ExpectLog ( gen_log , '<STR_LIT>' ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertEqual ( response . body , b'<STR_LIT>' ) <EOL> def test_twitter_show_user_future ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> response . rethrow ( ) <EOL> self . assertEqual ( json_decode ( response . body ) , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_twitter_show_user_future_error ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . code , <NUM_LIT> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . body ) <EOL> class GoogleLoginHandler ( RequestHandler , GoogleOAuth2Mixin ) : <EOL> def initialize ( self , test ) : <EOL> self . test = test <EOL> self . _OAUTH_REDIRECT_URI = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_AUTHORIZE_URL = test . get_url ( '<STR_LIT>' ) <EOL> self . _OAUTH_ACCESS_TOKEN_URL = test . get_url ( '<STR_LIT>' ) <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> code = self . get_argument ( '<STR_LIT:code>' , None ) <EOL> if code is not None : <EOL> access = yield self . get_authenticated_user ( self . _OAUTH_REDIRECT_URI , <EOL> code ) <EOL> user = yield self . oauth2_request ( <EOL> self . test . get_url ( "<STR_LIT>" ) , <EOL> access_token = access [ "<STR_LIT>" ] ) <EOL> user [ "<STR_LIT>" ] = access [ "<STR_LIT>" ] <EOL> self . write ( user ) <EOL> else : <EOL> yield self . authorize_redirect ( <EOL> redirect_uri = self . _OAUTH_REDIRECT_URI , <EOL> client_id = self . settings [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] , <EOL> client_secret = self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> scope = [ '<STR_LIT>' , '<STR_LIT:email>' ] , <EOL> response_type = '<STR_LIT:code>' , <EOL> extra_params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class GoogleOAuth2AuthorizeHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> code = '<STR_LIT>' <EOL> self . redirect ( url_concat ( self . get_argument ( '<STR_LIT>' ) , <EOL> dict ( code = code ) ) ) <EOL> class GoogleOAuth2TokenHandler ( RequestHandler ) : <EOL> def post ( self ) : <EOL> assert self . get_argument ( '<STR_LIT:code>' ) == '<STR_LIT>' <EOL> self . finish ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> class GoogleOAuth2UserinfoHandler ( RequestHandler ) : <EOL> def get ( self ) : <EOL> assert self . get_argument ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> self . finish ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' <EOL> } ) <EOL> class GoogleOAuth2Test ( AsyncHTTPTestCase ) : <EOL> def get_app ( self ) : <EOL> return Application ( <EOL> [ <EOL> ( '<STR_LIT>' , GoogleLoginHandler , dict ( test = self ) ) , <EOL> ( '<STR_LIT>' , GoogleOAuth2AuthorizeHandler ) , <EOL> ( '<STR_LIT>' , GoogleOAuth2TokenHandler ) , <EOL> ( '<STR_LIT>' , GoogleOAuth2UserinfoHandler ) , <EOL> ] , <EOL> google_oauth = { <EOL> "<STR_LIT:key>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' <EOL> } ) <EOL> def test_google_login ( self ) : <EOL> response = self . fetch ( '<STR_LIT>' ) <EOL> self . assertDictEqual ( { <EOL> u'<STR_LIT:name>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:email>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> } , json_decode ( response . body ) ) </s>
