Google plus API shutdown today, which alternative can be used to authentication?

99封情书 提交于 2019-12-17 10:04:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/55042981/google-plus-api-shutdown-today-which-alternative-can-be-used-to-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!