1.0.0 • Published 5 years ago

passport-elma v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

passport-elma

Passport strategy for authenticating with ELMA using the OAuth 2.0 API.

This module lets you authenticate using ELMA in your Node.js applications. By plugging into Passport, ELMA authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-elma

Usage

Configure Strategy

const ElmaStrategy = require("passport-elma").Strategy;

passport.use(
  new ElmaStrategy(
    {
      clientID: ELMA_APP_ID,
      clientSecret: ELMA_APP_SECRET,
      callbackURL: "http://localhost:3000/auth/elma/callback"
    },
    function(accessToken, refreshToken, profile, cb) {
      User.findOrCreate({ elmaId: profile.id }, function(err, user) {
        return cb(err, user);
      });
    }
  )
);

Authenticate Requests

Use passport.authenticate(), specifying the 'elma' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get("/auth/elma", passport.authenticate("elma"));

app.get(
  "/auth/elma/callback",
  passport.authenticate("elma", { failureRedirect: "/login" }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect("/");
  }
);

License

The MIT License

Copyright (c) 2019 aleksnick