diff --git a/packages/agent-auth/package.json b/packages/agent-auth/package.json index 52457a78e..7f6a8d425 100644 --- a/packages/agent-auth/package.json +++ b/packages/agent-auth/package.json @@ -1,6 +1,6 @@ { "name": "@better-auth/agent-auth", - "version": "0.4.5", + "version": "0.5.0", "description": "Agent Auth Protocol server plugin for Better Auth — agent identity, registration, and capability-based authorization", "license": "MIT", "repository": { diff --git a/packages/agent-auth/src/__tests__/agent-auth.test.ts b/packages/agent-auth/src/__tests__/agent-auth.test.ts index 1f1c81896..59cede9c7 100644 --- a/packages/agent-auth/src/__tests__/agent-auth.test.ts +++ b/packages/agent-auth/src/__tests__/agent-auth.test.ts @@ -86,7 +86,7 @@ beforeAll(async () => { describe("RFC 6749 §5.2 Error Envelope", () => { it("error responses use RFC 6749 §5.2 envelope", async () => { - const res = await client.api("/device/code", { + const res = await client.api("/agent/device/code", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ agent_id: "nonexistent" }), diff --git a/packages/agent-auth/src/__tests__/device-auth.test.ts b/packages/agent-auth/src/__tests__/device-auth.test.ts index 60e005ff4..c1ccce0c6 100644 --- a/packages/agent-auth/src/__tests__/device-auth.test.ts +++ b/packages/agent-auth/src/__tests__/device-auth.test.ts @@ -238,10 +238,10 @@ describe("Approval expiry", () => { }); // ================================================================ -// C. /device/code endpoint +// C. /agent/device/code endpoint // ================================================================ -describe("/device/code endpoint", () => { +describe("/agent/device/code endpoint", () => { it("returns valid RFC 8628 response shape", async () => { const { hostId, hostKeypair } = await setupAgent(); @@ -262,7 +262,7 @@ describe("/device/code endpoint", () => { audience: BASE, }); - const res = await client.api("/device/code", { + const res = await client.api("/agent/device/code", { method: "POST", headers: { authorization: `Bearer ${hostJWT}` }, body: JSON.stringify({ agent_id: pendingAgentId }), @@ -280,7 +280,7 @@ describe("/device/code endpoint", () => { expect(typeof body.user_code).toBe("string"); }); - it("user_code from /device/code can approve the agent", async () => { + it("user_code from /agent/device/code can approve the agent", async () => { const { hostId, hostKeypair } = await setupAgent(); const agentKeypair = await generateTestKeypair(); @@ -299,7 +299,7 @@ describe("/device/code endpoint", () => { audience: BASE, }); - const codeRes = await client.api("/device/code", { + const codeRes = await client.api("/agent/device/code", { method: "POST", headers: { authorization: `Bearer ${hostJWT}` }, body: JSON.stringify({ agent_id: agentId }), @@ -335,7 +335,7 @@ describe("/device/code endpoint", () => { audience: BASE, }); - const res = await client.api("/device/code", { + const res = await client.api("/agent/device/code", { method: "POST", headers: { authorization: `Bearer ${hostJWT}` }, body: JSON.stringify({ agent_id: agentId }), @@ -368,7 +368,7 @@ describe("/device/code endpoint", () => { audience: BASE, }); - const res = await client.api("/device/code", { + const res = await client.api("/agent/device/code", { method: "POST", headers: { authorization: `Bearer ${hostJWT}` }, body: JSON.stringify({ agent_id: agentId }), diff --git a/packages/agent-auth/src/client.ts b/packages/agent-auth/src/client.ts index f7b2f557f..8e963fe9c 100644 --- a/packages/agent-auth/src/client.ts +++ b/packages/agent-auth/src/client.ts @@ -37,7 +37,7 @@ export const agentAuthClient = () => { "/host/enroll": "POST", "/host/switch-account": "POST", "/agent/ciba/authorize": "POST", - "/device/code": "POST", + "/agent/device/code": "POST", }, $ERROR_CODES: AGENT_AUTH_ERROR_CODES, } satisfies BetterAuthClientPlugin; diff --git a/packages/agent-auth/src/routes/device/code.ts b/packages/agent-auth/src/routes/device/code.ts index f143fbd9f..1290c11a4 100644 --- a/packages/agent-auth/src/routes/device/code.ts +++ b/packages/agent-auth/src/routes/device/code.ts @@ -7,14 +7,17 @@ import { resolveDeviceAuthPage } from "../_helpers"; import type { Agent, ApprovalRequest, HostSession, ResolvedAgentAuthOptions } from "../../types"; /** - * POST /device/code (RFC 8628 §3.1–3.2). + * POST /agent/device/code (RFC 8628 §3.1–3.2). * * Issues a device code and user code for a pending agent. * Auth: Host JWT — the host must own the agent. + * + * Namespaced under `/agent/*` to avoid conflicting with Better Auth's + * core `device-authorization` plugin which owns `/device/code`. */ export function deviceCode(opts: ResolvedAgentAuthOptions) { return createAuthEndpoint( - "/device/code", + "/agent/device/code", { method: "POST", body: z.object({