41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* scanners 增加刷新令牌字段
|
||
*
|
||
* 背景:设备长期 JWT 默认 365 天,到期后服务会 401;而续期原本必须重新走
|
||
* 「主体管理员登录 → activate」,对无人值守的扫码服务不友好。
|
||
*
|
||
* 方案:激活时同时下发一枚**刷新令牌**(不透明随机串,库里只存 sha256),
|
||
* 后台服务在访问令牌快过期时用它换新访问令牌(同时轮换刷新令牌)。
|
||
* - `refresh_token_hash`:刷新令牌摘要(不存原文;索引便于反查)
|
||
* - `refresh_expires_at`:刷新令牌过期时间(每次刷新顺延)
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.addColumn('scanners', 'refresh_token_hash', {
|
||
type: Sequelize.STRING(128),
|
||
allowNull: true,
|
||
after: 'token_expires_at',
|
||
comment: '刷新令牌 sha256(不存原文)',
|
||
});
|
||
|
||
await queryInterface.addColumn('scanners', 'refresh_expires_at', {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
after: 'refresh_token_hash',
|
||
comment: '刷新令牌过期时间',
|
||
});
|
||
|
||
await queryInterface.addIndex('scanners', [ 'refresh_token_hash' ], {
|
||
name: 'idx_scanners_refresh_token_hash',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('scanners', 'idx_scanners_refresh_token_hash');
|
||
await queryInterface.removeColumn('scanners', 'refresh_expires_at');
|
||
await queryInterface.removeColumn('scanners', 'refresh_token_hash');
|
||
},
|
||
};
|