# jscda-jwt

> JWT plugin for js-core-data-app

Latest version **0.0.7** (published 2017-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install jscda-jwt
pnpm add jscda-jwt
yarn add jscda-jwt
bun add jscda-jwt
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2017-12-10 |
| First published | 2017-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | jakub.knejzlik |

## Links

- npm: https://www.npmjs.com/package/jscda-jwt
- Repository: https://github.com/js-core-data-app/jscda-jwt
- Homepage: https://github.com/js-core-data-app/jscda-jwt#readme
- Issues: https://github.com/js-core-data-app/jscda-jwt/issues
- npm.io page: https://npm.io/package/jscda-jwt

## Dependencies (4)

- [express](https://npm.io/package/express.md) ^4.16.2
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [http-errors](https://npm.io/package/http-errors.md) ^1.6.2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.1.0

## Recent versions

- 0.0.7 (latest) — 2017-12-10
- 0.0.6 — 2017-11-29
- 0.0.5 — 2017-11-29
- 0.0.4 — 2017-11-29

## README

# jscda-jwt

JWT plugin for js-core-data-app

[![Build Status](https://travis-ci.org/js-core-data/jscda-jwt.svg?branch=master)](https://travis-ci.org/js-core-data/jscda-jwt)

# Example

For js-core-data-app middleware

```
module.exports = app => {

    // get JWT payload
    app.use((req, res, next) => {
        app.locals
            .getJWT(req)
            .then(result => {
                res.send(result);
            })
            .catch(next);
    });

    // validate token permissions
    app.use((req, res, next) => {
        api.locals
            .checkJWTPermissions(req, 'resource_name_to_validate')
            .then(result => {
                if (!result) {
                    return res.status(403).send('forbidden')
                }
                next()
            })
            .catch(next);
    });
}
```

## JWT Permissions

To be able to control access, you can simply add `permissions` to JWT payload.
Example content (rule per line):

```
allow|* //allow access to every resource
allow|foo:test:aaa // allow access to secfootion:test:aaa
allow|foo:*:a* // allow access to foo:any:a, foo:any:ab, foo:any:abcdefg...
deny|blah* // deny access to blah, blahany, ...
```

Rules can be combined with presumption of denial.

```
allow|blah*
deny|blah:test*

...
"foo" -> false
"blah" -> true
"blahadfsdf" -> true
"blah:test" -> false
"blah:testadfadf" -> false
```

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