Login Route

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

const passport = require("passport");

Now create a login route

app.get(
  "/jhu/login",
  (req, res, next) => {
    next();
  },
  passport.authenticate("samlStrategy")
);

As you see, I've decided to use /jhu/login/ as the login route. It means, when a user tries to access a protected resource, I will redirect them to this route. Here, we must again redirect the user to JHU SSO (send the authentication XML request along with it). Normally, it would look like this:

app.get("/jhu/login", (req, res) => {
    // build the authentication request XML
    // redirect the user to JHU SSO with the request XML
});

But instead we are delegating that process to passport library by calling next() in the first callback function where next is the "next" callback: passport.authenticate("samlStrategy").

Diff
diff --git a/code/index.js b/code/index.js
index f2c2481..acb9c69 100644
--- a/code/index.js
+++ b/code/index.js
@@ -1,4 +1,5 @@
 const express = require("express");
+const passport = require("passport");
 
 // Initialize express.
 const app = express();
@@ -11,6 +12,15 @@ app.get("/", (req, res) => {
   res.send("Test Home Page!");
 });
 
+// login route
+app.get(
+  "/jhu/login",
+  (req, res, next) => {
+    next();
+  },
+  passport.authenticate("samlStrategy")
+);
+
 // Start the server.
 app.listen(port, () => {
   console.log(`Listening on http://localhost:${port}/`);