我正在使用rails-4
,并使用OAuth-2
与Google+ API
进行身份验证,在我的应用程序中使用了以下宝石:
我收到了以下的电子邮件通知:
在2019年3月7日,所有Google+ API和Google+登录都将完全关闭。这将是一个渐进式关闭,API调用最早在2019年1月28日开始间歇性失败,OAuth请求>对于Google+范围,最早在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
它现在很好用。