首页 > 解决方案 > 对于 Google+ API 和 OAuth 关闭,我需要进行哪些更改?

问题描述

我收到了一封来自 Google 的电子邮件,其中包含以下内容:

您好 Google+ 开发者,

下面的电子邮件包含您最近使用的 Google+ API。注意:它包括 Google+ OAuth 范围请求,这些请求也会受到 Google+ 关闭的影响。之前发送给活动 API 调用者的电子邮件未包含有关 OAuth 请求的信息。最终的提醒电子邮件将在 2 月份发送给仍有活跃 API 或 OAuth 请求活动的用户。

我需要知道什么?

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

我需要做什么?

请在 2019 年 3 月 7 日之前更新您的下列项目,并确保它们不再使用 Google+ API 或请求 Google+ OAuth 范围。下面的数据显示了您的项目最近调用了哪些 Google+ API 方法,以及它请求的 Google+ OAuth 范围。

注意:如果您看到对 people.get 的调用,这可能是在您的应用程序中使用 Google+ 登录功能的结果,该功能现已完全弃用并正在关闭。开发人员应该从 Google+ 登录功能迁移到更全面的 Google 登录身份验证系统。

| Project   | Google+ API Name  | Version | Method or OAuth ScopeA |   
|   A       | plus              | v1      | plus.people.get        |
|   B       | plus              | v1      | plus.people.get        |

我正在为谷歌使用护照和这个插件,以避免为用户存储密码。但我也需要电子邮件地址。我试图只使用email范围,但这不起作用,所以这就是我同时使用两个范围的原因。这是一个片段,我是如何使用它的:

我请求两个范围,这是它的片段:

const express = require('express');
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;

const app = exprress();
auth(passport);
app.use(passport.initialize());
const auth = function (passport) = {
    passport.serializeUser((user, done) => {
        done(null, user);
    });
    passport.deserializeUser((user, done) => {
        done(null, user);
    });
    passport.use(new GoogleStrategy({
            clientID: CLIENT_ID,
            clientSecret: CLIENT_SECRET,
            callbackURL: CALLBACK_URL
        },
        (token, refreshToken, profile, done) => {
            return done(null, {
                profile: profile,
                token: token
            });
        }));
};
app.get('/auth/google', passport.authenticate('google', {
    scope: ['profile', 'email']
}));

所以现在我有点困惑,因为我不使用plus.people.get范围。甚至在此文档页面上,他们也建议使用profileemail. 那为什么我会收到电子邮件?

标签: oauth-2.0google-apipassport.jsgoogle-plus

解决方案


问题不在于您使用plus.profile 范围,而在于该库使用 HTTP端点plus.people.get获取配置文件信息。即使您没有使用plus范围,三年前的最佳实践是使用 plus 端点来获取配置文件信息。

有一个拉取请求会更改所使用的端点。我不清楚为什么它没有被合并,但应该很快。

同时,您还可以在userProfileURL创建GoogleStrategy对象时在配置的属性中指定端点。所以该代码可能看起来像

passport.use(new GoogleStrategy({
        clientID: CLIENT_ID,
        clientSecret: CLIENT_SECRET,
        callbackURL: CALLBACK_URL,
        userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
    },
    (token, refreshToken, profile, done) => {
        return done(null, {
            profile: profile,
            token: token
        });
    }));

还有另一个模块使用 OpenID(Google 支持)来获取配置文件信息。您可能希望切换到这个,因为它似乎受支持。


推荐阅读