feat: 更新N5代理逻辑,支持使用用户JWKS令牌进行身份验证

This commit is contained in:
2026-03-03 18:33:41 +08:00
parent 120303961c
commit bb4096ce7e
2 changed files with 29 additions and 3 deletions

View File

@@ -85,14 +85,17 @@ export class User {
/**
* 创建JWKS token的通用方法
*/
private static async createJwksTokenResponse(user: { id: string; username: string }, opts: { expire?: number } = {}) {
static async createJwksTokenResponse(user: { id: string; username: string }, opts: { expire?: number, save?: boolean } = {}) {
const expiresIn = opts?.expire ?? JWKS_TOKEN_EXPIRY;
const save = opts?.save ?? true;
const accessToken = await jwksManager.sign({
sub: 'user:' + user.id,
name: user.username,
exp: Math.floor(Date.now() / 1000) + expiresIn,
});
await oauth.setJwksToken(accessToken, { id: user.id, expire: expiresIn });
if (save) {
await oauth.setJwksToken(accessToken, { id: user.id, expire: expiresIn });
}
const token = {
accessToken,