Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

ruby on rails - Google plus API shutdown today, which alternative can be used to authentication?

I am using rails-4, and have used OAuth-2 for authentication with Google+ API, for which the following gems are used, in my app:

  1. omniauth-oauth2
  2. omniauth-google-oauth2

I have received the following prior email notice:

On March 7, 2019, all Google+ APIs and Google+ Sign-in will be shut down completely. This will be a progressive shutdown, with API calls starting to intermittently fail as early as January 28, 2019, and OAuth requests > for Google+ scopes starting to intermittently fail as early as February > 15, 2019.

Today, I cannot authenticate, as I get nil for request.env["omniauth.auth"] after the API received the following piece of code:

@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)

Please suggest how I can solve this issue, or provide an alternative to this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally, I somehow managed to solve the issue by providing an alternate OpenIdConnect endpoint for user information. Using source, I replaced:

https://www.googleapis.com/plus/v1/people/me/openIdConnect

with:

https://www.googleapis.com/oauth2/v3/userinfo

I monkey-patched omniauth-google-oauth2 as follows:

config/initializers/omniauth_google_oauth2_patch.rb

class OmniAuth::Strategies::GoogleOauth2 < OmniAuth::Strategies::OAuth2
  def raw_info
    @raw_info ||= access_token.get('https://www.googleapis.com/oauth2/v3/userinfo').parsed
  end
end

And it's working great now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...