Node.js 使用passport+;古格里皮斯

Node.js 使用passport+;古格里皮斯,node.js,google-api,passport.js,Node.js,Google Api,Passport.js,我正在使用Node.js尝试使用GoogleBooksAPI和passport以及Google认证策略制作一个图书库应用程序。到目前为止,我可以验证和访问API。现在可能是一个愚蠢的问题,如何让数据返回到我的集合视图中使用?在验证之后,我可以访问Google数据,然后我需要重定向到集合,但是如何将该数据构建到我的新视图中 app.get('/auth/google', passport.authenticate('google', { scope: ['https://www.googlea

我正在使用Node.js尝试使用GoogleBooksAPI和passport以及Google认证策略制作一个图书库应用程序。到目前为止,我可以验证和访问API。现在可能是一个愚蠢的问题,如何让数据返回到我的集合视图中使用?在验证之后,我可以访问Google数据,然后我需要重定向到集合,但是如何将该数据构建到我的新视图中

app.get('/auth/google', passport.authenticate('google', {
  scope: ['https://www.googleapis.com/auth/books', 'https://www.googleapis.com/auth/userinfo.profile']
}));

app.get('/auth/google/callback', passport.authenticate('google', {failureRedirect: '/'}), function (req, res) {
  // Successful authentication, get data and redirect to user collection
  googleapis.discover('books', 'v1').execute(function (err, client) {
    oath2Client.credentials = {
      access_token: req.user.accessToken,
      refresh_token: req.user.refreshToken
    };
    var req1 = client.books.mylibrary.bookshelves.list().withAuthClient(oath2Client);
    req1.execute(function (err, bookshelves) {});
  });
  res.redirect('/collection');
});

app.get('/collection', routes.collection, function (req, res) {});

您可以做的是将数据存储在会话变量中,然后从另一个路由获取数据。下面是一个存储字符串并从另一个页面访问它的示例:

//enable session support
app.use(express.cookieParser());
app.use(express.session({
  secret: 'secret key for signed cookies'
}));

app.get('/foo', function(req, res) {
  req.session.property = 'property value';
  res.redirect('/bar');
});

app.get('/bar', function(req, res) {
  //the session variables can be accessed here too
  res.send(req.session.property);
});

完美的我今天到家后会试试的。