mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 18:50:20 +00:00
refactor: share gateway auth and approval helpers
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { buildGatewayConnectionDetails } from "../gateway/call.js";
|
||||
import { resolveGatewayClientBootstrap } from "../gateway/client-bootstrap.js";
|
||||
import { GatewayClient } from "../gateway/client.js";
|
||||
import { resolveGatewayConnectionAuth } from "../gateway/connection-auth.js";
|
||||
import { APPROVALS_SCOPE, READ_SCOPE, WRITE_SCOPE } from "../gateway/method-scopes.js";
|
||||
import type { EventFrame } from "../gateway/protocol/index.js";
|
||||
import { extractFirstTextBlock } from "../shared/chat-message-content.js";
|
||||
@@ -84,25 +83,14 @@ export class OpenClawChannelBridge {
|
||||
return;
|
||||
}
|
||||
this.started = true;
|
||||
const connection = buildGatewayConnectionDetails({
|
||||
config: this.cfg,
|
||||
url: this.params.gatewayUrl,
|
||||
});
|
||||
const gatewayUrlOverrideSource =
|
||||
connection.urlSource === "cli --url"
|
||||
? "cli"
|
||||
: connection.urlSource === "env OPENCLAW_GATEWAY_URL"
|
||||
? "env"
|
||||
: undefined;
|
||||
const creds = await resolveGatewayConnectionAuth({
|
||||
const bootstrap = await resolveGatewayClientBootstrap({
|
||||
config: this.cfg,
|
||||
gatewayUrl: this.params.gatewayUrl,
|
||||
explicitAuth: {
|
||||
token: this.params.gatewayToken,
|
||||
password: this.params.gatewayPassword,
|
||||
},
|
||||
env: process.env,
|
||||
urlOverride: gatewayUrlOverrideSource ? connection.url : undefined,
|
||||
urlOverrideSource: gatewayUrlOverrideSource,
|
||||
});
|
||||
if (this.closed) {
|
||||
this.resolveReadyOnce();
|
||||
@@ -110,9 +98,9 @@ export class OpenClawChannelBridge {
|
||||
}
|
||||
|
||||
this.gateway = new GatewayClient({
|
||||
url: connection.url,
|
||||
token: creds.token,
|
||||
password: creds.password,
|
||||
url: bootstrap.url,
|
||||
token: bootstrap.auth.token,
|
||||
password: bootstrap.auth.password,
|
||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||
clientDisplayName: "OpenClaw MCP",
|
||||
clientVersion: VERSION,
|
||||
|
||||
Reference in New Issue
Block a user