@leanmcp/auth 0.4.2 → 0.4.4-alpha.10.96d2437

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/README.md CHANGED
@@ -27,6 +27,10 @@
27
27
  <a href="https://x.com/LeanMcp">
28
28
  <img src="https://img.shields.io/badge/@LeanMCP-f5f5f5?logo=x&logoColor=000000" />
29
29
  </a>
30
+ <a href="https://leanmcp.com/">
31
+ <img src="https://img.shields.io/badge/Website-leanmcp-0A66C2?" />
32
+ </a>
33
+ <a href="https://deepwiki.com/LeanMCP/leanmcp-sdk"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
30
34
  </p>
31
35
 
32
36
  ## Features
@@ -47,16 +51,19 @@ npm install @leanmcp/auth @leanmcp/core
47
51
  ### Provider Dependencies
48
52
 
49
53
  **AWS Cognito:**
54
+
50
55
  ```bash
51
56
  npm install @aws-sdk/client-cognito-identity-provider axios jsonwebtoken jwk-to-pem
52
57
  ```
53
58
 
54
59
  **Clerk:**
60
+
55
61
  ```bash
56
62
  npm install axios jsonwebtoken jwk-to-pem
57
63
  ```
58
64
 
59
65
  **Auth0:**
66
+
60
67
  ```bash
61
68
  npm install axios jsonwebtoken jwk-to-pem
62
69
  ```
@@ -66,12 +73,12 @@ npm install axios jsonwebtoken jwk-to-pem
66
73
  ### 1. Initialize Auth Provider
67
74
 
68
75
  ```typescript
69
- import { AuthProvider } from "@leanmcp/auth";
76
+ import { AuthProvider } from '@leanmcp/auth';
70
77
 
71
78
  const authProvider = new AuthProvider('cognito', {
72
79
  region: 'us-east-1',
73
80
  userPoolId: 'us-east-1_XXXXXXXXX',
74
- clientId: 'your-client-id'
81
+ clientId: 'your-client-id',
75
82
  });
76
83
 
77
84
  await authProvider.init();
@@ -80,8 +87,8 @@ await authProvider.init();
80
87
  ### 2. Protect Methods with @Authenticated
81
88
 
82
89
  ```typescript
83
- import { Tool } from "@leanmcp/core";
84
- import { Authenticated } from "@leanmcp/auth";
90
+ import { Tool } from '@leanmcp/core';
91
+ import { Authenticated } from '@leanmcp/auth';
85
92
 
