# express-meshblu-auth

> Express middleware for all meshblu auth styles

Latest version **9.2.1** (published 2017-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-meshblu-auth
pnpm add express-meshblu-auth
yarn add express-meshblu-auth
bun add express-meshblu-auth
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.2.1 |
| Published | 2017-07-26 |
| First published | 2015-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Octoblu |
| Maintainers | octoblu |
| Keywords | meshblu, express |

## Links

- npm: https://www.npmjs.com/package/express-meshblu-auth
- Repository: https://github.com/octoblu/express-meshblu-auth
- Issues: https://github.com/octoblu/express-meshblu-auth/issues
- npm.io page: https://npm.io/package/express-meshblu-auth

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^2.6.1
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [request](https://npm.io/package/request.md) ^2.72.0
- [meshblu-http](https://npm.io/package/meshblu-http.md) ^9.7.2
- [coffee-script](https://npm.io/package/coffee-script.md) ^1.12.4

## Recent versions

- 9.2.1 (latest) — 2017-07-26
- 9.2.0 — 2017-07-26
- 9.1.0 — 2017-03-02
- 9.0.2 — 2017-01-26
- 9.0.1 — 2017-01-26
- 9.0.0 — 2017-01-09
- 8.0.0 — 2017-01-09
- 7.0.0 — 2016-07-06
- 6.0.0 — 2016-05-26
- 5.3.5 — 2016-05-09
- 5.3.4 — 2016-05-09
- 5.3.3 — 2016-05-06
- 1.7.1 — 2016-05-06
- 2.1.2 — 2016-05-06
- 3.1.1 — 2016-05-06
- … 39 more at https://npm.io/package/express-meshblu-auth/versions

## README

# Express Meshblu Authentication Middleware

Express middleware to support all meshblu auth styles

[![Build Status](https://travis-ci.org/octoblu/express-meshblu-auth.svg?branch=master)](https://travis-ci.org/octoblu/express-meshblu-auth) [![Code Climate](https://codeclimate.com/github/octoblu/express-meshblu-auth/badges/gpa.svg)](https://codeclimate.com/github/octoblu/express-meshblu-auth) [![Test Coverage](https://codeclimate.com/github/octoblu/express-meshblu-auth/badges/coverage.svg)](https://codeclimate.com/github/octoblu/express-meshblu-auth) [![npm version](https://badge.fury.io/js/express-meshblu-auth.svg)](http://badge.fury.io/js/express-meshblu-auth) [![Gitter](https://badges.gitter.im/octoblu/help.svg)](https://gitter.im/octoblu/help)

## Supported Auth Methods

* cookies: `request.cookies.meshblu_auth_uuid` and `request.cookies.meshblu_auth_token`
* headers: `request.cookies.meshblu_auth_uuid` and `request.cookies.meshblu_auth_token`
* basic: `Authorization: Basic c3VwZXItcGluazpwaW5raXNoLXB1cnBsZWlzaAo=`
* bearer: `Authorization: Bearer c3VwZXItcGluazpwaW5raXNoLXB1cnBsZWlzaAo=`

## Example:

```javascript
var express = require('express');
var MeshbluAuth = require('express-meshblu-auth');
var meshbluAuth = new MeshbluAuth({
  protocol: 'https',
  server: 'meshblu.octoblu.com',
  port: 443
});

var app = express();
// Retrieves the uuid & token from the request,
// validate them, then add them to request.meshbluAuth
app.use(meshbluAuth.auth());

// Retrieves the uuid & token from the request,
// validate them by retrieving the device, then:
// add credentials to request.meshbluAuth
// add device to request.meshbluDevice
app.use(meshbluAuth.get());

// Returns a 401 if no uuid & token were provided in the request
// Returns a 403 if the uuid & token provided were invalid
// calls next otherwise
// meshbluAuth.auth or meshbluAuth.get MUST BE CALLED FIRST in the middleware chain
app.use(meshbluAuth.gateway());

// Returns a 401 if no uuid & token were provided in the request
// Returns a 403 if the uuid & token provided were invalid
// Returns a 403 if the uuid given does not match the authorized uuid
// calls next otherwise
// meshbluAuth.auth or meshbluAuth.get MUST BE CALLED FIRST in the middleware chain
app.use(meshbluAuth.gatewayDevice('uuid'));

// Can be used instead of gateway. Redirects user if uuid & token were not
// provided or were not valid
app.use(meshbluAuth.gatewayRedirect('/login'));

app.use(function (request, response) {
  response.json({uuid: request.meshbluAuth.uuid, token: request.meshbluAuth.token});
});
app.listen(3333);
```

---
_Source: https://npm.io/package/express-meshblu-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
