【发布时间】:2013-01-05 06:41:12
【问题描述】:
我对@987654321@ 和oauth_required 之间区别的理解是aware 不会强制授权,而required 会强制授权,但这不是我在实践中看到的。我有下面两个 webapp RequestHandlers,其中一个get() 方法用decorator.oauth_aware 装饰,另一个用decorator.oauth_required 装饰。但是,当我在本地或 App Engine 上运行时,两者都会立即重定向到登录流程。
目标是SplashHandler 为用户提供一个链接以进行授权,如果他们还没有,则转发到/tasks/。
decorator = OAuth2Decorator(
client_id=settings.CLIENT_ID,
client_secret=settings.CLIENT_SECRET,
scope=settings.SCOPE,
user_agent='mytasks')
class SplashHandler(webapp.RequestHandler):
@decorator.oauth_aware
def get(self):
if not decorator.has_credentials():
self.response.out.write(template.render('templates/convert.html',
{'authorize_url': decorator.authorize_url()}))
else:
self.redirect('/tasks/')
class TasksHandler(webapp.RequestHandler):
@decorator.oauth_required
def get(self):
tasks = get_tasks()
tasks.sort(key=lambda x: x['due'])
self.response.out.write(template.render('templates/index.html',
{'tasks': tasks}))
application = webapp.WSGIApplication(
[('/', SplashHandler), ('/tasks/', TasksHandler)], debug=True)
【问题讨论】:
标签: google-app-engine oauth-2.0