86
93
  export class SentimentService {
87
94
  @Tool({ description: 'Analyze sentiment (requires auth)' })
@@ -91,10 +98,10 @@ export class SentimentService {
91
98
  console.log('User ID:', authUser.sub);
92
99
  console.log('Email:', authUser.email);
93
100
 
94
- return {
95
- sentiment: 'positive',
101
+ return {
102
+ sentiment: 'positive',
96
103
  score: 0.8,
97
- analyzedBy: authUser.sub
104
+ analyzedBy: authUser.sub,
98
105
  };
99
106
  }
100
107
 
@@ -143,6 +150,7 @@ async createPost(input: { title: string, content: string }) {
143
150
  ### Provider-Specific User Data
144
151
 
145
152
  **AWS Cognito:**
153
+
146
154
  ```typescript
147
155
  {
148
156
  sub: 'user-uuid',
@@ -154,6 +162,7 @@ async createPost(input: { title: string, content: string }) {
154
162
  ```
155
163
 
156
164
  **Clerk:**
165
+
157
166
  ```typescript
158
167
  {
159
168
  sub: 'user_2abc123xyz',
@@ -166,6 +175,7 @@ async createPost(input: { title: string, content: string }) {
166
175
  ```
167
176
 
168
177
  **Auth0:**
178
+
169
179
  ```typescript
170
180
  {
171
181
  sub: 'auth0|507f1f77bcf86cd799439011',
@@ -202,12 +212,13 @@ async tokenOnlyValidation(input: any) {
202
212
  const authProvider = new AuthProvider('cognito', {
203
213
  region: 'us-east-1',
204
214
  userPoolId: 'us-east-1_XXXXXXXXX',
205
- clientId: 'your-client-id'
215
+ clientId: 'your-client-id',
206
216
  });
207
217
  await authProvider.init();
208
218
  ```
209
219
 
210
220
  **Environment Variables:**
221
+
211
222
  ```bash
212
223
  AWS_REGION=us-east-1
213
224
  COGNITO_USER_POOL_ID=us-east-1_XXXXXXXXX
@@ -220,7 +231,7 @@ COGNITO_CLIENT_ID=your-client-id
220
231
  // Session Mode (default)
221
232
  const authProvider = new AuthProvider('clerk', {
222
233
  frontendApi: 'your-frontend-api.clerk.accounts.dev',
223
- secretKey: 'sk_test_...'
234
+ secretKey: 'sk_test_...',
224
235
  });
225
236
 
226
237
  // OAuth Mode (with refresh tokens)
@@ -229,7 +240,7 @@ const authProvider = new AuthProvider('clerk', {
229
240
  secretKey: 'sk_test_...',
230
241
  clientId: 'your-oauth-client-id',
231
242
  clientSecret: 'your-oauth-client-secret',
232
- redirectUri: 'https://yourapp.com/callback'
243
+ redirectUri: 'https://yourapp.com/callback',
233
244
  });
234
245
 
235
246
  await authProvider.init();
@@ -242,7 +253,7 @@ const authProvider = new AuthProvider('auth0', {
242
253
  domain: 'your-tenant.auth0.com',
243
254
  clientId: 'your-client-id',
244
255
  clientSecret: 'your-client-secret',
245
- audience: 'https://your-api-identifier'
256
+ audience: 'https://your-api-identifier',
246
257
  });
247
258
  await authProvider.init();
248
259
  ```
@@ -253,7 +264,7 @@ For LeanMCP platform deployments with user secrets support:
253
264
 
254
265
  ```typescript
255
266
  const authProvider = new AuthProvider('leanmcp', {
256
- apiKey: 'your-leanmcp-api-key'
267
+ apiKey: 'your-leanmcp-api-key',
257
268
  });
258
269
  await authProvider.init();
259
270
  ```
@@ -266,14 +277,14 @@ Authentication tokens are passed via the `_meta` field following MCP protocol st
266
277
 
267
278
  ```typescript
268
279
  await mcpClient.callTool({
269
- name: "analyzeSentiment",
270
- arguments: { text: "Hello world" },
280
+ name: 'analyzeSentiment',
281
+ arguments: { text: 'Hello world' },
271
282
  _meta: {
272
283
  authorization: {
273
- type: "bearer",
274
- token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
275
- }
276
- }
284
+ type: 'bearer',
285
+ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
286
+ },
287
+ },
277
288
  });
278
289
  ```
279
290
 
@@ -282,10 +293,10 @@ await mcpClient.callTool({
282
293
  ## Error Handling
283
294
 
284
295
  ```typescript
285
- import { AuthenticationError } from "@leanmcp/auth";
296
+ import { AuthenticationError } from '@leanmcp/auth';
286
297
 
287
298
  try {
288
- await service.protectedMethod({ text: "test" });
299
+ await service.protectedMethod({ text: 'test' });
289
300
  } catch (error) {
290
301
  if (error instanceof AuthenticationError) {
291
302
  switch (error.code) {
@@ -324,13 +335,13 @@ class AuthProvider {
324
335
 
325
336
  ```typescript
326
337
  function Authenticated(
327
- authProvider: AuthProvider,
338
+ authProvider: AuthProvider,
328
339
  options?: AuthenticatedOptions
329
340
  ): ClassDecorator | MethodDecorator;
330
341
 
331
342
  interface AuthenticatedOptions {
332
- getUser?: boolean; // Default: true
333
- projectId?: string; // For LeanMCP user secrets
343
+ getUser?: boolean; // Default: true
344
+ projectId?: string; // For LeanMCP user secrets
334
345
  }
335
346
  ```
336
347
 
@@ -361,17 +372,20 @@ function getAuthUser(): any;
361
372
  ## Best Practices
362
373
 
363
374
  ### Security
375
+
364
376
  - Always use HTTPS in production
365
377
  - Store tokens securely (keychain, encrypted storage)
366
378
  - Implement token refresh before expiration
367
379
  - Add rate limiting to protect against brute force
368
380
 
369
381
  ### Configuration
382
+
370
383
  - Use environment variables for credentials
371
384
  - Never hardcode secrets in code
372
385
  - Use `_meta` for auth, not business arguments
373
386
 
374
387
  ### Performance
388
+
375
389
  - Use `getUser: false` when you only need token validation
376
390
  - JWKS keys are cached automatically for performance
377
391
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AuthProviderBase
3
- } from "./chunk-P4HFKA5R.mjs";
3
+ } from "./chunk-ZJYMG6ZM.mjs";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-LPEX4YW6.mjs";
@@ -31,14 +31,14 @@ var MemoryStorage = class {
31
31
  tokens = /* @__PURE__ */ new Map();
32
32
  clients = /* @__PURE__ */ new Map();
33
33
  /**
34
- * Normalize server URL for consistent key lookup
35
- */
34
+ * Normalize server URL for consistent key lookup
35
+ */
36
36
  normalizeUrl(serverUrl) {
37
37
  return serverUrl.replace(/\/+$/, "").toLowerCase();
38
38
  }
39
39
  /**
40
- * Check if an entry is expired
41
- */
40
+ * Check if an entry is expired
41
+ */
42
42
  isExpired(entry) {
43
43
  if (!entry) return true;
44
44
  if (!entry.expiresAt) return false;
@@ -176,25 +176,25 @@ var AuthProvider = class extends AuthProviderBase {
176
176
  const finalConfig = config || this.config;
177
177
  switch (this.providerType) {
178
178
  case "cognito": {
179
- const { AuthCognito } = await import("./cognito-QQT7LK2Y.mjs");
179
+ const { AuthCognito } = await import("./cognito-XKPEG6UH.mjs");
180
180
  this.providerInstance = new AuthCognito();
181
181
  await this.providerInstance.init(finalConfig);
182
182
  break;
183
183
  }
184
184
  case "auth0": {
185
- const { AuthAuth0 } = await import("./auth0-UTD4QBG6.mjs");
185
+ const { AuthAuth0 } = await import("./auth0-DWCHZ7IN.mjs");
186
186
  this.providerInstance = new AuthAuth0();
187
187
  await this.providerInstance.init(finalConfig);
188
188
  break;
189
189
  }
190
190
  case "clerk": {
191
- const { AuthClerk } = await import("./clerk-3SDKGD6C.mjs");
191
+ const { AuthClerk } = await import("./clerk-YVTZMRLF.mjs");
192
192
  this.providerInstance = new AuthClerk();
193
193
  await this.providerInstance.init(finalConfig);
194
194
  break;
195
195
  }
196
196
  case "leanmcp": {
197
- const { AuthLeanmcp } = await import("./leanmcp-Y7TXNSTD.mjs");
197
+ const { AuthLeanmcp } = await import("./leanmcp-73RUGZ2B.mjs");
198
198
  this.providerInstance = new AuthLeanmcp();
199
199
  await this.providerInstance.init(finalConfig);
200
200
  break;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AuthProviderBase
3
- } from "./chunk-P4HFKA5R.mjs";
3
+ } from "./chunk-ZJYMG6ZM.mjs";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-LPEX4YW6.mjs";