The SAML Strategy

You may have noticed we used the following middleware in both login and callback routes:

passport.authenticate("samlStrategy"),

Passport-SAML library allows us to configure the samlStrategy object.

Open index.js and add the following to the top of the file

const saml = require("passport-saml");

// Setup SAML strategy
const samlStrategy = new saml.Strategy(
  {
    // config options here
  },
  (profile, done) => {
    return done(null, profile);
  }
);

// Tell passport to use the samlStrategy
passport.use("samlStrategy", samlStrategy);

The saml.Strategy() accepts two arguments:

  • The first is a configuration object, which I left blank for the moment.
  • The second is a function which processes the user.
    • The first argument into the function is a profile object, and the second is done, a callback.
    • For our purposes, we are just executing the callback and sending it the profile object unchanged.
    • If we needed to do more, such as load application specific permissions from a database, this could be done here.
Diff
diff --git a/code/index.js b/code/index.js
index 826206b..4eb9a33 100644
--- a/code/index.js
+++ b/code/index.js
@@ -1,5 +1,19 @@
 const express = require("express");
 const passport = require("passport");
+const saml = require("passport-saml");
+
+// Setup SAML strategy
+const samlStrategy = new saml.Strategy(
+  {
+    // config options here
+  },
+  (profile, done) => {
+    return done(null, profile);
+  }
+);
+
+// Tell passport to use the samlStrategy
+passport.use("samlStrategy", samlStrategy);
 
 // Initialize express.
 const app = express();