问题描述
我正在使用 rails-4
,并使用 OAuth-2
与 Google+ API
进行身份验证,为此使用了以下 gem, 在我的应用中:
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:
2019 年 3 月 7 日,所有 Google+ API 和 Google+ Sign-in 都将关闭完全地.这将是渐进式关闭,API 调用开始最早在 2019 年 1 月 28 日间歇性失败,并且 OAuth 请求 > 针对 Google+ 范围的 OAuth 请求最早在 2019 年 2 月 > 15 日开始间歇性失败.
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.
今天,我无法进行身份验证,因为在 API 收到以下代码后,我为 request.env["omniauth.auth"]
获得了 nil
:>
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.
推荐答案
最后,我通过为用户信息提供备用 OpenIdConnect 端点以某种方式设法解决了该问题.使用 source,我替换了:
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
与:
https://www.googleapis.com/oauth2/v3/userinfo
我对 omniauth-google-oauth2
进行了猴子修补,如下所示:
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
现在效果很好.
这篇关于谷歌+API今天关闭,可以用哪个替代认证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2