$ npm i egg-kpauth --save
// {app_root}/config/plugin.js
exports.kpauth = {
enable: true,
package: "egg-kpauth",
};
// {app_root}/config/config.default.js
exports.kpauth = {
coreserviceURL: "http://10.28.18.44:3001/mock/32",
INTERNAL_API_KEY: "test",
};
see config/config.default.js for more detail.
In controllers:
校验失败会抛错,返回状态码 401
const user = this.ctx.authenticated();
const admin = this.ctx.adminAuthenticated();
const token = await this.ctx.refreshToken(oldToken, tokenBody);
旧的 token 会失效,tokenBody 里面必要参数为userId
,要保证userId
与 oldToken 一致,否则也会返回 401
Please open an issue here.