简体   繁体   English

重用OAuth访问令牌

[英]Reusing OAuth Access Tokens

On my site, I intend to offer users the ability to authenticate via OAuth. 在我的网站上,我打算为用户提供通过OAuth进行身份验证的功能。 I don't want to ask them to first register with me and then connect an external account; 我不想让他们先向我注册,然后再连接一个外部帐户; I want to offer single sign on. 我想提供单点登录。

I believe we're supposed to reuse Access Tokens; 我相信我们应该重用访问令牌; certainly within sessions and even between them. 当然在会议期间,甚至在会议之间。

Google goes so far as to say they'll limit the number of access tokens to 10 per user per application . 谷歌甚至宣称他们将每个应用程序的每个用户的访问令牌数量限制为10个 (Apparently Google still supports OAuth1, but recommends Auth2 now) 10 is a pretty small number. (显然Google仍然支持OAuth1,但现在建议使用Auth2)10是一个很小的数字。

Using cookies ( like this ) seems like a good plan for identifying a user between sessions, but I'm having trouble with the scenario where a user has deleted cookies or connects from a new machine. 使用cookie( 这样 )似乎是识别会话之间用户的好计划,但是对于用户已删除cookie或从新计算机连接的情况,我遇到了麻烦。

How do I know who the user is before I've requested another Access Token for them? 在为他们请求另一个访问令牌之前,如何知道用户是谁? Request tokens do not contain the userid, right? 请求令牌不包含用户ID,对吗?

Thanks 谢谢

You will have to maintain your own user accounts anyway, no matter which protocol and which provider you choose. 无论选择哪种协议和提供商,都必须维护自己的用户帐户。 A token (or a URL in the case of OpenID) that you get from a provider is unique for a given user and you are supposed to associate it with your internal user account and recognize user by it. 您从提供者那里获得的令牌(对于OpenID,则为URL)对于给定用户而言是唯一的,您应该将其与内部用户帐户相关联,并由此识别用户。

If you don't want to provide any registration UI it's okay: just get the token, retrieve all the user info you need from the provider and store all this somewhere in your database. 如果您不想提供任何注册UI,也可以:只需获取令牌,从提供商处检索所需的所有用户信息,并将所有这些信息存储在数据库中的某个位置。 You will also have to issue and recognize your own cookie for your users, or else they'll be forced to go through provider auth every time they visit your site. 您还必须为用户发布和识别您自己的cookie,否则,每次他们访问您的网站时,他们将被迫通过提供商身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM