mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:32:44 +00:00
Fix onboard ignoring OPENCLAW_GATEWAY_TOKEN env var (#22658)
* Fix onboard ignoring OPENCLAW_GATEWAY_TOKEN env var When running onboard via docker-setup.sh, the QuickStart wizard generates its own 48-char token instead of using the 64-char token already set in OPENCLAW_GATEWAY_TOKEN. This causes a token mismatch that breaks all CLI commands after setup. Check process.env.OPENCLAW_GATEWAY_TOKEN before falling back to randomToken() in both the interactive QuickStart path and the non-interactive path. Closes #22638 Co-authored-by: Clawborn <tianrun.yang103@gmail.com> * Tests: cover quickstart env token fallback * Changelog: note docker onboarding token parity fix * Tests: restore env var after non-interactive token fallback test * Update CHANGELOG.md --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -149,6 +149,46 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("uses OPENCLAW_GATEWAY_TOKEN when --gateway-token is omitted", async () => {
|
||||
await withStateDir("state-env-token-", async (stateDir) => {
|
||||
const envToken = "tok_env_fallback_123";
|
||||
const workspace = path.join(stateDir, "openclaw");
|
||||
const prevToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = envToken;
|
||||
|
||||
try {
|
||||
await runNonInteractiveOnboarding(
|
||||
{
|
||||
nonInteractive: true,
|
||||
mode: "local",
|
||||
workspace,
|
||||
authChoice: "skip",
|
||||
skipSkills: true,
|
||||
skipHealth: true,
|
||||
installDaemon: false,
|
||||
gatewayBind: "loopback",
|
||||
gatewayAuth: "token",
|
||||
},
|
||||
runtime,
|
||||
);
|
||||
|
||||
const configPath = resolveStateConfigPath(process.env, stateDir);
|
||||
const cfg = await readJsonFile<{
|
||||
gateway?: { auth?: { mode?: string; token?: string } };
|
||||
}>(configPath);
|
||||
|
||||
expect(cfg?.gateway?.auth?.mode).toBe("token");
|
||||
expect(cfg?.gateway?.auth?.token).toBe(envToken);
|
||||
} finally {
|
||||
if (prevToken === undefined) {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
} else {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = prevToken;
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("writes gateway.remote url/token and callGateway uses them", async () => {
|
||||
await withStateDir("state-remote-", async () => {
|
||||
const port = getPseudoPort(30_000);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { OpenClawConfig } from "../../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../../runtime.js";
|
||||
import { randomToken } from "../../onboard-helpers.js";
|
||||
import { normalizeGatewayTokenInput, randomToken } from "../../onboard-helpers.js";
|
||||
import type { OnboardOptions } from "../../onboard-types.js";
|
||||
|
||||
export function applyNonInteractiveGatewayConfig(params: {
|
||||
@@ -49,7 +49,10 @@ export function applyNonInteractiveGatewayConfig(params: {
|
||||
}
|
||||
|
||||
let nextConfig = params.nextConfig;
|
||||
let gatewayToken = opts.gatewayToken?.trim() || undefined;
|
||||
let gatewayToken =
|
||||
normalizeGatewayTokenInput(opts.gatewayToken) ||
|
||||
normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN) ||
|
||||
undefined;
|
||||
|
||||
if (authMode === "token") {
|
||||
if (!gatewayToken) {
|
||||
|
||||
Reference in New Issue
Block a user