修复登录报错问题

This commit is contained in:
2026-07-06 16:31:11 +08:00
parent 53b1842de8
commit 9a3070c749
8 changed files with 98 additions and 6 deletions

View File

@@ -46,6 +46,7 @@ export async function POST(request: Request) {
clientId: config.clientId,
clientSecret: config.clientSecret,
scope: config.scope,
tenantId: config.tenantId,
username,
password: prepareAuthPassword(password, {
passwordEncrypted: body.password_encrypted || body.passwordEncrypted,
@@ -82,6 +83,7 @@ async function exchangePasswordToken(input: {
clientId: string;
clientSecret: string;
scope: string;
tenantId?: string;
username: string;
password: string;
code?: string;
@@ -92,14 +94,17 @@ async function exchangePasswordToken(input: {
form.set("scope", input.scope);
form.set("username", input.username);
form.set("password", input.password);
if (input.tenantId) form.set("tenantId", input.tenantId);
if (input.code) form.set("code", input.code);
if (input.randomStr) form.set("randomStr", input.randomStr);
const headers: Record<string, string> = {
Authorization: `Basic ${Buffer.from(`${input.clientId}:${input.clientSecret}`).toString("base64")}`,
"Content-Type": "application/x-www-form-urlencoded"
};
if (input.tenantId) headers.tenantId = input.tenantId;
const response = await fetch(input.tokenUrl, {
method: "POST",
headers: {
Authorization: `Basic ${Buffer.from(`${input.clientId}:${input.clientSecret}`).toString("base64")}`,
"Content-Type": "application/x-www-form-urlencoded"
},
headers,
body: form
});
const payload = await response.json().catch(() => ({})) as PasswordTokenResponse;