node.js - Passport.js 中的 Google 策略是否随着 Google+ 的结束而弃用

标签 node.js passport.js google-plus google-signin

我在我的 nodejs 应用程序中使用 Passport.js 和 passport-google-oauth20 来使用“谷歌策略”进行身份验证。 我刚刚收到一封来自 Google 的电子邮件,表明我使用了 Google+ API 中的“plus.people.get”,并且它将被弃用。 我应该改变什么吗?我不直接使用这个 API 调用,但也许 Passport 可以?

最佳答案

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

如果您在 https://console.developers.google.com/apis/dashboard 上从 Google 控制台禁用 Google+ API 集成那么使用 Google 登录将不适用于您的应用程序。从 Google 收到的错误消息包含以下消息:

GooglePlusAPIError: Access Not Configured. Google+ API has not been used in project xxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/plus.googleapis.com/overview?project=xxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

为了让您的应用程序在禁用 Google+ API 的情况下正常工作,您必须使用此策略选项:

userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
就像在这个例子中:
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) {
           ...
  }
));

关于node.js - Passport.js 中的 Google 策略是否随着 Google+ 的结束而弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53887010/

相关文章:

Node.js 每个用户一个 session

javascript - 使用 Passport.js 和 Sequelize 引用多个模型

android - Google plus 和 twitter 应用程序在 Android 上打开链接的位置

javascript - NodeJS 将图像流转换为 base64 给出无效数据

node.js - 如何从在 docker 容器中运行的应用程序连接在我的机器上运行的 redis

node.js - Passport-ldapauth 获取嵌套组

google-plus - Google Plus 开放图错误 : G+ doesn't recognize open graph image when UTM or other query string appended to URL

ruby - 尝试获取 Google Plus 对某项事件的评论

node.js - node.js 真的没有优化对 [].slice.call(arguments) 的调用吗?

javascript - fs.writeFileSync 为错误 :UNKNOWN, 提供了在 nodejs 中进行同步文件写入的正确方法