NVandenBossche / salesforce-iam-flows

Node.js application that implements some of the most common SAML and OAuth flows in Salesforce.
37 stars 22 forks source link
cta heroku salesforce saml

Salesforce SAML and OAuth 2.0 authorization flows using Node.js

This application is an example implementation in Node.js of the different SAML and OAuth flows that are supported by Salesforce. Please leverage this repository as learning material, rather than something to be used in production.

Introduction

When I was preparing for the Salesforce Certified Technical Architect (CTA) certification, Identity & Access Management (IAM) was one of the topics I struggled with. Mainly because I hadn't come into contact with it frequently during any projects I'd worked on.

I knew how to set up Single Sign-On (SSO), but that didn't compare to understanding the more delicate complexities of the different OAuth flows. So I started diving into this topic in detail.

There were two resources that were invaluable to me:

  1. A very lengthy conversation about different IAM topics with Lawrence Newcombe. Lawrence has actually taken the outcome of these discussions and created very clear diagrams from them on his personal blog.
  2. A blog post about a Node.js application implementing the JWT OAuth flow by Jitendra Zaa.

At first, I expanded upon Jitendra's work by adding the flows I struggled with most. After passing the CTA board, I wanted to build it out further to include the majority of OAuth flows so that others could also learn from it.

It took a while but I've finally built it.

Video walkthrough

!! This video is outdated - planning to update soon

You can find a video walkthrough of how to install and set up the application on your personal Heroku environment. Click the below image to launch the video on Youtube.

Video walkthrough

Steps to run

Step-by-step instructions on how to get the application up and running.

You can run this application locally via Node.js or on Heroku.

Prerequisites

Create a Heroku account if you don't already have one.

If you want to run the application locally, install the Heroku CLI.

Step 1

Step 1.1 Generate your own private key and public certificate

For some of the OAuth flows, we'll need a public certificate (or public key) and upload it to the Connected App.

We'll either need to generate our own public & private key, or you can use the ones in this repository. Both keys are stored in the root folder:

To generate your own private key and public certificate, follow these steps

Step 1.2 Create Connected App

Create a Connected App in your Salesforce org. The Connected App should have the following settings:

Step 1.3 - Set Connected App Policies

From the newly created Connected App, click 'Manage', then 'Edit Policies'. Under 'OAuth Policies', selected 'Admin approved users are pre-authorized' for 'Permitted Users'.

After saving, add the correct profile of your user or add a permission set that is assigned to your user.

Step 2

Option 1 - Deploying to Heroku

Deploy

Option 2 - Running locally

Step 3

Navigate to your app, either on Heroku or locally (via https://localhost:8081). Go to the flow you're interested in, read the description and click the Launch button to execute.