在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:chentsulin/koa-bearer-token开源软件地址:https://github.com/chentsulin/koa-bearer-token开源编程语言:TypeScript 89.7%开源软件介绍:koa-bearer-token
Inspired by express-bearer-token Installation$ npm install koa-bearer-token What?Per RFC6750 this module will attempt to extract a bearer token from a request from these locations:
If a token is found, it will be stored on const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const { bearerToken } = require('koa-bearer-token');
const app = new Koa();
app.use(bodyParser());
app.use(bearerToken());
app.use((ctx) => {
// ctx.request.token
});
app.listen(3000); For APIs which are not compliant with [RFC6750], the key for the token in each location is customizable, as is the key the token is bound to on the request (default configuration shown): app.use(
bearerToken({
bodyKey: 'access_token',
queryKey: 'access_token',
headerKey: 'Bearer',
reqKey: 'token',
}),
); Get token from cookie key (it can be signed or not) Warning: by NOT passing app.use(
bearerToken({
cookie: {
signed: true, // if passed true you must pass secret otherwise will throw error
secret: 'YOUR_APP_SECRET',
key: 'access_token', // default value
},
}),
); TypeScriptAs of version 2.0.1 we've added initial support for TypeScript. If you're using your custom declare module 'koa' {
interface Request {
myToken?: string;
}
}
app.use(
bearerToken({
reqKey: 'myToken',
}),
); Compatibility table
LicenseMIT © C. T. Lin |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论