关于如何使用 OAuth2 登录用户的文档很多,但我还没有找到任何文档可以轻松地将用户注销。有谁知道我该怎么做?我只想让用户退出我的应用程序,以便其他人可以登录。
如果有帮助的话,这是我的登录代码:
import jinja2
import os
import webapp2
from apiclient.discovery import build
from oauth2client.contrib.appengine import OAuth2Decorator
from google.appengine.api import users
decorator = OAuth2Decorator(
client_id='',
client_secret='',
scope='https://www.googleapis.com/auth/userinfo.email')
template_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.getcwd()))
class LoginHandler(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
user = users.get_current_user()
template = template_env.get_template('index.html')
context = {
'user': user,
}
self.response.out.write(template.render(context))
application = webapp2.WSGIApplication(
[
('/login', LoginHandler),
(decorator.callback_path, decorator.callback_handler())
],
debug=True)
最佳答案
我认为您将身份验证(Open Id 连接)与授权 (Oauth2) 混淆了。 Oauth2 授权您访问与验证用户无关的用户数据。您永远不会注销 Oauth2 授权。
也就是说,您可以撤销对用户数据的访问权限,然后系统会提示他们再次授予您访问权限。
requests.post('https://accounts.google.com/o/oauth2/revoke',
params={'token': credentials.token},
headers = {'content-type': 'application/x-www-form-urlencoded'})
参见 revoke token了解更多信息
关于python - 从 OAuth2 注销 - Google App Engine/Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47830305/