docs: document gateway client auth helpers · openclaw/openclaw@861bf54
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway RPC call helper. |
| 2 | +// Builds a GatewayClient, resolves auth/scopes, and performs one request. |
1 | 3 | import { randomUUID } from "node:crypto"; |
2 | 4 | import { isLoopbackIpAddress } from "@openclaw/net-policy/ip"; |
3 | 5 | import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensitive-url"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway client bootstrap resolver. |
| 2 | +// Collects URL, auth, and handshake settings before constructing a GatewayClient. |
1 | 3 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 4 | import { resolveGatewayConnectionAuth } from "./connection-auth.js"; |
3 | 5 | import { buildGatewayConnectionDetailsWithResolvers } from "./connection-details.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// OpenClaw Gateway client facade. |
| 2 | +// Wraps the shared gateway-client package with OpenClaw host dependencies. |
1 | 3 | import { |
2 | 4 | GatewayClient as BaseGatewayClient, |
3 | 5 | GATEWAY_CLOSE_CODE_HINTS as BASE_GATEWAY_CLOSE_CODE_HINTS, |
@@ -191,6 +193,8 @@ export class GatewayClient {
|
191 | 193 | #client: BaseGatewayClient; |
192 | 194 | |
193 | 195 | constructor(opts: GatewayClientOptions) { |
| 196 | +// Inject host deps here so the reusable package stays decoupled from |
| 197 | +// OpenClaw device identity, token storage, proxy routing, and logging. |
194 | 198 | this.#client = new BaseGatewayClient({ |
195 | 199 | ...opts, |
196 | 200 | clientVersion: opts.clientVersion ?? VERSION, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway connection auth facade. |
| 2 | +// Resolves config-backed client credentials with or without async SecretRefs. |
1 | 3 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 4 | import { resolveGatewayCredentialsWithSecretInputs } from "./credentials-secret-inputs.js"; |
3 | 5 | import { resolveGatewayCredentialsFromConfig } from "./credentials.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway HTTP auth helpers. |
| 2 | +// Authenticates HTTP endpoints and derives trusted operator scopes. |
1 | 3 | import type { IncomingMessage, ServerResponse } from "node:http"; |
2 | 4 | import { |
3 | 5 | normalizeLowercaseStringOrEmpty, |
@@ -27,6 +29,8 @@ export function getHeader(req: IncomingMessage, name: string): string | undefine
|
27 | 29 | } |
28 | 30 | |
29 | 31 | export function getBearerToken(req: IncomingMessage): string | undefined { |
| 32 | +// Bearer parsing is intentionally minimal: callers pass the extracted token |
| 33 | +// into the shared gateway auth verifier for constant-time comparison. |
30 | 34 | const raw = normalizeOptionalString(getHeader(req, "authorization")) ?? ""; |
31 | 35 | if (!normalizeLowercaseStringOrEmpty(raw).startsWith("bearer ")) { |
32 | 36 | return undefined; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway probe auth resolver. |
| 2 | +// Adapts gateway credential precedence for local/remote reachability checks. |
1 | 3 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
3 | 5 | import { resolveGatewayCredentialsWithSecretInputs } from "./credentials-secret-inputs.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway probe target resolver. |
| 2 | +// Chooses local or remote probe mode from gateway config and URL availability. |
1 | 3 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
3 | 5 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway reachability probe client. |
| 2 | +// Connects to a gateway and summarizes auth, health, status, and presence. |
1 | 3 | import { randomUUID } from "node:crypto"; |
2 | 4 | import path from "node:path"; |
3 | 5 | import { |
@@ -105,6 +107,8 @@ function hasProbeAuth(auth: GatewayProbeAuth | undefined): boolean {
|
105 | 107 | } |
106 | 108 | |
107 | 109 | function shouldShortCircuitDeviceRequiredProbe(cacheKey: string, nowMs: number): boolean { |
| 110 | +// Repeated unauthenticated probes can trigger pairing/device-required closes. |
| 111 | +// Short-circuit briefly so status checks do not spam the gateway. |
108 | 112 | const entry = deviceRequiredProbeCache.get(cacheKey); |
109 | 113 | if (!entry) { |
110 | 114 | return false; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway startup Control UI origin seeding. |
| 2 | +// Adds runtime-only browser origins for non-loopback binds when safe. |
1 | 3 | import { |
2 | 4 | ensureControlUiAllowedOriginsForNonLoopbackBind, |
3 | 5 | type GatewayNonLoopbackBindMode, |
@@ -23,6 +25,8 @@ export async function maybeSeedControlUiAllowedOriginsAtStartup(params: {
|
23 | 25 | if (!seeded.seededOrigins || !seeded.bind) { |
24 | 26 | return { config: params.config, seededAllowedOrigins: false }; |
25 | 27 | } |
| 28 | +// This changes only the runtime config object. Operators still need explicit |
| 29 | +// config entries for additional browser origins. |
26 | 30 | params.log.info(buildSeededOriginsInfoLog(seeded.seededOrigins, seeded.bind)); |
27 | 31 | return { config: seeded.config, seededAllowedOrigins: true }; |
28 | 32 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。