# oauth2-mini

> OAuth2 mini server

Latest version **1.1.4** (published 2017-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install oauth2-mini
pnpm add oauth2-mini
yarn add oauth2-mini
bun add oauth2-mini
```

## 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.1.4 |
| Published | 2017-07-24 |
| First published | 2017-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | yupk |
| Maintainers | yupk |
| Keywords | oauth2 |

## Links

- npm: https://www.npmjs.com/package/oauth2-mini
- Repository: https://github.com/yupkey/oauth2-mini
- Homepage: https://github.com/yupkey/oauth2-mini#readme
- Issues: https://github.com/yupkey/oauth2-mini/issues
- npm.io page: https://npm.io/package/oauth2-mini

## Dependencies (1)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^7.4.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2017-07-24
- 1.1.3 — 2017-07-21
- 1.1.2 — 2017-07-21
- 1.1.1 — 2017-07-21
- 1.1.0 — 2017-07-20
- 1.0.7 — 2017-07-20
- 1.0.6 — 2017-07-18
- 1.0.5 — 2017-07-18
- 1.0.4 — 2017-07-18
- 1.0.3 — 2017-07-17
- 1.0.2 — 2017-07-17
- 1.0.1 — 2017-07-17
- 1.0.0 — 2017-07-17

## README

# oauth2-mini

OAuth2 mini server

## Instalation
`npm install oauth2-mini`


## Examples
```javascript
const OAuthServer = require('oauth2-mini');
const userAuthentication = require('./user-authentication');

app.oauth = new OAuthServer(userAuthentication);

//expecting header `Authorization: Basic <base64(login:password)>`
app.all('/token', app.oauth.authenticate());

//expecting header `Authorization: Bearer <accesssToken>`
app.use('/api', app.oauth.authorise(), (req, res) => {
  res.json({message: 'Welcome to API'});
});

app.use(app.oauth.errorHandler());

```

It's required to write own class to authenticate the user and check the token

User authentication example code:
```javascript
const jwt = require('jsonwebtoken');

class UserAuthentication {
  constructor() {
    /**
     * secretKey and jwtOptions are used to generate your access token
     * Read more here: https://www.npmjs.com/package/jsonwebtoken
     */
    this.secretKey = 'your-secret-key';
    this.jwtOptions = { expiresIn: 60 * 60 }; // default: null
  }
  checkUserCredentials(username, password, success, error) {
    //check credentials here
    if (username === 'username' && password === 'password') {
      success();
    } else {
      error('Invalid credentials');
    }
  }
  checkAccessToken(accessToken, success, error) {
    //check access token here
    jwt.verify(accessToken, this.secretKey, (err, decoded) => {
      if (err) {
        error(err);
      } else {
        success();
      }
    });
  }
  saveAccessToken(accessToken, success, error) {
    //save access token to your DB here
  }
}

module.exports = new UserAuthentication();
```

### Thanks for the tips :)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BXKSVNWW9A6Q2)

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