title: SSO nodeJs Azure AD
body: <p>I am trying to set up SSO (SAML) with azure AD using nodeJS. I have been given some information from the company I am working with. They are basically wanting to host my site on there internal site, and have it authenticate there users using there db. I was given some info,(tenantID, user access URL, application ID and object ID along with a metadata file) I haven't been able to find anything helpful online, and this is my first time trying to do this. please let me know if anyone can help! Thanks in advance! my code is below :)</p>
  <pre><code>var SamlStrategy = require('passport-saml').Strategy;
  
  passport.use(new SamlStrategy(
    {
      path: '/login/callback',
      entryPoint: 'https://myapps.microsoft.com/signin/SAML-companyname-DEV/id?tenantId=id
      issuer: 'issuer'
    },
    
  
    function(profile, done) {
      findByEmail(profile.email, function(err, user) {
        if (err) {
          return done(err);
        }
        return done(null, user);
        
      });
    })
  );
  
  app.post('/login/callback',
    function(req, res) {
      console.log('inside /login/callback')
      //after login, goes here, but renders back to login/callback. then back here.
     res.render('login.ejs')
    }
  );
  
  app.get('/login',
    passport.authenticate('saml', { failureRedirect: '/failed-login.ejs', failureFlash: true }),
    function(req, res) {
        console.log(&quot;inside azuread /login passport saml&quot;)
       res.render('index.ejs')
    }
  );
  
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(session(
    {
      resave: true,
      saveUninitialized: true,
      secret: 'test secret'
    }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(express.static(path.join(__dirname, 'views')));
  
  
  // 404 and forward to error handler
  app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
      res.send(err.status)
  });
  </code></pre>