passport-cloudron

passport-cloudron

Name Last Update
.gitignore Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
index.js Loading commit data...
logo.png Loading commit data...
logo.svg Loading commit data...
package.json Loading commit data...

passport-cloudron

Passport strategy for authenticating with Cloudron using the OAuth API.

This module lets you authenticate using a Cloudron in your Node.js applications through the Passport library.

Install

$ npm install passport-cloudron

Usage

var CloudronStrategy = require('passport-cloudron');

Configure Strategy

The Cloudron authentication strategy authenticates users using a Cloudron account and OAuth tokens. The strategy requires a verify callback, which receives the access token and corresponding secret as arguments, as well as profile which contains the authenticated user's Cloudron profile. The verify callback must call done providing a user to complete authentication.

In order to identify your application to the Cloudron, specify the clientID and clientSecret within options. These values are picked up automatically from the environment variables when using the oauth addon, so usually you don't have to provide them explicitly. See the addon documentation page for more information.

passport.use(new CloudronStrategy({
    callbackURL: process.env.APP_ORIGIN + '/auth/done'
  },
  function verify(token, tokenSecret, profile, done) {
    User.findOrCreate({ id: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/cloudron',
    passport.authenticate('cloudron'));

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