2017-02-28 215 views
1

我在我的應用程序集成的護照ID連接(https://github.com/jaredhanson/passport-openidconnect)成功的NodeJS +快遞+ OpenID支持重定向連接到根

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'))) 

我發送認證後的靜態內容,但快遞不能重定向到安全區域。 不幸的是,我的聯邦提供商無法接受與「http://HOST:PORT/」不同的重定向網址,換句話說,重定向網址位於根目錄(callbackURL:「http://MYRETURNURL:5000」)。

如何表示請發送靜態內容?

回答

1

解決了自己

第一步:安裝OpenID的連接

$ npm install passport-openidconnect --save 

第二步:在app.js

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; 

第三步配置startegy

:路由配置

//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'))); 
+0

很好..完成 – Stefano