Skip to content

easyauth-io/passport-easyauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Passport-EasyAuth

The EasyAuth authentication strategy for Passport.js, an authentication middleware for Node.js that can be unobtrusively dropped into any Express-based web application.

Getting started

Installation

The EasyAuth Passport strategy is installed with npm.

npm install @easyauth.io/passport-easyauth

Create Strategy

//Strategy.js

const passport = require('passport');
const EasyAuthStrategy = require('passport-easyauth');

passport.use(
  new EasyAuthStrategy(
    {
      discoveryURL: '',
      clientID: '',
      clientSecret: '',
      callbackURL: [''],
    },
    function (tokenset, userinfo, done) {
      done(null, userinfo);
    }
  )
);

Set:

discoveryURL to EasyAuth Tenant URL.

clientID to Registered Client ID of respective EasyAuth Tenant.

clientSecret to Client secret of respective ClientID.

callbackURL to Redirect URL of respective ClientID.

Express Usage

//index.js

app.get(
  "loginURL",
  passport.authenticate("easyauth", { scope: "openid" })
);

app.get(
  "callbackURL",
  passport.authenticate("easyauth", { failureRedirect: "loginURL" }),
  
  //Authentication successful
  (req, res) => {
    res.redirect("protectedURL");
  }
);