我正在使用rails-4,并在我的应用程序中使用OAuth-2来使用Google+ API进行身份验证,其中使用了以下宝石:
本人已收到以下电邮通知:
在2019年3月7日,所有Google+ API和Google+登录将被完全关闭。这将是一个渐进的关闭,API调用早在2019年1月28日就开始断断续续地失败,而OAuth requests > Google+作用域早在2019年2月>15日就开始间歇性地失效。
今天,我无法进行身份验证,因为在API接收到以下代码之后,我获得了nil for request.env["omniauth.auth"]:
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)请建议我如何解决这个问题,或提供一个替代方案。
发布于 2019-03-07 11:56:31
最后,通过为用户信息提供一个备用的OpenIdConnect端点,我设法解决了这个问题。使用来源,我替换了:
https://www.googleapis.com/plus/v1/people/me/openIdConnect通过以下方式:
https://www.googleapis.com/oauth2/v3/userinfo我给omniauth-google-oauth2打了个补丁,具体如下:
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现在效果很好。
https://stackoverflow.com/questions/55042981
复制相似问题