简体   繁体   English

设计:将Google Open ID迁移到Google OAuth

[英]Devise: Migrate Google Open ID to Google OAuth

Does anyone have clues about how to do this? 有没有人有关于如何做到这一点的线索? I'm basically trying to replace the strategy for "Connect With Google" from OpenID to OAuth. 我基本上试图将OpenID中的“与Google连接”策略替换为OAuth。 The challenge is identifying an old user (user on Google open ID) when a user signs in under the new OAuth scheme. 当用户在新的OAuth方案下登录时,挑战是识别旧用户(Google开放ID上的用户)。

I have a working implementation which relies on email address as the primary key, as the open ID strategy captures that. 我有一个工作实现,它依赖于电子邮件地址作为主键,因为开放ID策略捕获了这一点。 The problem is, I don't want to ask for email in the OAuth flow. 问题是,我不想在OAuth流程中要求提供电子邮件。 The ideal value is simply Google user ID, but the Open ID strategy doesn't seem to capture that. 理想的价值仅仅是Google用户ID,但Open ID策略似乎没有捕获到它。

So I have open ID tokens like https://www.google.com/accounts/o8/id?id=AfSCwGQ4PUaidXSQddJugXKLqU5V0MrXFhJM6UHybPw and trying to understand if I could get a Google ID from that. 所以我有https://www.google.com/accounts/o8/id?id=AfSCwGQ4PUaidXSQddJugXKLqU5V0MrXFhJM6UHybPw这样的开放式ID令牌,并尝试了解我是否可以从中获取Google ID。

UPDATE: I explained here how I ended up doing this migration - http://softwareas.com/migrating-user-accounts-from-google-openid-to-google-oauth-to-google-plus 更新:我在这里解释了我最终如何进行迁移 - http://softwareas.com/migrating-user-accounts-from-google-openid-to-google-oauth-to-google-plus

We don't have a strategy ready today that avoids the user seeing another approval page. 我们今天没有准备好的策略可以避免用户看到另一个批准页面。

However, rather than attempt to do an OAuth1 based hybrid flow and have to add all that legacy code to your server, I'd suggest you simply correlate on email address and move to OAuth2 login. 但是,我建议您只关联电子邮件地址并转到OAuth2登录,而不是尝试执行基于OAuth1的混合流并且必须将所有遗留代码添加到您的服务器。 I'm assuming you're like the majority of sites that end up asking for email address because they usually want it for account recovery. 我假设你像大多数网站最终要求电子邮件地址,因为他们通常希望它用于帐户恢复。 Just make sure you get the email address from OpenId as one of the signed parameters. 只需确保从OpenId获取电子邮件地址作为签名参数之一。

Then use the userinfo.email scope and OAuth2 https://developers.google.com/accounts/docs/OAuth2Login and you should be able to migrate with less developer pain. 然后使用userinfo.email范围和OAuth2 https://developers.google.com/accounts/docs/OAuth2Login ,您应该能够以更少的开发人员痛苦进行迁移。

In addition, we're in the process of adding support for OpenIDConnect and it supports a parameter of login_hint so you'd add &login_hint=bob@gmail.com to your authorization URL and it will steer the approval to the right account. 此外,我们正在添加对OpenIDConnect的支持,并且它支持login_hint的参数,因此您将&login_hint=bob@gmail.com添加到您的授权URL,它将引导批准到正确的帐户。 This is not documented right now but it may be useful for you to try it. 现在没有记录,但它可能对您有用。 The user's browser could be logged into Google with a number of accounts and you want to try to get the right one. 用户的浏览器可能会使用多个帐户登录到Google,您希望尝试使用正确的帐户。 Always check the email you get from the OAuth2 flow to make sure it matches since this is just a 'hint'. 始终检查您从OAuth2流程获得的电子邮件,以确保它匹配,因为这只是一个“提示”。

Users will still have to re-authorize for OAuth2, but we have plans to skip this reauthorization in the future. 用户仍然需要重新授权OAuth2,但我们计划在将来跳过此重新授权。 The main point is to plan on using OAuth2 and we hope to deliver a seamless migration soon and you'll be on a supported protocol. 重点是计划使用OAuth2,我们希望尽快提供无缝迁移,您将获得支持的协议。

Google uses directed identifiers for OpenID that are unique per relying party and are explicitly designed to conceal any correlatable identifier for the user. Google使用OpenID的定向标识符 ,每个依赖方都是唯一的,并明确设计为隐藏用户的任何相关标识符。 So the short answer is, no there's no way to get a Google ID that corresponds with a given Google OpenID. 所以简短的回答是,没有办法获得与给定的Google OpenID相对应的Google ID。

One option, however, might be to use Google's OpenID+OAuth Hybrid flow. 但是,一种选择可能是使用Google的OpenID + OAuth混合流程。 This allows you to get an OAuth token as part of a normal OpenID flow, which could then be used to get the user's ID from the OAuth2 Login API, which you can then associate with their existing account. 这允许您将OAuth令牌作为普通OpenID流的一部分获取,然后可以使用该令牌从OAuth2登录 API获取用户的ID,然后您可以将其与其现有帐户关联。 Once you've done that for all of your existing users, then switch to using the OAuth2 Login directly. 完成所有现有用户的操作后,请直接切换到使用OAuth2登录。

The trick, of course, with this approach is getting all of your users to login again so that you can send them through the new flow. 当然,使用这种方法的诀窍是让所有用户再次登录,以便您可以通过新流程发送它们。 That will come down to how long you're willing to wait to migrate accounts, and whether you're willing to prod existing users by emailing them and asking them to login again (similar to a forced password reset). 这将取决于您愿意等待多长时间迁移帐户,以及您是否愿意通过向他们发送电子邮件并要求他们再次登录来刺激现有用户(类似于强制密码重置)。

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

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