Code Monkey home page Code Monkey logo

passportjs-saml2-poc's Introduction

A PassportJS SAML 2.0 POC

Quick Start

• Configure your SP /login/callback enpoint in your IdP • Provide the environment variables for your IdP and run the SP app as shown below (OneLogin used in this example)

export SAML2_ISSUER='https://app.onelogin.com/saml/metadata/46......-d0..-49..-99..-7b..........' && \
export SAML2_SSO_ENTRYPOINT='https:/my-app.onelogin.com/trust/saml2/http-post/sso/46......-d0..-49..-99..-7b..........' && \
export SAML2_CERT='MII....................................................................................FKA==' && \
node index.js

• Go to an incognito window to make sure you always go through the full SAML 2.0 scenario: Hit your publicly available app url (use ngrok to expose a local running server) Since in incognito window there will be no current session, the user will not be authenticated and will be redirected to the IdP login form. Once authenticated the IdP redirects the user back to /login/callback where passport saml 2.0 implementation will assert that the user is indeed authenticated using the SAML issuer, SSO endpoint and certificates provided in environment vars. Finally when confirmed it will show a message comming from index.html to the user. Here is the console output for that user journey:

app listening on port 3000
Not authenticated
{"issuer":"https://app.onelogin.com/saml/metadata/46......-d0..-49..-99..-7b..........","sessionIndex":"_871052f2-4b45-4981-b08c-493d031e8cf1","nameID":"[email protected]","nameIDFormat":"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress","email":"[email protected]"}
Authenticated

OneLogin example

  • In the SP app add a user that should be forced to login via SSO
  • In the IdP (OnleLogin) add a new app of type "SAML Custom Connector (Advanced)"
  • In the IdP app settings set the "ACS (Consumer) URL Validator" with a regex that identifies the URL from the SP that the user will use to land into the SP.
  • In the IdP app settings set the "ACS (Consumer) URL" add the precise callback URL from the SP that the user will use to land into the SP.
  • In the IdP app settings, section parameters add the email as a custom field.
  • In the SP app configure for the user the usage of SSO by supplying the X.509 Certificate details, the SAML 2.0 Endpoint (HTTP), and the Issuer URL from the OneLogin app configuration SSO section.
  • Go to /login page in SP, provide email and the user should be redirected to the OneLogin IdP where after login should land back into the SP already logged in.

Setup

  1. In your IdP (OneLogin offers free accounts to test this) create an app of type SAML. This is the Identity Provider (IdP).
  2. install ngrok locally and point to your application.
./ngrok http localhost:3000
  1. Run your application as explained in the Quick Start section. The app uses PassportJS with a SAML 2.0 Strategy to provide authentication via the IdP. This PassportJS related code is what is called the Service Provider (SP).
  2. Point the IdP ACS (Consumer) URL to the /login/callback endpoint of your app (which contains the SP code) and the ACS (Consumer) URL Validator to the /login/callback endpoint of your app as well, for example:
ACS (Consumer) URL: http://d529-72-28-211-41.ngrok.io/login/callback
ACS (Consumer) URL validator: http://d529-72-28-211-41.ngrok.io/login/callback
  1. Setup the IdP with "SAML initiator = Service Provider"
  2. If needed, setup the IdP to provide the profile.nameID in the SAML payload sent to the SP.
  3. Create a user with same email in the IdP and in the SP
  4. Access the app as explained in the Quick Start section

passportjs-saml2-poc's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.