feat(api): expose REST-only agent routes
This commit is contained in:
+20
-11
@@ -100,7 +100,7 @@ export const requireAgentAuth = async (
|
||||
const timer = setTimeout(() => controller.abort(), config.AGENT_AUTH_TIMEOUT_MS);
|
||||
|
||||
try {
|
||||
const response = await fetch(new URL("/api/v1/agent/auth/context", config.TJWATER_API_BASE_URL), {
|
||||
const response = await fetch(new URL("/api/v1/agent-auth-context", config.TJWATER_API_BASE_URL), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
@@ -125,18 +125,27 @@ export const requireAgentAuth = async (
|
||||
return;
|
||||
}
|
||||
|
||||
const detail = await response.text();
|
||||
res.status(response.status === 403 ? 403 : 401).json({
|
||||
message: response.status === 403 ? "forbidden" : "unauthorized",
|
||||
detail: detail || undefined,
|
||||
});
|
||||
const status =
|
||||
response.status === 400 ||
|
||||
response.status === 401 ||
|
||||
response.status === 403 ||
|
||||
response.status === 404
|
||||
? response.status
|
||||
: response.status === 503
|
||||
? 503
|
||||
: 502;
|
||||
const messages: Record<number, string> = {
|
||||
400: "invalid authentication request",
|
||||
401: "unauthorized",
|
||||
403: "forbidden",
|
||||
404: "authentication context not found",
|
||||
502: "invalid authentication service response",
|
||||
503: "authentication service unavailable",
|
||||
};
|
||||
res.status(status).json({ message: messages[status] });
|
||||
} catch (error) {
|
||||
const detail = error instanceof Error ? error.message : String(error);
|
||||
logger.warn({ err: error }, "agent auth validation failed");
|
||||
res.status(503).json({
|
||||
message: "authentication service unavailable",
|
||||
detail,
|
||||
});
|
||||
res.status(503).json({ message: "authentication service unavailable" });
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user