Twitter API - 登出 [英] Twitter API - Logout

查看:21
本文介绍了Twitter API - 登出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网络应用中使用 OAuth,用户可以使用 Twitter 登录.

I'm using OAuth in my web app, and users can login with twitter.

我想添加切换推特帐户"按钮,它实际上清除了会话,然后打开了 authorize_url.

I want to add "switch twitter account" button, which actually clears the session and then opens the authorize_url.

由于在我的 Web 应用程序中清除会话不会注销 twitter,authorize_url 将自动验证当前 twitter.com 用户.这意味着我无法注销,除非我将用户发送到 twitter.com.

As clearing the session in my web app doesn't log out of twitter, the authorize_url will automatically authenticate the current twitter.com user. That means I can't do logout, unless I send the user to twitter.com.

可以使用 API 吗?实现此目的的最佳方法是什么?

Is it possible with the API? What is the best way to implement this?

推荐答案

与 Twitter 的会话是由 Twitter 拥有的 cookie 定义的——这是您无法控制的.您不能代表他们从 Twitter 注销.

The session with Twitter is defined by a cookie owned by Twitter -- something you do not have control over. You cannot log them out of Twitter on their behalf.

如果您希望某人能够使用您的切换 Twitter 帐户"功能,您需要再次将他们传递给 OAuth 握手,但使用 /oauth/authorize 路径代替/oauth/authenticate 路径.这将允许用户在握手期间在 Twitter 上切换他们的用户凭据,而不仅仅是使用他们现有的 Twitter 会话重新进行身份验证.

If you want someone to be able to use your "switch twitter account" functionality, you'll need to pass them off to the OAuth handshake again, but use the /oauth/authorize path instead of the /oauth/authenticate path. This will allow the user to switch their user credentials at Twitter during the handshake instead of just re-authenticating using their existing Twitter session.

或者,您可以在自己的应用程序中拥有一个单独的用户概念,即您拥有自己的用户模型,其中包含许多与之关联的 Twitter 帐户.这样,您就可以让您的用户更无缝地切换帐户.他们必须事先为他们的每个 Twitter 帐户授权您的应用,但之后您将拥有他们每个 Twitter 帐户的所有 oauth 密钥.

Alternatively, you could have a separate notion of users in your own app whereby you have your own user model that has many twitter accounts associated with it. That way, you could allow your users to switch accounts more seemlessly. They would have to authorize your app up front for each of their twitter accounts, but you would have all their oauth keys for each of their twitter accounts after that.

这篇关于Twitter API - 登出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