Browse Source

invalidateAll

master
巴林闲侠 2 years ago
parent
commit
345b7faa0d
  1. 38
      code/api/app/lib/controllers/auth/app.js
  2. 3
      code/api/app/lib/routes/auth/app.js

38
code/api/app/lib/controllers/auth/app.js

@ -128,8 +128,44 @@ async function invalidate (ctx) {
}
}
async function invalidateAll (ctx) {
// 给其他系统删除token
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
const { appKey } = ctx.query;
const tokenRes = await models.UserToken.findAll({
where: {
'userInfo.appKey': appKey
}
})
// 删除token
await models.UserToken.destroy({
where: { 'userInfo.appKey': appKey },
transaction
});
tokenRes.forEach(async t => {
await ctx.redisTools.hdelall(t.token);
})
await transaction.commit();
ctx.status = 204;
} catch (e) {
await transaction.rollback();
ctx.status = 400;
ctx.body = {
name: 'RequestError',
message: e.message
};
}
}
// OAUTH2.0 END
module.exports = {
apply,
refresh,
invalidate
invalidate,
invalidateAll, // 给其他系统删除token
}

3
code/api/app/lib/routes/auth/app.js

@ -11,4 +11,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['POST/oauth2/token/invalidate'] = { content: '作废访问令牌', visible: false };
router.post('/oauth2/token/invalidate', OAuth.invalidate);
app.fs.api.logAttr['DEL/oauth2/token/invalidate_all'] = { content: '删除所有访问令牌', visible: false };
router.delete('/oauth2/token/invalidate_all', OAuth.invalidateAll);
};

Loading…
Cancel
Save