[FIXED]:
在我的代码中,我失踪了
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
我正在编写一个演示应用程序来访问microsoft单驱动器 当我访问http://localhost:3000/auth/mslive时,我的应用会将我重定向到使用windows-live进行单点登录
但是,“/ mslive”和“/ mslive / callback”中的回调函数永远不会被命中。 当Windows live尝试重新导向我的应用程序时,我一直收到500错误。 任何想法?
Remote Address:127.0.0.1:3000
Request URL:http://anotherdemoapp.localtest.me:3000/auth/mslive/callback?code=d3f9d642-b013-af4e-e4d0-0cb828554ca5
Request Method:GET
Status Code:500 Internal Server Error
app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var authRoutes = require("./routes/auth");
var app = express();
//// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use("/auth", authRoutes);
auth.js
var express = require('express');
var path = require("path");
var passport = require("passport");
var passportMSLive = require("passport-windowslive");
var app = express();
app.use(passport.initialize());
passport.use(new passportMSLive.Strategy({
clientID: process.env.MSLiveClientID,
clientSecret: process.env.MSLiveClientSecret,
callbackURL: "http://anotherdemoapp.localtest.me:3000/auth/mslive/callback"
},
function (accessToken, refreshToken, profile, done) {
// this callback function will be invoked after successfully login
return done(null, profile);
}
));
// call back
app.get(
"/mslive",
passport.authenticate("windowslive", {
scope: ["wl.offline_access", "wl.contacts_skydrive", "wl.skydrive", "wl.skydrive_update", "wl.signin"]
}),
function (req, res) {
// never enter here
res.send("mslive login");
}
);
app.get(
"/mslive/callback",
passport.authenticate("windowslive", {
failureRedirect: '/mslive/fail'
}),
function (req, res) {
// never enter here
res.send("mslive callback");
}
);
app.get("/mslive/fail", function (req, res) {
// never enter here
res.send("login failed");
});
module.exports = app;