feat: 添加JWKS token支持,更新用户和OAuth相关逻辑
This commit is contained in:
@@ -74,7 +74,7 @@ interface Store<T> {
|
||||
delKeys: (keys: string[]) => Promise<number>;
|
||||
}
|
||||
|
||||
type TokenData = {
|
||||
export type TokenData = {
|
||||
accessToken: string;
|
||||
accessTokenExpiresIn?: number;
|
||||
refreshToken?: string;
|
||||
@@ -401,4 +401,24 @@ export class OAuth<T extends OauthUser> {
|
||||
const tokens = await this.store.keys('*');
|
||||
await this.store.delKeys(tokens);
|
||||
}
|
||||
/**
|
||||
* 设置 jwks token, 用于jwt的验证, 过期时间为2小时
|
||||
*/
|
||||
async setJwksToken(token: string, opts: { id: string; expire: number }) {
|
||||
const expire = opts.expire ?? 2 * 3600; // 2 hours
|
||||
const id = opts.id || '';
|
||||
// jwks token的过期时间比accessToken多3天,确保3天内可以用来refresh token
|
||||
const addExpire = 3 * 24 * 3600;
|
||||
await this.store.redis.set('user:jwks:' + token, id, 'EX', expire + addExpire);
|
||||
}
|
||||
async deleteJwsToken(token: string) {
|
||||
await this.store.redis.expire('user:jwks:' + token, 0);
|
||||
}
|
||||
async getJwksToken(token: string) {
|
||||
const id = await this.store.redis.get('user:jwks:' + token);
|
||||
if (id) {
|
||||
this.deleteJwsToken(token);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user