4

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. The challenge is identifying an old user (user on Google open ID) when a user signs in under the new OAuth scheme.

I have a working implementation which relies on email address as the primary key, as the open ID strategy captures that. The problem is, I don't want to ask for email in the OAuth flow. The ideal value is simply Google user ID, but the Open ID strategy doesn't seem to capture that.

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.

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

mahemoff
  • 44,526
  • 36
  • 160
  • 222
  • 1
    Maybe [this link](http://andrewhorsman.net/ruby-oauth-google-calendar-data/) and Will Norris' answer will help you. If you do manage to get it working, it would be great if you could later post here your solution. I'd really appreciate it. – Ashitaka Dec 19 '12 at 23:44

2 Answers2

4

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. 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.

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.

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. 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. Always check the email you get from the OAuth2 flow to make sure it matches since this is just a 'hint'.

Users will still have to re-authorize for OAuth2, but we have plans to skip this reauthorization in the future. 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.

David Primmer
  • 421
  • 2
  • 7
  • Thanks David. I can make this work by asking for email, but I was trying to avoid asking for it. – mahemoff Dec 21 '12 at 01:38
  • This is dangerous however as it allows a user to generate a google account under the email address of a past user, and then login. – Doug Feb 26 '15 at 05:53
3

Google uses directed identifiers for OpenID that are unique per relying party and are explicitly designed to conceal any correlatable identifier for the user. So the short answer is, no there's no way to get a Google ID that corresponds with a given Google OpenID.

One option, however, might be to use Google's OpenID+OAuth Hybrid flow. 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. Once you've done that for all of your existing users, then switch to using the OAuth2 Login directly.

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).

Will Norris
  • 542
  • 2
  • 8
  • Thanks for this detailed answer. The challenge here is I want to show a single Connect With Google for everyone (new and existing), so the OpenID+OAuth flow wouldn't be what I want new users to go through. Luckily not so many users have connected via Google Open ID so far, so I will probably just make a custom migration flow for them and mail them a link to it. – mahemoff Dec 20 '12 at 04:24