Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/altipla-consulting/jwt.js

Secure and reusable JWT validation for Node.
https://github.com/altipla-consulting/jwt.js

Last synced: about 1 month ago
JSON representation

Secure and reusable JWT validation for Node.

Awesome Lists containing this project

README

        

# jwt.js

Secure and reusable JWT validation for Node.

## Install

```sh
npm install @altipla/jwt
```

## Usage

### Verify an asymetric token

```ts
import { verifyJWT } from '@altipla/jwt'

async function main() {
try {
let config = {
discovery: 'https://example.com/.well-known/jwks.json',
issuer: 'https://example.com',
audience: 'foo',
}
let token = '...'
let payload = await verifyJWT(config, token)
} catch (error: any) {
console.error(error)
}
}
main()
```

### Sign and verify symmetric tokens

```ts
import { Generator } from '@altipla/jwt'

interface Data {
// ... put your token content here
}

let generator = new Generator({
key: 'test-key',
issuer: 'https://www.example.com/issuer',
audience: 'foo',
})

async function main() {
let token = generator.sign(1000, 'test', {
// ... put your token content here
})

try {
let data = generator.verify(token)
} catch (error: any) {
console.error(error)
}
}

main()
```

### Sign and verify symmetric tokens with no payload

```ts
import { Generator } from '@altipla/jwt'

let generator = new Generator({
key: 'test-key',
issuer: 'https://www.example.com/issuer',
audience: 'foo',
})

async function main() {
let token = generator.sign(1000, 'test')

try {
let data = generator.verify(token)
} catch (error: any) {
console.error(error)
}
}

main()
```