fix: 获取token之后要回填到userAuth记录中

This commit is contained in:
Pan Qiancheng 2025-10-23 17:36:03 +08:00
parent d7b34fb3f6
commit 6f5dead6cc
2 changed files with 32 additions and 4 deletions

View File

@ -108,11 +108,12 @@ const oauthTokenEndpoint: Endpoint<EntityDict, BackendRuntimeContext<EntityDict>
const refreshTokenExpiresIn = 86400 * 30; // 30 days const refreshTokenExpiresIn = 86400 * 30; // 30 days
// create // create
const tokenId = await generateNewIdAsync();
await context.operate("oauthToken", { await context.operate("oauthToken", {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
action: "create", action: "create",
data: { data: {
id: await generateNewIdAsync(), id: tokenId,
accessToken: genaccessToken, accessToken: genaccessToken,
refreshToken: refreshToken, refreshToken: refreshToken,
userId: authCodeRecord.userId, userId: authCodeRecord.userId,
@ -122,6 +123,18 @@ const oauthTokenEndpoint: Endpoint<EntityDict, BackendRuntimeContext<EntityDict>
} }
}, {}) }, {})
// 创建记录
await context.operate("oauthUserAuthorization", {
id: await generateNewIdAsync(),
action: "update",
data: {
tokenId: tokenId,
},
filter: {
codeId: authCodeRecord.id,
}
}, {})
// 标记code为已使用 // 标记code为已使用
await context.operate("oauthAuthorizationCode", { await context.operate("oauthAuthorizationCode", {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),

View File

@ -68,6 +68,21 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
revoked: '#6c757d', revoked: '#6c757d',
} }
} }
},
indexes: [
// 根据授权码查询唯一记录
{
name: 'idx_code_id',
attributes: [
{
name: 'code',
direction: 'ASC',
} }
],
config: {
unique: true,
}
}
]
}; };