Digg.com 风格的 oauth
我一直试图弄清楚 digg.com 和其他类似网站如何通过 oauth 处理身份验证。通过 oauth 创建帐户非常简单,用户单击 twitter/facebook 连接按钮,然后 digg 向我们发送一个秘密,如果一切正常,该秘密将被返回并存储为访问令牌。
然而,身份验证是如何工作的呢?例如,当我单击“通过 Twitter 登录”按钮时,一个随机秘密将被发送到 Twitter。 twitter 是否返回先前的访问令牌,或者 digg 是否获取 twitter 用户 ID,例如,将其与数据库中存储的值进行比较,然后使用那里存储的访问令牌?
例如: 1. 用户点击 Twitter 登录。 2. 发送秘密,twitter 进行一些处理并返回信息,例如用户名/id/等... 3. 根据这些返回值之一,轮询数据库并加载用户行,身份验证成功。
我在这方面还差得远吗?有人可以启发我吗?
I've been trying to figure out exactly how digg.com and other similar sites deal with authentication via oauth. Creating an account via oauth is pretty straight forward, the user clicks the twitter/facebook connect button which then digg sends our a secret and if everything works, this secret is returned and gets stored as the access token.
However, how does authentication work this way? When I click on the login via twitter button for example, a random secret is being sent to twitter. Does twitter instead return the prior access token or does digg get the twitter user id for example, compare it to a stored value in the db and then uses the stored access token from there?
For example:
1. user clicks login via twitter.
2. a secret is sent, twitter does some processing and returns info such as username/id/etc...
3. based on one of these return values, the db is polled and the user rows are loaded, authentication succeeds.
Am I way off on this? Can someone please enlighten me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下内容基于工作流程 由hueniverse提供:
Digg 从 Twitter 请求请求令牌(不是特定于用户的,Digg 可以使用它来获得用户的用户批准以访问用户的信息)。
Digg 接收请求令牌并使用 RequestToekn 将用户重定向到 Twitter OAuth 用户授权 URL,并要求 Twitter 在获得批准后将用户重定向回来。
OAuth 要求服务提供商 (Twitter) 首先对用户进行身份验证,然后要求他们授予消费者 (Digg) 访问权限。
Twitter 通知用户谁正在请求访问(Digg)以及被授予的访问类型。 (我对 Digg 不熟悉,所以以 Stack Exchange 为例,它只要求访问用户名。)
Twitter 将请求令牌标记为用户授权。 用户的浏览器被重定向回 Digg。
Digg 使用授权的请求令牌并将其交换为访问令牌(用于访问受保护的资源。在堆栈交换的情况下,用户名,尽管听起来有点奇怪)。
这是我的非官方图片:
以上内容基于 OAuth 1.0 官方指南,但根据 OAuth 2.0 简介:
The following is based on Workflow provided by hueniverse:
Digg requests from Twitter a Request Token (not User-specific, can be used by Digg to gain User approval from User to access User's information).
Digg receives the Request Token and redirects User to the Twitter OAuth User Authorization URL with RequestToekn and asks Twitter to redirect User back once approval has been granted.
OAuth requires that Service Providers (Twitter) first authenticate the User, and then ask them to grant access to the Consumer (Digg).
Twitter informs User of who is requesting access (Digg) and the type of access being granted. (I am not familiar with Digg, so take Stack Exchange as another example, it only asks for access to username.)
Twitter marks the Request Token as User-authorized. User's browser is redirected back to Digg.
Digg uses the authorized Request Token and exchanges it for an Access Token (used to access Protected Resources. In case of Stack Exchange, username, though it sounds a little bit weird).
Here is an unofficial picture by me:
Above is based on the the Official Guide to OAuth 1.0, but according to Introducing OAuth 2.0:
如果您想实现此类身份验证,可以查看 示例 ZF 应用程序,展示了为此目的使用 twitter、facebook、google 等的一种方法。
If you would like to implement such authentication, you can have a look at example ZF application that shows one way of using twitter, facebook, google, etc. for this purpose.