passport-chaira

1.1.0 • Public • Published

passport-chaira

Build

Passport strategy for authenticating with Chairá using the OAuth 2.0 API.

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

Install

$ npm install passport-chaira

Usage

Configure Strategy

The Chairá authentication strategy authenticates users using a Chairá account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

var ChairaStrategy = require('passport-chaira').Strategy;
 
passport.use(new ChairaStrategy({
    clientID: CHAIRA_CLIENT_ID,
    clientSecret: CHAIRA_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/chaira/callback",
    state: true
  },
  function(accessToken, refreshToken, profile, cb) {
    console.log(accessToken, profile);
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

Keep in mind you also need to enable the express-session middleware for Chairá's state verification to work correctly

Support

This software is provided to you as open source, free of charge. The time and effort to develop and maintain this project is dedicated by @cdiaz.

License

The MIT License

Package Sidebar

Install

npm i passport-chaira

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

9.53 kB

Total Files

7

Last publish

Collaborators

  • cdiaz