@leanmcp/auth 0.4.3 → 0.4.4-alpha.8.f4673cd
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/LICENSE +21 -21
- package/README.md +410 -396
- package/dist/{auth0-UTD4QBG6.mjs → auth0-DWCHZ7IN.mjs} +1 -1
- package/dist/{chunk-RGCCBQWG.mjs → chunk-MXTUNMHA.mjs} +4 -4
- package/dist/{chunk-P4HFKA5R.mjs → chunk-ZJYMG6ZM.mjs} +4 -4
- package/dist/{clerk-3SDKGD6C.mjs → clerk-YVTZMRLF.mjs} +1 -1
- package/dist/client/index.js +56 -56
- package/dist/client/index.mjs +53 -53
- package/dist/{cognito-QQT7LK2Y.mjs → cognito-XKPEG6UH.mjs} +1 -1
- package/dist/index.js +8 -8
- package/dist/index.mjs +1 -1
- package/dist/{leanmcp-Y7TXNSTD.mjs → leanmcp-73RUGZ2B.mjs} +9 -9
- package/dist/proxy/index.js +36 -36
- package/dist/proxy/index.mjs +36 -36
- package/dist/server/index.js +69 -69
- package/dist/server/index.mjs +69 -69
- package/dist/storage/index.js +24 -24
- package/dist/storage/index.mjs +21 -21
- package/package.json +121 -121
|
@@ -31,14 +31,14 @@ var MemoryStorage = class {
|
|
|
31
31
|
tokens = /* @__PURE__ */ new Map();
|
|
32
32
|
clients = /* @__PURE__ */ new Map();
|
|
33
33
|
/**
|
|
34
|
-
|
|
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
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
197
|
+
const { AuthLeanmcp } = await import("./leanmcp-73RUGZ2B.mjs");
|
|
198
198
|
this.providerInstance = new AuthLeanmcp();
|
|
199
199
|
await this.providerInstance.init(finalConfig);
|
|
200
200
|
break;
|
package/dist/client/index.js
CHANGED
|
@@ -292,14 +292,14 @@ var MemoryStorage = class {
|
|
|
292
292
|
tokens = /* @__PURE__ */ new Map();
|
|
293
293
|
clients = /* @__PURE__ */ new Map();
|
|
294
294
|
/**
|
|
295
|
-
|
|
296
|
-
|
|
295
|
+
* Normalize server URL for consistent key lookup
|
|
296
|
+
*/
|
|
297
297
|
normalizeUrl(serverUrl) {
|
|
298
298
|
return serverUrl.replace(/\/+$/, "").toLowerCase();
|
|
299
299
|
}
|
|
300
300
|
/**
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
* Check if an entry is expired
|
|
302
|
+
*/
|
|
303
303
|
isExpired(entry) {
|
|
304
304
|
if (!entry) return true;
|
|
305
305
|
if (!entry.expiresAt) return false;
|
|
@@ -408,8 +408,8 @@ var OAuthClient = class {
|
|
|
408
408
|
this.preConfiguredClientSecret = options.clientSecret;
|
|
409
409
|
}
|
|
410
410
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
411
|
+
* Discover OAuth metadata from .well-known endpoint
|
|
412
|
+
*/
|
|
413
413
|
async discoverMetadata() {
|
|
414
414
|
if (this.metadata) return this.metadata;
|
|
415
415
|
const wellKnownUrl = `${this.serverUrl}/.well-known/oauth-authorization-server`;
|
|
@@ -439,8 +439,8 @@ var OAuthClient = class {
|
|
|
439
439
|
return this.metadata;
|
|
440
440
|
}
|
|
441
441
|
/**
|
|
442
|
-
|
|
443
|
-
|
|
442
|
+
* Get or register OAuth client credentials
|
|
443
|
+
*/
|
|
444
444
|
async getClientCredentials(redirectUri) {
|
|
445
445
|
if (this.preConfiguredClientId) {
|
|
446
446
|
return {
|
|
@@ -486,12 +486,12 @@ var OAuthClient = class {
|
|
|
486
486
|
return registration;
|
|
487
487
|
}
|
|
488
488
|
/**
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
489
|
+
* Start the browser-based OAuth flow
|
|
490
|
+
*
|
|
491
|
+
* Opens the user's browser to the authorization URL and waits for the callback.
|
|
492
|
+
*
|
|
493
|
+
* @returns OAuth tokens
|
|
494
|
+
*/
|
|
495
495
|
async authenticate() {
|
|
496
496
|
const existing = await this.storage.getTokens(this.serverUrl);
|
|
497
497
|
if (existing && !isTokenExpired(existing, this.refreshBuffer)) {
|
|
@@ -548,8 +548,8 @@ ${authUrl.toString()}
|
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
/**
|
|
551
|
-
|
|
552
|
-
|
|
551
|
+
* Open URL in browser
|
|
552
|
+
*/
|
|
553
553
|
async openBrowser(url) {
|
|
554
554
|
try {
|
|
555
555
|
const open = require("open");
|
|
@@ -573,8 +573,8 @@ ${authUrl.toString()}
|
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
/**
|
|
576
|
-
|
|
577
|
-
|
|
576
|
+
* Exchange authorization code for tokens
|
|
577
|
+
*/
|
|
578
578
|
async exchangeCodeForTokens(code, redirectUri, credentials, codeVerifier) {
|
|
579
579
|
const metadata = await this.discoverMetadata();
|
|
580
580
|
const tokenPayload = {
|
|
@@ -603,8 +603,8 @@ ${authUrl.toString()}
|
|
|
603
603
|
return response.json();
|
|
604
604
|
}
|
|
605
605
|
/**
|
|
606
|
-
|
|
607
|
-
|
|
606
|
+
* Refresh the access token using the refresh token
|
|
607
|
+
*/
|
|
608
608
|
async refreshTokens() {
|
|
609
609
|
if (this.pendingRefresh) {
|
|
610
610
|
return this.pendingRefresh;
|
|
@@ -651,8 +651,8 @@ ${authUrl.toString()}
|
|
|
651
651
|
return enrichedTokens;
|
|
652
652
|
}
|
|
653
653
|
/**
|
|
654
|
-
|
|
655
|
-
|
|
654
|
+
* Get a valid access token, refreshing if necessary
|
|
655
|
+
*/
|
|
656
656
|
async getValidToken() {
|
|
657
657
|
let tokens = await this.storage.getTokens(this.serverUrl);
|
|
658
658
|
if (!tokens) {
|
|
@@ -668,35 +668,35 @@ ${authUrl.toString()}
|
|
|
668
668
|
return tokens.access_token;
|
|
669
669
|
}
|
|
670
670
|
/**
|
|
671
|
-
|
|
672
|
-
|
|
671
|
+
* Get current tokens (may be expired)
|
|
672
|
+
*/
|
|
673
673
|
async getTokens() {
|
|
674
674
|
return this.storage.getTokens(this.serverUrl);
|
|
675
675
|
}
|
|
676
676
|
/**
|
|
677
|
-
|
|
678
|
-
|
|
677
|
+
* Check if we have valid (non-expired) tokens
|
|
678
|
+
*/
|
|
679
679
|
async isAuthenticated() {
|
|
680
680
|
const tokens = await this.storage.getTokens(this.serverUrl);
|
|
681
681
|
if (!tokens) return false;
|
|
682
682
|
return !isTokenExpired(tokens, this.refreshBuffer) || !!tokens.refresh_token;
|
|
683
683
|
}
|
|
684
684
|
/**
|
|
685
|
-
|
|
686
|
-
|
|
685
|
+
* Clear stored tokens and log out
|
|
686
|
+
*/
|
|
687
687
|
async logout() {
|
|
688
688
|
await this.storage.clearTokens(this.serverUrl);
|
|
689
689
|
await this.storage.clearClientInfo(this.serverUrl);
|
|
690
690
|
}
|
|
691
691
|
/**
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
692
|
+
* Create an auth handler for HTTP requests
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* const authHandler = client.asAuthHandler();
|
|
697
|
+
* const authedRequest = await authHandler(request);
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
700
|
asAuthHandler() {
|
|
701
701
|
return async (request) => {
|
|
702
702
|
const token = await this.getValidToken();
|
|
@@ -731,7 +731,7 @@ async function discoverOAuthMetadata(serverUrl, options = {}) {
|
|
|
731
731
|
const response = await customFetch(oauthUrl, {
|
|
732
732
|
signal: controller.signal,
|
|
733
733
|
headers: {
|
|
734
|
-
|
|
734
|
+
Accept: "application/json"
|
|
735
735
|
}
|
|
736
736
|
});
|
|
737
737
|
if (response.ok) {
|
|
@@ -746,7 +746,7 @@ async function discoverOAuthMetadata(serverUrl, options = {}) {
|
|
|
746
746
|
const response = await customFetch(oidcUrl, {
|
|
747
747
|
signal: controller.signal,
|
|
748
748
|
headers: {
|
|
749
|
-
|
|
749
|
+
Accept: "application/json"
|
|
750
750
|
}
|
|
751
751
|
});
|
|
752
752
|
if (response.ok) {
|
|
@@ -852,8 +852,8 @@ var RefreshManager = class {
|
|
|
852
852
|
this.retryDelay = options.retryDelay ?? 5e3;
|
|
853
853
|
}
|
|
854
854
|
/**
|
|
855
|
-
|
|
856
|
-
|
|
855
|
+
* Start background refresh monitoring
|
|
856
|
+
*/
|
|
857
857
|
start() {
|
|
858
858
|
if (this.isRunning) return;
|
|
859
859
|
this.isRunning = true;
|
|
@@ -863,8 +863,8 @@ var RefreshManager = class {
|
|
|
863
863
|
}, this.checkInterval);
|
|
864
864
|
}
|
|
865
865
|
/**
|
|
866
|
-
|
|
867
|
-
|
|
866
|
+
* Stop background refresh monitoring
|
|
867
|
+
*/
|
|
868
868
|
stop() {
|
|
869
869
|
this.isRunning = false;
|
|
870
870
|
if (this.intervalId) {
|
|
@@ -873,8 +873,8 @@ var RefreshManager = class {
|
|
|
873
873
|
}
|
|
874
874
|
}
|
|
875
875
|
/**
|
|
876
|
-
|
|
877
|
-
|
|
876
|
+
* Register event listener
|
|
877
|
+
*/
|
|
878
878
|
on(listener) {
|
|
879
879
|
this.listeners.push(listener);
|
|
880
880
|
return () => {
|
|
@@ -882,8 +882,8 @@ var RefreshManager = class {
|
|
|
882
882
|
};
|
|
883
883
|
}
|
|
884
884
|
/**
|
|
885
|
-
|
|
886
|
-
|
|
885
|
+
* Emit event to all listeners
|
|
886
|
+
*/
|
|
887
887
|
emit(event) {
|
|
888
888
|
for (const listener of this.listeners) {
|
|
889
889
|
try {
|
|
@@ -893,8 +893,8 @@ var RefreshManager = class {
|
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
895
|
/**
|
|
896
|
-
|
|
897
|
-
|
|
896
|
+
* Check token and refresh if needed
|
|
897
|
+
*/
|
|
898
898
|
async checkAndRefresh() {
|
|
899
899
|
if (this.pendingRefresh) return;
|
|
900
900
|
try {
|
|
@@ -917,8 +917,8 @@ var RefreshManager = class {
|
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
919
|
/**
|
|
920
|
-
|
|
921
|
-
|
|
920
|
+
* Perform token refresh with retry logic
|
|
921
|
+
*/
|
|
922
922
|
async performRefresh(refreshToken) {
|
|
923
923
|
this.emit({
|
|
924
924
|
type: "refresh_started",
|
|
@@ -950,8 +950,8 @@ var RefreshManager = class {
|
|
|
950
950
|
}
|
|
951
951
|
}
|
|
952
952
|
/**
|
|
953
|
-
|
|
954
|
-
|
|
953
|
+
* Actually perform the refresh
|
|
954
|
+
*/
|
|
955
955
|
async doRefresh(refreshToken) {
|
|
956
956
|
const newTokens = await this.refreshFn(refreshToken);
|
|
957
957
|
const enrichedTokens = withExpiresAt(newTokens);
|
|
@@ -962,8 +962,8 @@ var RefreshManager = class {
|
|
|
962
962
|
return enrichedTokens;
|
|
963
963
|
}
|
|
964
964
|
/**
|
|
965
|
-
|
|
966
|
-
|
|
965
|
+
* Force an immediate refresh
|
|
966
|
+
*/
|
|
967
967
|
async forceRefresh() {
|
|
968
968
|
const tokens = await this.storage.getTokens(this.serverUrl);
|
|
969
969
|
if (!tokens?.refresh_token) {
|
|
@@ -986,8 +986,8 @@ var RefreshManager = class {
|
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
988
|
/**
|
|
989
|
-
|
|
990
|
-
|
|
989
|
+
* Get current running state
|
|
990
|
+
*/
|
|
991
991
|
get running() {
|
|
992
992
|
return this.isRunning;
|
|
993
993
|
}
|
package/dist/client/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
MemoryStorage,
|
|
10
10
|
isTokenExpired,
|
|
11
11
|
withExpiresAt
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-MXTUNMHA.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__name,
|
|
15
15
|
__require
|
|
@@ -239,8 +239,8 @@ var OAuthClient = class {
|
|
|
239
239
|
this.preConfiguredClientSecret = options.clientSecret;
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
* Discover OAuth metadata from .well-known endpoint
|
|
243
|
+
*/
|
|
244
244
|
async discoverMetadata() {
|
|
245
245
|
if (this.metadata) return this.metadata;
|
|
246
246
|
const wellKnownUrl = `${this.serverUrl}/.well-known/oauth-authorization-server`;
|
|
@@ -270,8 +270,8 @@ var OAuthClient = class {
|
|
|
270
270
|
return this.metadata;
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
* Get or register OAuth client credentials
|
|
274
|
+
*/
|
|
275
275
|
async getClientCredentials(redirectUri) {
|
|
276
276
|
if (this.preConfiguredClientId) {
|
|
277
277
|
return {
|
|
@@ -317,12 +317,12 @@ var OAuthClient = class {
|
|
|
317
317
|
return registration;
|
|
318
318
|
}
|
|
319
319
|
/**
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
320
|
+
* Start the browser-based OAuth flow
|
|
321
|
+
*
|
|
322
|
+
* Opens the user's browser to the authorization URL and waits for the callback.
|
|
323
|
+
*
|
|
324
|
+
* @returns OAuth tokens
|
|
325
|
+
*/
|
|
326
326
|
async authenticate() {
|
|
327
327
|
const existing = await this.storage.getTokens(this.serverUrl);
|
|
328
328
|
if (existing && !isTokenExpired(existing, this.refreshBuffer)) {
|
|
@@ -379,8 +379,8 @@ ${authUrl.toString()}
|
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
/**
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
* Open URL in browser
|
|
383
|
+
*/
|
|
384
384
|
async openBrowser(url) {
|
|
385
385
|
try {
|
|
386
386
|
const open = __require("open");
|
|
@@ -404,8 +404,8 @@ ${authUrl.toString()}
|
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
* Exchange authorization code for tokens
|
|
408
|
+
*/
|
|
409
409
|
async exchangeCodeForTokens(code, redirectUri, credentials, codeVerifier) {
|
|
410
410
|
const metadata = await this.discoverMetadata();
|
|
411
411
|
const tokenPayload = {
|
|
@@ -434,8 +434,8 @@ ${authUrl.toString()}
|
|
|
434
434
|
return response.json();
|
|
435
435
|
}
|
|
436
436
|
/**
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
* Refresh the access token using the refresh token
|
|
438
|
+
*/
|
|
439
439
|
async refreshTokens() {
|
|
440
440
|
if (this.pendingRefresh) {
|
|
441
441
|
return this.pendingRefresh;
|
|
@@ -482,8 +482,8 @@ ${authUrl.toString()}
|
|
|
482
482
|
return enrichedTokens;
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
|
-
|
|
486
|
-
|
|
485
|
+
* Get a valid access token, refreshing if necessary
|
|
486
|
+
*/
|
|
487
487
|
async getValidToken() {
|
|
488
488
|
let tokens = await this.storage.getTokens(this.serverUrl);
|
|
489
489
|
if (!tokens) {
|
|
@@ -499,35 +499,35 @@ ${authUrl.toString()}
|
|
|
499
499
|
return tokens.access_token;
|
|
500
500
|
}
|
|
501
501
|
/**
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
* Get current tokens (may be expired)
|
|
503
|
+
*/
|
|
504
504
|
async getTokens() {
|
|
505
505
|
return this.storage.getTokens(this.serverUrl);
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
508
|
-
|
|
509
|
-
|
|
508
|
+
* Check if we have valid (non-expired) tokens
|
|
509
|
+
*/
|
|
510
510
|
async isAuthenticated() {
|
|
511
511
|
const tokens = await this.storage.getTokens(this.serverUrl);
|
|
512
512
|
if (!tokens) return false;
|
|
513
513
|
return !isTokenExpired(tokens, this.refreshBuffer) || !!tokens.refresh_token;
|
|
514
514
|
}
|
|
515
515
|
/**
|
|
516
|
-
|
|
517
|
-
|
|
516
|
+
* Clear stored tokens and log out
|
|
517
|
+
*/
|
|
518
518
|
async logout() {
|
|
519
519
|
await this.storage.clearTokens(this.serverUrl);
|
|
520
520
|
await this.storage.clearClientInfo(this.serverUrl);
|
|
521
521
|
}
|
|
522
522
|
/**
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
523
|
+
* Create an auth handler for HTTP requests
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* const authHandler = client.asAuthHandler();
|
|
528
|
+
* const authedRequest = await authHandler(request);
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
531
|
asAuthHandler() {
|
|
532
532
|
return async (request) => {
|
|
533
533
|
const token = await this.getValidToken();
|
|
@@ -562,7 +562,7 @@ async function discoverOAuthMetadata(serverUrl, options = {}) {
|
|
|
562
562
|
const response = await customFetch(oauthUrl, {
|
|
563
563
|
signal: controller.signal,
|
|
564
564
|
headers: {
|
|
565
|
-
|
|
565
|
+
Accept: "application/json"
|
|
566
566
|
}
|
|
567
567
|
});
|
|
568
568
|
if (response.ok) {
|
|
@@ -577,7 +577,7 @@ async function discoverOAuthMetadata(serverUrl, options = {}) {
|
|
|
577
577
|
const response = await customFetch(oidcUrl, {
|
|
578
578
|
signal: controller.signal,
|
|
579
579
|
headers: {
|
|
580
|
-
|
|
580
|
+
Accept: "application/json"
|
|
581
581
|
}
|
|
582
582
|
});
|
|
583
583
|
if (response.ok) {
|
|
@@ -683,8 +683,8 @@ var RefreshManager = class {
|
|
|
683
683
|
this.retryDelay = options.retryDelay ?? 5e3;
|
|
684
684
|
}
|
|
685
685
|
/**
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
* Start background refresh monitoring
|
|
687
|
+
*/
|
|
688
688
|
start() {
|
|
689
689
|
if (this.isRunning) return;
|
|
690
690
|
this.isRunning = true;
|
|
@@ -694,8 +694,8 @@ var RefreshManager = class {
|
|
|
694
694
|
}, this.checkInterval);
|
|
695
695
|
}
|
|
696
696
|
/**
|
|
697
|
-
|
|
698
|
-
|
|
697
|
+
* Stop background refresh monitoring
|
|
698
|
+
*/
|
|
699
699
|
stop() {
|
|
700
700
|
this.isRunning = false;
|
|
701
701
|
if (this.intervalId) {
|
|
@@ -704,8 +704,8 @@ var RefreshManager = class {
|
|
|
704
704
|
}
|
|
705
705
|
}
|
|
706
706
|
/**
|
|
707
|
-
|
|
708
|
-
|
|
707
|
+
* Register event listener
|
|
708
|
+
*/
|
|
709
709
|
on(listener) {
|
|
710
710
|
this.listeners.push(listener);
|
|
711
711
|
return () => {
|
|
@@ -713,8 +713,8 @@ var RefreshManager = class {
|
|
|
713
713
|
};
|
|
714
714
|
}
|
|
715
715
|
/**
|
|
716
|
-
|
|
717
|
-
|
|
716
|
+
* Emit event to all listeners
|
|
717
|
+
*/
|
|
718
718
|
emit(event) {
|
|
719
719
|
for (const listener of this.listeners) {
|
|
720
720
|
try {
|
|
@@ -724,8 +724,8 @@ var RefreshManager = class {
|
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
/**
|
|
727
|
-
|
|
728
|
-
|
|
727
|
+
* Check token and refresh if needed
|
|
728
|
+
*/
|
|
729
729
|
async checkAndRefresh() {
|
|
730
730
|
if (this.pendingRefresh) return;
|
|
731
731
|
try {
|
|
@@ -748,8 +748,8 @@ var RefreshManager = class {
|
|
|
748
748
|
}
|
|
749
749
|
}
|
|
750
750
|
/**
|
|
751
|
-
|
|
752
|
-
|
|
751
|
+
* Perform token refresh with retry logic
|
|
752
|
+
*/
|
|
753
753
|
async performRefresh(refreshToken) {
|
|
754
754
|
this.emit({
|
|
755
755
|
type: "refresh_started",
|
|
@@ -781,8 +781,8 @@ var RefreshManager = class {
|
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
/**
|
|
784
|
-
|
|
785
|
-
|
|
784
|
+
* Actually perform the refresh
|
|
785
|
+
*/
|
|
786
786
|
async doRefresh(refreshToken) {
|
|
787
787
|
const newTokens = await this.refreshFn(refreshToken);
|
|
788
788
|
const enrichedTokens = withExpiresAt(newTokens);
|
|
@@ -793,8 +793,8 @@ var RefreshManager = class {
|
|
|
793
793
|
return enrichedTokens;
|
|
794
794
|
}
|
|
795
795
|
/**
|
|
796
|
-
|
|
797
|
-
|
|
796
|
+
* Force an immediate refresh
|
|
797
|
+
*/
|
|
798
798
|
async forceRefresh() {
|
|
799
799
|
const tokens = await this.storage.getTokens(this.serverUrl);
|
|
800
800
|
if (!tokens?.refresh_token) {
|
|
@@ -817,8 +817,8 @@ var RefreshManager = class {
|
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
819
|
/**
|
|
820
|
-
|
|
821
|
-
|
|
820
|
+
* Get current running state
|
|
821
|
+
*/
|
|
822
822
|
get running() {
|
|
823
823
|
return this.isRunning;
|
|
824
824
|
}
|
package/dist/index.js
CHANGED
|
@@ -669,13 +669,13 @@ var init_leanmcp = __esm({
|
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
671
|
/**
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
672
|
+
* Fetch user-specific environment variables for a project
|
|
673
|
+
* Uses the user's UID and project ID to retrieve their stored secrets
|
|
674
|
+
*
|
|
675
|
+
* @param token - User's auth token
|
|
676
|
+
* @param projectId - Project ID to scope the secrets
|
|
677
|
+
* @returns Record of environment variables
|
|
678
|
+
*/
|
|
679
679
|
async getUserSecrets(token, projectId) {
|
|
680
680
|
if (!this.apiKey) {
|
|
681
681
|
console.warn("[LeanMCP] API key not configured - cannot fetch user secrets. Set LEANMCP_API_KEY environment variable or pass apiKey in config.");
|
|
@@ -685,7 +685,7 @@ var init_leanmcp = __esm({
|
|
|
685
685
|
try {
|
|
686
686
|
const { data } = await import_axios4.default.get(url, {
|
|
687
687
|
headers: {
|
|
688
|
-
|
|
688
|
+
Authorization: `Bearer ${token}`,
|
|
689
689
|
"x-api-key": this.apiKey
|
|
690
690
|
}
|
|
691
691
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthProviderBase
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZJYMG6ZM.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-LPEX4YW6.mjs";
|
|
@@ -108,13 +108,13 @@ var AuthLeanmcp = class extends AuthProviderBase {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
* Fetch user-specific environment variables for a project
|
|
112
|
+
* Uses the user's UID and project ID to retrieve their stored secrets
|
|
113
|
+
*
|
|
114
|
+
* @param token - User's auth token
|
|
115
|
+
* @param projectId - Project ID to scope the secrets
|
|
116
|
+
* @returns Record of environment variables
|
|
117
|
+
*/
|
|
118
118
|
async getUserSecrets(token, projectId) {
|
|
119
119
|
if (!this.apiKey) {
|
|
120
120
|
console.warn("[LeanMCP] API key not configured - cannot fetch user secrets. Set LEANMCP_API_KEY environment variable or pass apiKey in config.");
|
|
@@ -124,7 +124,7 @@ var AuthLeanmcp = class extends AuthProviderBase {
|
|
|
124
124
|
try {
|
|
125
125
|
const { data } = await axios.get(url, {
|
|
126
126
|
headers: {
|
|
127
|
-
|
|
127
|
+
Authorization: `Bearer ${token}`,
|
|
128
128
|
"x-api-key": this.apiKey
|
|
129
129
|
}
|
|
130
130
|
});
|