oak-general-business/lib/watchers/oauth.js

47 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const watchers = [
{
name: '定期刷新过期的oauthUser令牌',
entity: 'oauthUser',
filter() {
const now = Date.now();
const tenMinutes = 10 * 60 * 1000; // 10分钟
const oneDay = 24 * 60 * 60 * 1000; // 1天
return {
$and: [
{
refreshToken: {
$exists: true,
},
},
{
state: {
provider: {
refreshEndpoint: {
$exists: true,
}
}
}
},
// accessToken在10分钟内过期包括已过期
{
accessExpiresAt: {
$lt: now + tenMinutes,
},
},
// refreshToken还没过期至少还有1天有效期
{
refreshExpiresAt: {
$gt: now + oneDay,
},
},
],
};
},
action: 'refreshTokens',
actionData: {},
},
];
exports.default = watchers;