Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/altipla-consulting/jwt.js
- Owner: altipla-consulting
- License: mit
- Created: 2023-04-03T13:20:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-13T09:33:29.000Z (about 1 year ago)
- Last Synced: 2024-11-07T00:07:21.182Z (2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@altipla/jwt
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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()
```