Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/agent-auth/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-auth/src/__tests__/agent-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),
Expand Down
14 changes: 7 additions & 7 deletions packages/agent-auth/src/__tests__/device-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 }),
Expand All @@ -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();
Expand All @@ -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 }),
Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-auth/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions packages/agent-auth/src/routes/device/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading