Проведя попытку реализовать паспортную стратегию для токена google неудачно, я решил написать его сам, используя клиентскую библиотеку Nodejs для Google API. Я передаю accesstoken из angularjs в запросе $ http и хочу вернуть зарегистрированного пользователя на вызов после аутентификации на стороне сервера. У меня возникли проблемы с передачей подписанного пользователя пользователю req, поэтому я могу передать его следующему промежуточному программному обеспечению. Любая помощь будет оценена.Экспресс Манипулирование объекта req для перехода к следующему промежуточному программному обеспечению
**express code**
маршрутизатор
var gCtrl = require('./googleController.js');
app.post('/auth/google/accesstoken',
function (req, res) {
console.log('Im in the google auth middleware');
//below line is not returning the gUser so I can pass it to the next middleware
var gUser=gCtrl(req.token);
res.send(gUser);
},
function(req,res){
//do something with authenticated user
}
);
gCtrl модуль, который делает API вызов Google
var ubCust = require('../models/ubCust.js');
var bodyParser = require('body-parser');
var google=require('googleapis');
var plus = google.plus('v1');
var OAuth2 = google.auth.OAuth2;
var oauth2client = new OAuth2('1094664898379-8u0muh9eme8nnvp95dafuc3rvigu4j9u.apps.googleusercontent.com','KQ_vNDaZzTvXDdsfgp5jqeZW','http://localhost:3000/auth/google/callback');
module.exports = function(acc_token){
//console.log(acc_token);
oauth2client.setCredentials({
access_token : acc_token
//refresh_token: token.refresh_token
});
plus.people.get({
userId:'me',
auth:oauth2client
},function(err,response){
if (err)
throw err;
//console.log('google user',response);
return response;
});
};
Имеет ли req.token значение? –