Okta is one of the major player (see Gartner magic quadrant) these days in market offering Identity Management Service. You can easily plugin OKTA with active directory of your company to identify legit user. Salesforce integration with OKTA is fairly easy and straightforward so as Heorku. But while building a custom SAML support for Node.Js I couldn't find much support, later with some research we found saml integration to be straightforward without passport, but you can see passportJS saml authentication via heroku platform here as well

I have written a boiler-plate code covering any node application with OKTA layer with SAML (2.0), you can fork this code, add you code in it and simply provide okta layer on top your application. So lets get started on this

For node, I am considering express as my framework to build facade for my application and relying on passport to provide SAML backbone flow architecture. Lets being by building package.json and list all our dependencies

Node makes application development hell lot easier and on top of the Express make it fun to quick spin up application. In this article we will be discussing routing mechanism in node.js using Express. I recommend reading express documentation on routing which are self-explanatory, but here is quick example routing in Node.js

Let begin by creating a user database, I have added sample json you can also generate sample json here

Nodemon - I used nodemon for this example, I recommend using nodemon for your node application to monitor your node changes, lets generate our package.json. In here I created index.js as landing page for our application

In this article we will be implementing authentication via Heroku in a Node.js web application. For this we'll be using Passport, an authentication middleware for Node.js for heroku. Since passport provides multiple flavors for varied applications, we will use passport-heroku .

Express Web Apps

Install Node.js first on your machine, You will also require Express, a framework for building web application on Node.js. Lets being by install following command in your terminal

Implementing Heroku Authentication

Once package is downloaded then lets design auth.html, I used materializecss, for implementing this a better layout.

We want our default route to serve this HTML page. In app.js there is already a route for /. Modify that route to serve this file as shown in the following code sample. Once this is done, restart the Node server and refresh your browser, and you should see this page.

process.nextTick() behaves much like setTimeout(). For more detailed info, take a look here. In the callback, we call done() with the user’s profile if they exist, or false otherwiseThe next step is to set up routes for handling the Heroku authentication:

When an authentication succeeds, a session is established and is maintained via a cookie. Passport will need to serialize and deserialize user instances to support sessions. Therefore, serializeUser and deserializeUser callbacks are also required.

About me

Hi. I’m Enterprise Architect (IT) at Intuitive Surgical Inc , building worlds smartest and largest surgical robots and binding business systems with cloud. I’m Founder of OyeCode. I have worked with Salesforce.com as Technical Architect (HQ) in San Francisco and designed/developed the cutting edge Salesforce Product Trailhead . I enjoy development on Salesforce, Heroku, Rails and other cloud based platform