# micro-auth2

> authentication middleware for octane microservices

Latest version **1.6.1** (published 2017-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install micro-auth2
pnpm add micro-auth2
yarn add micro-auth2
bun add micro-auth2
```

## 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 | 1.6.1 |
| Published | 2017-08-15 |
| First published | 2017-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Zak Holt |
| Maintainers | zakjholt |

## Links

- npm: https://www.npmjs.com/package/micro-auth2
- Repository: https://github.com/Zakjholt/micro-auth2
- Homepage: https://github.com/zakjholt/micro-auth2#readme
- Issues: https://github.com/Zakjholt/micro-auth2/issues
- npm.io page: https://npm.io/package/micro-auth2

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.16.2
- [micro](https://npm.io/package/micro.md) ^7.3.3

## Recent versions

- 1.6.1 (latest) — 2017-08-15
- 1.6.0 — 2017-08-15
- 1.5.0 — 2017-07-05
- 1.4.1 — 2017-07-05
- 1.4.0 — 2017-06-28
- 1.3.2 — 2017-06-28
- 1.3.1 — 2017-06-28
- 1.3.0 — 2017-06-28
- 1.2.2 — 2017-06-28
- 1.2.1 — 2017-06-28
- 1.2.0 — 2017-06-28
- 1.1.1 — 2017-06-28
- 1.1.0 — 2017-06-27
- 1.0.4 — 2017-06-27
- 1.0.3 — 2017-06-27
- … 3 more at https://npm.io/package/micro-auth2/versions

## README

<p align="center"><img src='https://raw.githubusercontent.com/Zakjholt/micro-auth2/master/lock.png'></p>
<h2 align="center">micro-auth2</h2>

This is the oauth 2.0 authentication middleware for Octane zeit micro-services. It checks for accessTokens and checks for the token's status and scope, and also makes the user's ID available inside of a req.userData object.

It expects access tokens to be provided in the Authorization header, prepended with 'Bearer'

## Installation
```sh
yarn add micro-auth2
```

## Usage
```javascript
const auth = require('micro-auth2')

module.exports = auth({
    introspectionUrl: '<INTROSPECTION_URL>',
    clientId: '<CLIENT_ID>',
    clientSecret: '<CLIENT_SECRET>'
  })(async (req, res) => {
  return 'Hello World!'
})
```

## Composed with other micro plugins
```javascript
const auth = require('micro-auth2')
const visualize = require('micro-visualize')
const cookieParse = require('micro-cookie')
const { compose } = require('lodash/fp')
const { send } = require('micro')

module.exports = compose(
  auth({
    introspectionUrl: '<INTROSPECTION_URL>',
    clientId: '<CLIENT_ID>',
    clientSecret: '<CLIENT_SECRET>'
  }),
  visualize,
  cookieParse
)(async (req, res) => {
  const { userId, scope } = req.userData
  const responseMessage = {
    message: 'Great! You have been authenticated!',
    userId,
    scope
  }

  send(res, 200, responseMessage)
})
```

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