在 Google 上的操作中与我自己的 OAuth 服务器关联的帐户

Account Linking with my own OAuth server in Actions on Google

我在 google 应用程序上的操作的帐户链接中使用 "OAuth and Google Sign-In" 和 "Authorization code flow"。我已经使用 Passport js 编写了自己的服务器,其中实现了 Google 身份验证并将其部署到 Heroku。 我在浏览器中对其进行了测试,它工作正常并成功提供了访问令牌和刷新令牌,但我面临的问题是当我将它与我在 google 应用程序上的操作集成时它正确执行了身份验证并且没有发送accessToken 回到我的应用程序,我不明白我应该在 "Token URL" 字段中输入什么。下面是服务器的代码。

passport.use(new GoogleStrategy({
    // authorizationURL: 'https://accounts.google.com/o/oauth2/auth',
    // tokenURL: 'https://www.googleapis.com/oauth2/v3/token',
    clientID: keys.googleClientID,
    clientSecret: keys.googleClientSecret,
    callbackURL: '/auth/google/callback'
  },
  (accessToken, refreshToken, profile, done) => {
    return done(null, {
      token: accessToken
    })
  }
));

app.get(
  '/auth/google',
  passport.authenticate('google', {
    scope: ['profile', 'email']
  })
);

app.get('/auth/google/callback',
  passport.authenticate('google', {
    failureRedirect: '/login'
  }),
  function(req, res) {
    console.log(req.user.token)
    res.send(req.user.token)
  });

app.get('/', (req, res) => {
  res.send('<h1>Hello express</h1>');
});

这里是我的 Google 助手应用程序的客户端信息。

虽然我不确定,但您似乎混淆了 授权 URL令牌 URL.

授权 URL 是一种向用户显示登录屏幕并最终重定向到 Google 处的重定向 URI 的授权 URL =24=]授权码.

Google 将获取 授权码 并调用您的 令牌 URL 以获得 授权令牌刷新令牌。稍后,它还将使用此 URL 将 refresh token 交换为新的 auth token.

一般来说,passport.js用于为OAuth服务创建登录界面,这与助手需要的相反。所以不清楚你为什么要使用它。

如果您只是希望用户登录他们的 Google 帐户以获取他们的个人资料和电子邮件,那么您根本还不清楚为什么要使用 OAuth - 您可以使用 Google Sign In for Assistant.

即使您需要额外的范围来访问其他 Google 资源,Google 登录助手也是可行的方法。参见