https://github.com/yornaath/koa-jwt-auth
https://github.com/yornaath/koa-jwt-auth
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yornaath/koa-jwt-auth
- Owner: yornaath
- Created: 2017-04-12T11:56:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-04T09:24:21.000Z (over 8 years ago)
- Last Synced: 2025-03-15T17:43:13.554Z (7 months ago)
- Language: TypeScript
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
```js
import * as koa from 'koa'
import * as Router from 'koa-router'
import {auth, isAuth} from 'koa-jwt-auth'const server = new koa()
const router = new Router()router.use(auth({
secret: "bees-knees",
throws: () =>
new AuthorizationError("Your request authorization headers where not accepted.")
}))const ensureAuth = isAuth({
throws: () =>
new AuthorizationError("You are not authenticated to make that request.")
})router.get("/protected", ensureAuth, protectedResource)
server.use(router.routes())
server.use(router.allowedMethods())
```