refactor(gateway): unify auth credential resolution

This commit is contained in:
Peter Steinberger
2026-02-22 18:21:20 +01:00
parent ded9a59f78
commit 66529c7aa5
13 changed files with 537 additions and 126 deletions

View File

@@ -442,6 +442,7 @@ export async function connectReq(
ws: WebSocket,
opts?: {
token?: string;
deviceToken?: string;
password?: string;
skipDefaultAuth?: boolean;
minProtocol?: number;
@@ -494,7 +495,9 @@ export async function connectReq(
? ((testState.gatewayAuth as { password?: string }).password ?? undefined)
: process.env.OPENCLAW_GATEWAY_PASSWORD;
const token = opts?.token ?? defaultToken;
const deviceToken = opts?.deviceToken?.trim() || undefined;
const password = opts?.password ?? defaultPassword;
const authTokenForSignature = token ?? deviceToken;
const requestedScopes = Array.isArray(opts?.scopes)
? opts.scopes
: role === "operator"
@@ -524,7 +527,7 @@ export async function connectReq(
role,
scopes: requestedScopes,
signedAtMs,
token: token ?? null,
token: authTokenForSignature ?? null,
nonce: connectChallengeNonce,
});
return {
@@ -550,9 +553,10 @@ export async function connectReq(
role,
scopes: requestedScopes,
auth:
token || password
token || password || deviceToken
? {
token,
deviceToken,
password,
}
: undefined,