https://github.com/mhio/node-jwt
JWT helpers for Koa
https://github.com/mhio/node-jwt
Last synced: 2 months ago
JSON representation
JWT helpers for Koa
- Host: GitHub
- URL: https://github.com/mhio/node-jwt
- Owner: mhio
- License: mit
- Created: 2019-11-27T01:28:51.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-16T01:59:38.000Z (over 1 year ago)
- Last Synced: 2025-03-01T21:36:10.409Z (3 months ago)
- Language: JavaScript
- Size: 175 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JWT - @mhio/jwt
----------Do JWT things for koa
## Install
```
yarn add @mhio/jwt
npm install @mhio/jwt
```## Usage
```
import { Jwt } from '@mhio/jwt'const jwt = new Jwt({ jwt_sign_secret: 'SomeStrongPasswordForJwt' })
```Auto generated private/public key
```
import { Jwt } from '@mhio/jwt'
import Koa from 'koa'
import Router from '@koa/router'const jwt = new Jwt({ jwt_algorithm: 'RS256' })
const app = new Koa()
const router = new Router()router.get('/jwt', async function(ctx) {
const token = await jwt.jwtSign({ role: 'admin' })
ctx.body = token
})
router.use(jwt.koaMiddleware())
router.get('/protected', async function(ctx) {
ctx.body = ok
})app.use(router.routes())
.use(router.allowedMethods())```
## Links
https://github.com/mhio/node-jwt
https://www.npmjs.com/package/@mhio/jwt