3.2.0 • Published 5 years ago

wedeploy-middleware v3.2.0

Weekly downloads
28
License
MIT
Repository
github
Last release
5 years ago

wedeploy-middleware

Build Status npm version

Auth

Node.js middleware to help users to authenticate using passwords, popular federated identity providers like Google, Facebook, GitHub, and more using WeDeploy™ Auth.

How it works - For every request intercepted by the auth middleware a token or credential may be extracted in the following order:

SourceKey
Basic Authenticationcurl -u "username:password" "https://api.wedeploy.io/"
OAuth2 Token (header)curl -H "Authorization: Bearer TOKEN" "https://api.wedeploy.io/"
OAuth2 Token (query string)curl "https://api.wedeploy.io/?access_token=TOKEN"
OAuth2 Token (cookie)curl -H "Cookie:access_token=TOKEN" "https://api.wedeploy.io/"

Installation

$ npm install wedeploy-middleware

API

var express = require('express');
var wedeployMiddleware = require('wedeploy-middleware');

var app = express();
app.use(wedeployMiddleware.auth({url: 'auth.project.wedeploy.io'}));

wedeployMiddleware.auth(options)

  • options.url authorization service url passed to WeDeploy.auth(url).
  • options.redirect optional url to redirect on authentication failure, e.g. /login.
  • options.scopes optional authorization scopes.
  • options.scopesOr optional boolean, if true, users need only one passed in scope to be authorized
  • options.authorizationError optional authorization error response body, e.g. {status: 401, message: 'Unauthorized'}.
  • options.unauthorizedOnly optional check ensuring that there's no logged user for the current route, e.g. true.

Examples

Basic usage

var express = require('express');
var wedeployMiddleware = require('wedeploy-middleware');

var app = express();
app.use(wedeployMiddleware.auth({url: 'auth.project.wedeploy.io'}));

app.get('/private', function(req, res) {
  // User that has been signed in
  console.log('User: ', res.locals.auth.currentUser);
});

app.listen(8080);

Authenticating with scopes

var express = require('express');
var wedeployMiddleware = require('wedeploy-middleware');

var app = express();

var authMiddleware = wedeployMiddleware.auth({
  url: 'auth.project.wedeploy.io',
  scopes: ['superuser', 'manager']
});

app.get('/admin', authMiddleware, function(req, res) {
  // User that has been signed in
  console.log('User: ', res.locals.auth.currentUser);
});

app.listen(8080);
// curl http://localhost:8080/private -H 'Authorization: Bearer token' -v
// curl http://localhost:8080/private -H 'Authorization: Basic dXNlcjpwYXNz' -v

MIT Licensed

3.2.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.7.0

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago