let fs = require("fs"),
  passport = require("passport"),
  SamlStrategy = require("passport-saml").Strategy;
passport.serializeUser(function (user, done) {
  done(null, user);
});
passport.deserializeUser(function (user, done) {
  done(null, user);
});

passport.use(
  new SamlStrategy(
    {
      entryPoint: "https://sso.satitm.chula.ac.th/adfs/ls",
      issuer: "https://localhost:3000",
      callbackUrl: "https://localhost:3000/selfservice/activedirectory/postResponse",
      privateKey: fs.readFileSync("adfs_connect/urn_satitm_sso_selfservice.key", "utf-8"),
      acceptedClockSkewMs: -1,
      identifierFormat: null,
      signatureAlgorithm: "sha256",
      racComparison: "exact",
    },
    function (profile, done) {
      console.log("profile", profile);
      let user = profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"];
      return done(null, {
        username: profile["username"],
        first_name: profile["first_name"],
        last_name: profile["last_name"],
        org_unit: profile["org_unit"],
      });
    }
  )
);

module.exports = passport;