Skip to content

Commit 558a2aa

Browse files
Merge pull request anomalyco#333 from different-ai/feat/openwork-server-auth
Improve OpenWork server auth handling
2 parents bbc9052 + 056291d commit 558a2aa

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎packages/app/src/app/app.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ export default function App() {
294294
const client = createOpenworkServerClient({ baseUrl: url, token });
295295
try {
296296
await client.health();
297-
} catch {
297+
} catch (error) {
298+
if (error instanceof OpenworkServerError && (error.status === 401 || error.status === 403)) {
299+
return { status: "limited" as OpenworkServerStatus, capabilities: null };
300+
}
298301
return { status: "disconnected" as OpenworkServerStatus, capabilities: null };
299302
}
300303

‎packages/app/src/app/context/workspace.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,24 @@ export function createWorkspaceStore(options: {
182182

183183
const client = createOpenworkServerClient({ baseUrl: normalized, token: input.token ?? undefined });
184184

185+
const trimmedToken = input.token?.trim() ?? "";
186+
185187
try {
186188
const health = await client.health();
187189
if (!health?.ok) {
188190
return { kind: "fallback" as const };
189191
}
190192
} catch (error) {
191193
if (error instanceof OpenworkServerError && (error.status === 401 || error.status === 403)) {
192-
throw error;
194+
if (!trimmedToken) {
195+
throw new Error("Access token required for OpenWork host.");
196+
}
197+
throw new Error("OpenWork host rejected the client token.");
193198
}
194199
return { kind: "fallback" as const };
195200
}
196201

197-
if (!input.token?.trim()) {
202+
if (!trimmedToken) {
198203
throw new Error("Access token required for OpenWork host.");
199204
}
200205

‎packages/app/src/app/lib/openwork-server.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
238238
return {
239239
baseUrl,
240240
token,
241-
health: () => requestJson<{ ok: boolean; version: string; uptimeMs: number }>(baseUrl, "/health"),
241+
health: () =>
242+
requestJson<{ ok: boolean; version: string; uptimeMs: number }>(baseUrl, "/health", { token, hostToken }),
242243
capabilities: () => requestJson<OpenworkServerCapabilities>(baseUrl, "/capabilities", { token, hostToken }),
243244
listWorkspaces: () => requestJson<{ items: OpenworkWorkspaceInfo[] }>(baseUrl, "/workspaces", { token, hostToken }),
244245
getConfig: (workspaceId: string) =>

0 commit comments

Comments
 (0)