我正在使用rails-4
,并且已经在我的应用程序中使用以下 gemsOAuth-2
进行身份验证Google+ API
:
我已收到以下事先电子邮件通知:
2019 年 3 月 7 日,所有 Google+ API 和 Google+ Sign-in 将完全关闭。这将是一个渐进式关闭,API 调用最早在 2019 年 1 月 28 日开始间歇性失败,并且 OAuth 请求 > 针对 Google+ 范围的 OAuth 请求最早在 2019 年 2 月 > 15 日开始间歇性失败。
今天,我无法进行身份验证,因为在 API 收到以下代码后我得到nil
了request.env["omniauth.auth"]
:
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
请建议我如何解决这个问题,或者提供一个替代方案。
最后,我通过为用户信息提供备用 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
现在效果很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句