我已成功将Passport OpenId Connect(https://github.com/jaredhanson/passport-openidconnect)集成到我的应用程序中
passport.use('provider', new OICStrategy({
issuer: "https://fssfed.stage.ge.com/fss",
authorizationURL : "https://MYFEDERATIONURL/authorization.oauth2",
tokenURL : "https://MYFEDERATIONURL/token.oauth2",
userInfoURL : "https://MYFEDERATIONURL/userinfo.openid",
callbackURL : "http://MYRETURNURL:5000",
clientID: "MYSECRET",
clientSecret: "MYPASSWORD"
},
function(accessToken, refreshToken, profile, done) {
console.log(accessToken);
console.log(refreshToken);
console.log("profile:")
console.log(profile);
console.log(done);
return done(null, profile);
}
));
和
app.use('/', function(req, res, next) {
console.log(req.url + " " + req.isAuthenticated());
if (req.isAuthenticated()) {
/*** HOW TO REDIRECT TO****/
} else {
next();
}
},passport.authenticate('provider'));
app.use('/secure',express.static(path.join(__dirname, process.env['base-dir'] ? process.env['base-dir'] : '../public')))
我必须在身份验证后发送静态内容,但express不能重定向到安全区域。 遗憾的是,我的联盟提供商无法接受与“http://HOST:PORT/”不同的重定向网址,换句话说,重定向位于根网址(callbackURL:“http://MYRETURNURL:5000”)。
如何表达请发送静态内容?
答案 0 :(得分:1)
由我自己解决
$ npm install passport-openidconnect --save
passport.use('provider', new OICStrategy({
issuer: "https://fssfed.stage.ge.com/fss",
authorizationURL : "https://MYFEDERATIONURL/authorization.oauth2",
tokenURL : "https://MYFEDERATIONURL/token.oauth2",
userInfoURL : "https://MYFEDERATIONURL/userinfo.openid",
callbackURL : "http://MYRETURNURL:5000",
clientID: "MYSECRET",
clientSecret: "MYPASSWORD"
},
function(accessToken, refreshToken, profile, done) {
return done(null, profile);
}
));
var OICStrategy = require('passport-openidconnect').Strategy;
//logout route
app.get('/login',passport.authenticate('provider', {noredirect: false}));
app.get('/authorize',passport.authenticate('provider', {noredirect: false}),
function (req, res, next) {
res.redirect('/');
});
app.use('/',
function(req, res, next) {
console.log(req.url + " " + req.isAuthenticated());
if (req.isAuthenticated()) {
next();
} else {
res.redirect('/login');
}
},
express.static(path.join(__dirname, process.env['base-dir'] ? process.env['base-dir'] : '../public')));