Skip to content

How to use with Auth0

Rlok edited this page Sep 23, 2022 · 1 revision

How to use with Auth0

Who is Auth0?

Auth0 is an easy to implement, adaptable authentication and authorization platform

It can serve as an identity and/or service provider for SAML federation.

Preparation

  1. Firstly you have to create a developer account on Auth0 and create your application.

    Navigate to the Applications page by the left menu.

    image

  2. Click "Create Application", choose the "Regular Web Applications" and type your App name.

    image

  3. Your application is now ready to use like this.

    Screenshot 2022-09-13 at 3 25 36 PM

  4. Switch to the "Addons" tab and turn on "SAML2".

    Screenshot 2022-09-13 at 5 27 22 PM

  5. A popup window will show up with all information we needed.

    • Issuer - issuer of the config parameter
    • Identity Provider Certificate - cert of the config parameter, that is a .pem file
    • Identity Provider Login URL - entryPoint of the config parameter

    Screenshot 2022-09-13 at 5 33 23 PM

Configure strategy

const SamlStrategy = require('passport-saml').Strategy;
const fs = require('fs');
[...]

passport.use(
  new SamlStrategy(
    {
      path: "/login/callback",
      entryPoint: "place_your_Identity_Provider_Login_URL_here",
      issuer: "place_your_Issuer_here",
      cert: fs.readFileSync('./path_to_your_downloaded_Identity_Provider_Certificate_file.pem', "utf-8"), // cert must be provided
    },
    function (profile, done) {
      // for signon
      findByEmail(profile.email, function (err, user) {
        if (err) {
          return done(err);
        }
        return done(null, user);
      });
    },
    function (profile, done) {
      // for logout
      findByNameID(profile.nameID, function (err, user) {
        if (err) {
          return done(err);
        }
        return done(null, user);
      });
    }
  )
);