【问题标题】:Nodejs + express + OpenId connect with redirect to rootNodejs + express + OpenId 连接并重定向到 root
【发布时间】:2017-03-01 16:18:59
【问题描述】:

我已成功在我的应用中集成 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')))

我必须在认证后发送静态内容,但快递无法重定向到安全区域。 不幸的是,我的联合提供商不能接受不同于“http://HOST:PORT/”的重定向 url,换句话说,重定向必须位于根目录(callbackURL:“http://MYRETURNURL:5000”)。

如何表达请发静态内容?

【问题讨论】:

    标签: node.js express redirect openid-connect


    【解决方案1】:

    自己解决

    第一步:安装openid-connect

    $ npm install passport-openidconnect --save
    

    Step2:配置startegy

    在 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;
    

    Step3:配置路由

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

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多