0

我正在使用rails-4,并已在我的应用程序中使用以下 gemOAuth-2进行身份验证:Google+ API

  1. 全域认证-oauth2
  2. omn​​iauth-google-oauth2

我已收到以下事先电子邮件通知:

2019 年 3 月 7 日,所有 Google+ API 和 Google+ 登录将完全关闭。这将是一个渐进式关闭,API 调用早在 2019 年 1 月 28 日就开始间歇性失败,而针对 Google+ 范围的 OAuth 请求早在 2019 年 2 月 15 日就开始间歇性失败。

今天,我无法进行身份验证,因为我在 API 收到nil以下request.env["omniauth.auth"]代码后得到:

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

请建议我如何解决此问题,或提供替代方法。

4

1 回答 1

3

最后,我设法通过为用户信息提供备用 OpenIdConnect 端点来解决这个问题。使用source,我替换了:

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

和:

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

我猴子修补omniauth-google-oauth2如下:

配置/初始化程序/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

现在效果很好。

于 2019-03-07T11:56:31.233 回答