0
我想獲得谷歌身份驗證與龍捲風工作來測試的概念。我有以下代碼:谷歌身份驗證與龍捲風
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.gen
import tornado.auth
import os.path
import time
from tornado.options import define, options
define("port",default=8000, help="run on port", type=int)
class AuthHandler(tornado.web.RequestHandler, tornado.auth.GoogleMixin):
@tornado.gen.coroutine
def get(self):
if self.get_argument('code', False):
print("now running auth_user()")
user = yield self.get_authenticated_user(
redirect_uri='http://localhost:8000/auth',
code=self.get_argument('code'))
self.set_secure_cookie('token',"XXX")
self.redirect('/')
else:
yield self.authorize_redirect(
redirect_uri='http://localhost:8000/auth',
client_id=self.settings['google_oauth']['key'],
scope=['profile', 'email'],
response_type='code',
extra_params={'approval_prompt': 'force'})
# def post(self):
# self.render('index.html')
class IndexHandler(tornado.web.RequestHandler):
def get(self):
token=self.get_secure_cookie('token')
if not token:
print("getting google token")
self.redirect('/auth')
else:
print("TOKEN!")
# def post(self):
# self.render('index.html')
if __name__ == '__main__':
tornado.options.parse_command_line()
H=[(r'/',IndexHandler),(r'/auth',AuthHandler)]
T=os.path.join(os.path.dirname(__file__),"templates")
settings=dict(
google_oauth = dict(key="XXX.apps.googleusercontent.com", secret ="YYYYY"),
cookie_secret = 'DPTDQARHTDayv8WV61iMSsvAD18Rc00bizO519+2i4w='
)
app = tornado.web.Application(handlers=H,template_path=T,debug=True, **settings)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
我不斷收到一個
"TypeError: authorize_redirect() got an unexpected keyword argument 'client_id'"
我身邊跟着獲取客戶端ID和祕密,並把這些值在設置的文檔。此外,我已經設置了重定向URI谷歌的控制檯內是'localhost:8000/auth'