gpt4 book ai didi

google-app-engine - OAuth2 Decorator oauth 感知强​​制认证

转载 作者:太空宇宙 更新时间:2023-11-03 15:24:23 24 4
gpt4 key购买 nike

我对 oauth_awareoauth_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)

最佳答案

oauth_aware 方法旨在明确回答“我们是否有当前用户的访问 token ?”这个问题。它可以回答这个问题的唯一方法是知道当前用户是谁,并使用应用程序引擎用户 api 来做到这一点,它本身需要权限提示才能通过您看到的重定向获取您的电子邮件/用户 ID。使用 oauth_required 你实际上得到 2 个重定向,同一个应用程序引擎,然后是 oauth 请求 G+ 或 Docs 或其他任何东西的权限。

我碰巧认为这不是特别有用,我认为您的用例更为常见,但显然图书馆作者不同意。

话虽如此,oauth_aware 函数中的代码并不是很复杂,您可以基于它制作自己的装饰器,不进行第一次重定向。不同之处在于,在您的情况下,对同一问题的回答要么是"is",要么是“我不知道”,而不是明确的“否”。

关于google-app-engine - OAuth2 Decorator oauth 感知强​​制认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9936163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com