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

https://github.com/yornaath/koa-jwt-auth


https://github.com/yornaath/koa-jwt-auth

Last synced: 3 months ago
JSON representation

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())
```