koa-jwt-blacklist
Install
npm install koa-jwt-blacklist
Example
var Koa = require('koa');
var jwt = require('koa-jwt');
import { configure,revoke,isRevoked } from 'koa-jwt-blacklist';
var app = new Koa();
type Configure = {
strict?: boolean;
tokenId?: string;
store?: {
options?:any
type?: string;
host: string;
port?: string;
keyPrefix?: string;
get?: (key: string) => Promise<any>;
set?: (key: string, value: any) => Promise<any>;
};
};
const options = {}
configure(options:Configure)
app.use(jwt({ secret:'shared-secret',isRevoked:isRevoked }).unless({
path: [/^\/public/]
}))
app.use(async function(ctx){
await revoke(ctx.state.user)
ctx.body = "logout"
})
import jsonwebtoken from 'jsonwebtoken'
import { v4 as uuid } from 'uuid'
app.use(async function(ctx){
const user = {userId:'userId'}
const tokenId = uuid()
const token = jsonwebtoken.sign({
data: user,
sub:tokenId,
exp: Math.floor(Date.now() / 1000) + (60 * 60),
}, 'shared-secret')
ctx.body = token
})
[git地址](luoHongFSD/koa-jwt-blacklist (github.com))