# @tinyhttp/jwt

> tiny JWT middleware for Node.js

Latest version **2.0.0** (published 2023-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tinyhttp/jwt
pnpm add @tinyhttp/jwt
yarn add @tinyhttp/jwt
bun add @tinyhttp/jwt
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2023-10-27 |
| First published | 2020-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=14.18 \|\| >=16.20 |
| Dependencies | 1 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | BRA1L0R |
| Maintainers | dropthebeatbro |
| Keywords | tinyhttp, nodejs, web, backend, jwt |

## Links

- npm: https://www.npmjs.com/package/@tinyhttp/jwt
- Repository: https://github.com/tinyhttp/jwt
- Homepage: https://github.com/tinyhttp/jwt#readme
- Issues: https://github.com/tinyhttp/jwt/issues
- npm.io page: https://npm.io/package/@tinyhttp/jwt

## Dependencies (1)

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

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2023-10-27
- 0.1.15 (pnpm-temp) — 2020-08-17
- 1.3.1 — 2021-07-04
- 1.3.0 — 2021-04-26
- 1.2.2 — 2021-04-14
- 1.2.1 — 2021-04-02
- 1.2.0 — 2021-02-21
- 1.1.1 — 2021-01-13
- 1.1.0 — 2020-12-21
- 1.0.7 — 2020-12-12
- 1.0.6 — 2020-12-12
- 1.0.5 — 2020-12-11
- 1.0.4 — 2020-12-11
- 1.0.3 — 2020-12-09
- 1.0.2 — 2020-12-09
- … 31 more at https://npm.io/package/@tinyhttp/jwt/versions

## README

<div align="center">

# @tinyhttp/jwt

[![NPM][npm-badge]][npm-url] [![NPM][dl-badge]][npm-url] [![GitHub Workflow Status][actions-img]][github-actions] [![Coverage][cov-img]][cov-url]

JWT middleware for HTTP servers.

</div>

## Install

```sh
bun i @tinyhttp/jwt
```

## API

```ts
import { jwt } from '@tinyhttp/jwt'
```

### Options

#### `jwt(options)`

- `secret`: can be an array of strings (in case you are using private / public key encryption), or just a string if you are using basic HMAC signing (see the examples below)
- `algorithm? ("HS256")`: the algorithm used to sign and verify the token
- `audience?`: the expected "audience" of the jwt token
- `issuer?`: who issued this token
- `expiresIn?`: expiration time of the token (ex: `1d` for 1 day)
- `notBefore?`: not before date of the token (ex: `20m` for 20 minutes)
- `requestHeaderName? ("Authorization")`: the name of the header contaning the Bearer token
- `responseHeaderName? ("X-Token")`: the name of the response header containing the new signed token that will be used later on
- `getToken(string)?: string`: the method used for ex

## Example

### Basic secret

```ts
import { App } from '@tinyhttp/app'
import { jwt } from '@tinyhttp/jwt'

new App()
  .use(jwt({ secret: 'secret', algorithm: 'HS256' }))
  .get('/', (req, res) => res.send(`Data inside the payload: ${req['user']}`))
  .listen(8080)
```

### Private / Public key

```ts
import { App } from '@tinyhttp/app'
import { jwt } from '@tinyhttp/jwt'

new App()
  .use(jwt({ secret: ['PRIVATE KEY', 'PUBLIC KEY'], algorithm: 'RS256' }))
  .get('/', (req, res) => res.send(`Data inside the payload: ${req['user']}`))
  .listen(8080)
```

[npm-badge]: https://img.shields.io/npm/v/@tinyhttp/jwt?style=for-the-badge&color=hotpink&label=&logo=npm
[npm-url]: https://npmjs.com/package/@tinyhttp/jwt
[dl-badge]: https://img.shields.io/npm/dt/@tinyhttp/jwt?style=for-the-badge&color=hotpink
[actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/jwt/main.yml?style=for-the-badge&logo=github&label=&color=hotpink
[github-actions]: https://github.com/tinyhttp/jwt/actions
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/jwt?style=for-the-badge&color=hotpink&a
[cov-url]: https://coveralls.io/github/tinyhttp/jwt

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