是否已在Google+结束时弃用Passport.js中的Google策略

jta*_*tag 12 node.js google-plus passport.js google-signin

我在我的nodejs aplication中使用Passport.js和passport-google-oauth20进行"Google策略"身份验证.我刚收到Google发来的电子邮件,表示我使用了Google+ API中的"plus.people.get",并且不推荐使用该电子邮件.我应该改变什么吗?我不直接使用这个API调用,但也许Passport呢?

Vas*_*kas 24

是的,Passport的Google OAuth策略目前使用Google+ API端点来检索用户的个人资料信息.

如果您通过https://console.developers.google.com/apis/dashboard从Google控制台停用Google+ API集成,那么使用Google登录将无法用于您的应用.从Google收到的错误包含以下消息:

GooglePlusAPIError:未配置访问权限.Google+ API尚未在项目xxxxxx中使用之前或已被禁用.通过访问https://console.developers.google.com/apis/api/plus.googleapis.com/overview?project=xxxxxx启用它,然后重试.如果您最近启用了此API,请等待几分钟,以便将操作传播到我们的系统并重试.

为了使您的应用程序能够正常使用Google+ API,您必须使用此策略选项:

userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
Run Code Online (Sandbox Code Playgroud) 像在这个例子中:
var GoogleStrategy = require('passport-google-oauth20').Strategy;

passport.use(new GoogleStrategy({
    clientID: GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: "http://www.example.com/auth/google/callback",
    userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
  },
  function(accessToken, refreshToken, profile, cb) {
           ...
  }
));
Run Code Online (Sandbox Code Playgroud)

  • 救命!该解决方案也适用于```passport-google-oauth``` (2认同)