问题
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:
- omniauth-oauth2
- 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