feat: 定期刷新要过期的oauth授权用户
This commit is contained in:
parent
1a063c86f5
commit
18c8d3b670
|
|
@ -3,8 +3,9 @@ import { Watcher } from 'oak-domain/lib/types';
|
|||
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
|
||||
import token from './token';
|
||||
import extraFile from './extraFile';
|
||||
import oauth from './oauth';
|
||||
|
||||
export default [...token, ...extraFile] as Watcher<
|
||||
export default [...token, ...extraFile, ...oauth] as Watcher<
|
||||
EntityDict,
|
||||
keyof EntityDict,
|
||||
BackendRuntimeContext<EntityDict>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
import { EntityDict } from '../oak-app-domain';
|
||||
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
|
||||
import { Watcher, BBWatcher } from 'oak-domain/lib/types/Watcher';
|
||||
|
||||
const watchers: Watcher<
|
||||
EntityDict,
|
||||
'oauthUser',
|
||||
BackendRuntimeContext<EntityDict>
|
||||
>[] = [
|
||||
{
|
||||
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: {},
|
||||
},
|
||||
];
|
||||
export default watchers;
|
||||
Loading…
Reference in New Issue