# @oslojs/jwt

> Parse and encoding JSON web tokens

Latest version **0.3.0** (published 2024-11-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2024-11-23 |
| First published | 2024-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 174 |
| Author | pilcrowOnPaper |
| Maintainers | pilcrowonpaper |
| Keywords | auth, jwt |

## Links

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

## Dependencies (1)

- [@oslojs/encoding](https://npm.io/package/@oslojs/encoding.md) 0.4.1

## Alternatives

- [@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
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2024-11-23
- 0.2.0 — 2024-09-18
- 0.1.0 — 2024-09-16

## README

# @oslojs/jwt

**Documentation: https://jwt.oslojs.dev**

A JavaScript library for parsing and encoding JSON web tokens (JWT) by [Oslo](https://oslojs.dev). Only signed tokens are supported.

- Runtime-agnostic
- No third-party dependencies
- Fully typed

```ts
import { parseJWT, JWSRegisteredHeaders, JWTRegisteredClaims, joseAlgorithmHS256 } from "@oslojs/jwt";

const [header, payload, signature] = parseJWT(jwt);
const headerParameters = new JWSRegisteredHeaders(header);
if (header.algorithm() !== joseAlgorithmHS256) {
	throw new Error("Unsupported algorithm");
}
const claims = new JWTRegisteredClaims(payload);
if (!claims.verifyExpiration()) {
	throw new Error("Expired token");
}
if (claims.hasNotBefore() && !claims.verifyNotBefore()) {
	throw new Error("Invalid token");
}
```

## Installation

```
npm i @oslojs/jwt
```

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