macro-agent 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +59 -0
- package/dist/agent/agent-manager.d.ts.map +1 -1
- package/dist/agent/agent-manager.js +10 -4
- package/dist/agent/agent-manager.js.map +1 -1
- package/dist/cli/acp.d.ts +6 -0
- package/dist/cli/acp.d.ts.map +1 -1
- package/dist/cli/acp.js +16 -2
- package/dist/cli/acp.js.map +1 -1
- package/dist/map/adapter/index.d.ts +1 -1
- package/dist/map/adapter/index.d.ts.map +1 -1
- package/dist/map/adapter/index.js +1 -1
- package/dist/map/adapter/index.js.map +1 -1
- package/dist/map/utils/address-translation.d.ts +99 -0
- package/dist/map/utils/address-translation.d.ts.map +1 -0
- package/dist/map/utils/address-translation.js +285 -0
- package/dist/map/utils/address-translation.js.map +1 -0
- package/dist/map/utils/index.d.ts +7 -0
- package/dist/map/utils/index.d.ts.map +1 -0
- package/dist/map/utils/index.js +7 -0
- package/dist/map/utils/index.js.map +1 -0
- package/dist/server/combined-server.d.ts.map +1 -1
- package/dist/server/combined-server.js +8 -1
- package/dist/server/combined-server.js.map +1 -1
- package/dist/store/event-store.js +9 -2
- package/dist/store/event-store.js.map +1 -1
- package/dist/store/types/agents.d.ts +2 -0
- package/dist/store/types/agents.d.ts.map +1 -1
- package/package.json +4 -4
- package/references/acp-factory-ref/CHANGELOG.md +33 -0
- package/references/acp-factory-ref/LICENSE +21 -0
- package/references/acp-factory-ref/README.md +341 -0
- package/references/acp-factory-ref/package-lock.json +3102 -0
- package/references/acp-factory-ref/package.json +96 -0
- package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
- package/references/acp-factory-ref/python/LICENSE +21 -0
- package/references/acp-factory-ref/python/Makefile +57 -0
- package/references/acp-factory-ref/python/README.md +253 -0
- package/references/acp-factory-ref/python/pyproject.toml +73 -0
- package/references/acp-factory-ref/python/tests/__init__.py +0 -0
- package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
- package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
- package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
- package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
- package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
- package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
- package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
- package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
- package/references/claude-code-acp/.prettierrc.json +4 -0
- package/references/claude-code-acp/CHANGELOG.md +249 -0
- package/references/claude-code-acp/LICENSE +222 -0
- package/references/claude-code-acp/README.md +53 -0
- package/references/claude-code-acp/docs/RELEASES.md +24 -0
- package/references/claude-code-acp/eslint.config.js +48 -0
- package/references/claude-code-acp/package-lock.json +4570 -0
- package/references/claude-code-acp/package.json +88 -0
- package/references/claude-code-acp/scripts/release.sh +119 -0
- package/references/claude-code-acp/src/acp-agent.ts +2079 -0
- package/references/claude-code-acp/src/index.ts +26 -0
- package/references/claude-code-acp/src/lib.ts +38 -0
- package/references/claude-code-acp/src/mcp-server.ts +911 -0
- package/references/claude-code-acp/src/settings.ts +522 -0
- package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
- package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
- package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
- package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
- package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
- package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
- package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
- package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
- package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
- package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
- package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
- package/references/claude-code-acp/src/tools.ts +819 -0
- package/references/claude-code-acp/src/utils.ts +171 -0
- package/references/claude-code-acp/tsconfig.json +18 -0
- package/references/claude-code-acp/vitest.config.ts +19 -0
- package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
- package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
- package/references/multi-agent-protocol/LICENSE +21 -0
- package/references/multi-agent-protocol/README.md +113 -0
- package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
- package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
- package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
- package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
- package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
- package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
- package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
- package/references/multi-agent-protocol/docs/07-federation.md +259 -0
- package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
- package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
- package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
- package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
- package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
- package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
- package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
- package/references/multi-agent-protocol/docs-site/README.md +82 -0
- package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
- package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
- package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
- package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
- package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
- package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
- package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
- package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
- package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
- package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
- package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
- package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
- package/references/multi-agent-protocol/docs-site/index.md +136 -0
- package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
- package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
- package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
- package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
- package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
- package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
- package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
- package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
- package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
- package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
- package/references/multi-agent-protocol/package-lock.json +3886 -0
- package/references/multi-agent-protocol/package.json +56 -0
- package/references/multi-agent-protocol/schema/meta.json +467 -0
- package/references/multi-agent-protocol/schema/schema.json +2558 -0
- package/src/agent/__tests__/agent-manager.test.ts +67 -1
- package/src/agent/agent-manager.ts +10 -4
- package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
- package/src/cli/acp.ts +17 -2
- package/src/map/adapter/index.ts +3 -0
- package/src/server/combined-server.ts +10 -0
- package/src/store/event-store.ts +10 -3
- package/src/store/types/agents.ts +2 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Authentication
|
|
3
|
+
parent: Guides
|
|
4
|
+
grand_parent: SDK
|
|
5
|
+
nav_order: 5
|
|
6
|
+
description: "Configure authentication in the SDK"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Authentication
|
|
10
|
+
{: .no_toc }
|
|
11
|
+
|
|
12
|
+
Configure authentication for MAP connections.
|
|
13
|
+
{: .fs-6 .fw-300 }
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
{: .no_toc .text-delta }
|
|
17
|
+
|
|
18
|
+
1. TOC
|
|
19
|
+
{:toc}
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
MAP supports multiple authentication methods. The SDK provides built-in support for bearer tokens, API keys, and custom authentication.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Client Authentication
|
|
30
|
+
|
|
31
|
+
### Bearer Token
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { ClientConnection } from "@multi-agent-protocol/sdk";
|
|
35
|
+
|
|
36
|
+
const client = new ClientConnection(stream, {
|
|
37
|
+
name: "Dashboard",
|
|
38
|
+
auth: {
|
|
39
|
+
method: "bearer",
|
|
40
|
+
credential: "eyJhbGciOiJSUzI1NiIs...",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await client.connect();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### API Key
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const client = new ClientConnection(stream, {
|
|
51
|
+
name: "Dashboard",
|
|
52
|
+
auth: {
|
|
53
|
+
method: "api-key",
|
|
54
|
+
credential: "map_abc123_secretkey",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### No Authentication
|
|
60
|
+
|
|
61
|
+
For local or development environments:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const client = new ClientConnection(stream, {
|
|
65
|
+
name: "LocalClient",
|
|
66
|
+
// No auth property = no authentication
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Agent Authentication
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { AgentConnection } from "@multi-agent-protocol/sdk";
|
|
76
|
+
|
|
77
|
+
const agent = new AgentConnection(stream, {
|
|
78
|
+
name: "WorkerAgent",
|
|
79
|
+
role: "processor",
|
|
80
|
+
auth: {
|
|
81
|
+
method: "bearer",
|
|
82
|
+
credential: "agent-service-token",
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await agent.connect();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Server Authentication Configuration
|
|
92
|
+
|
|
93
|
+
### Require Authentication
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
97
|
+
|
|
98
|
+
const server = new MAPServer({
|
|
99
|
+
name: "SecureServer",
|
|
100
|
+
auth: {
|
|
101
|
+
required: true,
|
|
102
|
+
methods: ["bearer", "api-key"],
|
|
103
|
+
|
|
104
|
+
// Validate credentials
|
|
105
|
+
validate: async (credentials) => {
|
|
106
|
+
if (credentials.method === "bearer") {
|
|
107
|
+
const payload = await verifyJWT(credentials.credential);
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
principal: {
|
|
111
|
+
id: payload.sub,
|
|
112
|
+
claims: payload,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (credentials.method === "api-key") {
|
|
118
|
+
const key = await lookupApiKey(credentials.credential);
|
|
119
|
+
if (key) {
|
|
120
|
+
return {
|
|
121
|
+
success: true,
|
|
122
|
+
principal: {
|
|
123
|
+
id: key.ownerId,
|
|
124
|
+
claims: { scope: key.scope },
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
error: { code: "invalid_credentials", message: "Invalid credentials" },
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Optional Authentication
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const server = new MAPServer({
|
|
143
|
+
name: "FlexibleServer",
|
|
144
|
+
auth: {
|
|
145
|
+
required: false, // Allow anonymous connections
|
|
146
|
+
methods: ["bearer", "api-key", "none"],
|
|
147
|
+
|
|
148
|
+
validate: async (credentials) => {
|
|
149
|
+
if (credentials.method === "none") {
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
principal: {
|
|
153
|
+
id: "anonymous",
|
|
154
|
+
claims: { role: "guest" },
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Validate other methods...
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## JWT Validation
|
|
168
|
+
|
|
169
|
+
### Using jsonwebtoken
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import jwt from "jsonwebtoken";
|
|
173
|
+
|
|
174
|
+
const server = new MAPServer({
|
|
175
|
+
name: "JWTServer",
|
|
176
|
+
auth: {
|
|
177
|
+
required: true,
|
|
178
|
+
methods: ["bearer"],
|
|
179
|
+
|
|
180
|
+
validate: async (credentials) => {
|
|
181
|
+
try {
|
|
182
|
+
const payload = jwt.verify(
|
|
183
|
+
credentials.credential,
|
|
184
|
+
process.env.JWT_SECRET!
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
success: true,
|
|
189
|
+
principal: {
|
|
190
|
+
id: payload.sub as string,
|
|
191
|
+
issuer: payload.iss,
|
|
192
|
+
claims: payload,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
} catch (err) {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
error: {
|
|
199
|
+
code: "invalid_credentials",
|
|
200
|
+
message: err.message,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Using JWKS
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
213
|
+
|
|
214
|
+
const JWKS = createRemoteJWKSet(
|
|
215
|
+
new URL("https://auth.example.com/.well-known/jwks.json")
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const server = new MAPServer({
|
|
219
|
+
name: "JWKSServer",
|
|
220
|
+
auth: {
|
|
221
|
+
required: true,
|
|
222
|
+
methods: ["bearer"],
|
|
223
|
+
|
|
224
|
+
validate: async (credentials) => {
|
|
225
|
+
try {
|
|
226
|
+
const { payload } = await jwtVerify(credentials.credential, JWKS, {
|
|
227
|
+
issuer: "https://auth.example.com",
|
|
228
|
+
audience: "map-server",
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
success: true,
|
|
233
|
+
principal: {
|
|
234
|
+
id: payload.sub!,
|
|
235
|
+
issuer: payload.iss,
|
|
236
|
+
claims: payload,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
} catch (err) {
|
|
240
|
+
return {
|
|
241
|
+
success: false,
|
|
242
|
+
error: {
|
|
243
|
+
code: "invalid_credentials",
|
|
244
|
+
message: "Token validation failed",
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Permission-Based Access
|
|
256
|
+
|
|
257
|
+
Use authentication claims to control permissions:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const server = new MAPServer({
|
|
261
|
+
name: "PermissionServer",
|
|
262
|
+
auth: {
|
|
263
|
+
required: true,
|
|
264
|
+
methods: ["bearer"],
|
|
265
|
+
validate: validateToken,
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
middleware: [
|
|
269
|
+
async (method, params, ctx, next) => {
|
|
270
|
+
const { principal } = ctx.session;
|
|
271
|
+
|
|
272
|
+
// Check permissions based on claims
|
|
273
|
+
if (method.startsWith("admin/")) {
|
|
274
|
+
if (!principal?.claims?.roles?.includes("admin")) {
|
|
275
|
+
throw new Error("Admin access required");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (method === "map/agents/register") {
|
|
280
|
+
if (!principal?.claims?.canRegisterAgents) {
|
|
281
|
+
throw new Error("Agent registration not permitted");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return next();
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Token Refresh
|
|
294
|
+
|
|
295
|
+
### Client-Side Refresh
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
const client = new ClientConnection(stream, {
|
|
299
|
+
name: "Dashboard",
|
|
300
|
+
auth: {
|
|
301
|
+
method: "bearer",
|
|
302
|
+
credential: accessToken,
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
await client.connect();
|
|
307
|
+
|
|
308
|
+
// When token is about to expire, refresh it
|
|
309
|
+
client.updateAuth({
|
|
310
|
+
method: "bearer",
|
|
311
|
+
credential: newAccessToken,
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Server-Side Expiration Notification
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
const server = new MAPServer({
|
|
319
|
+
name: "TokenServer",
|
|
320
|
+
auth: {
|
|
321
|
+
required: true,
|
|
322
|
+
methods: ["bearer"],
|
|
323
|
+
|
|
324
|
+
validate: async (credentials) => {
|
|
325
|
+
const payload = await verifyJWT(credentials.credential);
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
success: true,
|
|
329
|
+
principal: {
|
|
330
|
+
id: payload.sub,
|
|
331
|
+
claims: payload,
|
|
332
|
+
},
|
|
333
|
+
expiresAt: payload.exp * 1000, // When token expires
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
// Notify clients before expiration
|
|
338
|
+
notifyBeforeExpiry: 5 * 60 * 1000, // 5 minutes
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Connection Flow Examples
|
|
346
|
+
|
|
347
|
+
### Authenticated Connection
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
// Client
|
|
351
|
+
const client = new ClientConnection(stream, {
|
|
352
|
+
name: "SecureClient",
|
|
353
|
+
auth: {
|
|
354
|
+
method: "bearer",
|
|
355
|
+
credential: await getAccessToken(),
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const result = await client.connect();
|
|
360
|
+
|
|
361
|
+
if (result.principal) {
|
|
362
|
+
console.log(`Authenticated as: ${result.principal.id}`);
|
|
363
|
+
console.log(`Claims:`, result.principal.claims);
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Handle Auth Errors
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
try {
|
|
371
|
+
await client.connect();
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (error.code === 1000) {
|
|
374
|
+
// AUTH_REQUIRED
|
|
375
|
+
console.error("Authentication required");
|
|
376
|
+
} else if (error.code === 1001) {
|
|
377
|
+
// AUTH_FAILED
|
|
378
|
+
console.error("Invalid credentials");
|
|
379
|
+
} else if (error.code === 1002) {
|
|
380
|
+
// AUTH_EXPIRED
|
|
381
|
+
console.error("Token expired, please refresh");
|
|
382
|
+
} else if (error.code === 1003) {
|
|
383
|
+
// PERMISSION_DENIED
|
|
384
|
+
console.error("Insufficient permissions");
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## Best Practices
|
|
392
|
+
|
|
393
|
+
1. **Use HTTPS/WSS** - Always use secure transports in production
|
|
394
|
+
2. **Short-lived tokens** - Use access tokens with short expiration
|
|
395
|
+
3. **Validate on server** - Never trust client-provided claims
|
|
396
|
+
4. **Least privilege** - Grant minimum required permissions
|
|
397
|
+
5. **Log auth events** - Track authentication for security auditing
|
|
398
|
+
6. **Rotate secrets** - Regularly rotate API keys and signing keys
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## Next Steps
|
|
403
|
+
|
|
404
|
+
- [Server Setup](./server.html) - Configure server authentication
|
|
405
|
+
- [Testing](./testing.html) - Test authenticated connections
|