fastmcp 4.28.0 → 4.28.2

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/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkAAPHX5IGcjs = require('./chunk-AAPHX5IG.cjs');
14
+ var _chunkGW5MENCIcjs = require('./chunk-GW5MENCI.cjs');
15
15
 
16
16
 
17
17
 
@@ -24,7 +24,7 @@ var _chunkAAPHX5IGcjs = require('./chunk-AAPHX5IG.cjs');
24
24
 
25
25
 
26
26
 
27
- var _chunkVVAKRLCYcjs = require('./chunk-VVAKRLCY.cjs');
27
+ var _chunkHZJE6ZGHcjs = require('./chunk-HZJE6ZGH.cjs');
28
28
  require('./chunk-2NZFMD6I.cjs');
29
29
 
30
30
 
@@ -50,5 +50,5 @@ require('./chunk-2NZFMD6I.cjs');
50
50
 
51
51
 
52
52
 
53
- exports.AuthProvider = _chunkVVAKRLCYcjs.AuthProvider; exports.AzureProvider = _chunkVVAKRLCYcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkAAPHX5IGcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkAAPHX5IGcjs.FastMCP; exports.FastMCPError = _chunkAAPHX5IGcjs.FastMCPError; exports.FastMCPSession = _chunkAAPHX5IGcjs.FastMCPSession; exports.GitHubProvider = _chunkVVAKRLCYcjs.GitHubProvider; exports.GoogleProvider = _chunkVVAKRLCYcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkAAPHX5IGcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkVVAKRLCYcjs.OAuthProvider; exports.ServerState = _chunkAAPHX5IGcjs.ServerState; exports.SessionError = _chunkAAPHX5IGcjs.SessionError; exports.UnexpectedStateError = _chunkAAPHX5IGcjs.UnexpectedStateError; exports.UserError = _chunkAAPHX5IGcjs.UserError; exports.audioContent = _chunkAAPHX5IGcjs.audioContent; exports.getAuthSession = _chunkVVAKRLCYcjs.getAuthSession; exports.imageContent = _chunkAAPHX5IGcjs.imageContent; exports.jsonSchemaAdapter = _chunkAAPHX5IGcjs.jsonSchemaAdapter; exports.requireAll = _chunkVVAKRLCYcjs.requireAll; exports.requireAny = _chunkVVAKRLCYcjs.requireAny; exports.requireAuth = _chunkVVAKRLCYcjs.requireAuth; exports.requireRole = _chunkVVAKRLCYcjs.requireRole; exports.requireScopes = _chunkVVAKRLCYcjs.requireScopes;
53
+ exports.AuthProvider = _chunkHZJE6ZGHcjs.AuthProvider; exports.AzureProvider = _chunkHZJE6ZGHcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkGW5MENCIcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkGW5MENCIcjs.FastMCP; exports.FastMCPError = _chunkGW5MENCIcjs.FastMCPError; exports.FastMCPSession = _chunkGW5MENCIcjs.FastMCPSession; exports.GitHubProvider = _chunkHZJE6ZGHcjs.GitHubProvider; exports.GoogleProvider = _chunkHZJE6ZGHcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkGW5MENCIcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkHZJE6ZGHcjs.OAuthProvider; exports.ServerState = _chunkGW5MENCIcjs.ServerState; exports.SessionError = _chunkGW5MENCIcjs.SessionError; exports.UnexpectedStateError = _chunkGW5MENCIcjs.UnexpectedStateError; exports.UserError = _chunkGW5MENCIcjs.UserError; exports.audioContent = _chunkGW5MENCIcjs.audioContent; exports.getAuthSession = _chunkHZJE6ZGHcjs.getAuthSession; exports.imageContent = _chunkGW5MENCIcjs.imageContent; exports.jsonSchemaAdapter = _chunkGW5MENCIcjs.jsonSchemaAdapter; exports.requireAll = _chunkHZJE6ZGHcjs.requireAll; exports.requireAny = _chunkHZJE6ZGHcjs.requireAny; exports.requireAuth = _chunkHZJE6ZGHcjs.requireAuth; exports.requireRole = _chunkHZJE6ZGHcjs.requireRole; exports.requireScopes = _chunkHZJE6ZGHcjs.requireScopes;
54
54
  //# sourceMappingURL=FastMCP.cjs.map
@@ -12,8 +12,8 @@ import { CorsOptions } from 'mcp-proxy';
12
12
  export { CorsOptions } from 'mcp-proxy';
13
13
  import { StrictEventEmitter } from 'strict-event-emitter-types';
14
14
  import { z } from 'zod';
15
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BnQsqcsL.cjs';
16
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BnQsqcsL.cjs';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-DvIxa9N1.cjs';
16
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-DvIxa9N1.cjs';
17
17
  import 'node:http';
18
18
 
19
19
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.d.ts CHANGED
@@ -12,8 +12,8 @@ import { CorsOptions } from 'mcp-proxy';
12
12
  export { CorsOptions } from 'mcp-proxy';
13
13
  import { StrictEventEmitter } from 'strict-event-emitter-types';
14
14
  import { z } from 'zod';
15
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BnQsqcsL.js';
16
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BnQsqcsL.js';
15
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-DvIxa9N1.js';
16
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-DvIxa9N1.js';
17
17
  import 'node:http';
18
18
 
19
19
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-EI3KPYSZ.js";
14
+ } from "./chunk-MBIVAKUB.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "./chunk-4ZSNKIR3.js";
27
+ } from "./chunk-76OY4FEK.js";
28
28
  import "./chunk-AM3HVK4Z.js";
29
29
  export {
30
30
  AuthProvider,
@@ -550,11 +550,9 @@ declare class OAuthProxy {
550
550
  private consentManager;
551
551
  private jwtIssuer?;
552
552
  /**
553
- * The fallback storage this proxy created for itself, if any. It runs a
554
- * cleanup timer that keeps the event loop alive, so `destroy()` has to stop
555
- * it — and once the storage is wrapped for encryption it is reachable
556
- * through nothing else. A caller-supplied storage is deliberately not
557
- * recorded here: its lifetime belongs to the caller.
553
+ * The fallback storage this proxy created for itself, if any. Keep a
554
+ * reference so `destroy()` can stop its cleanup timer even when the storage
555
+ * is wrapped for encryption. Caller-supplied storage has its own lifetime.
558
556
  */
559
557
  private ownedTokenStorage;
560
558
  /**
@@ -781,6 +779,7 @@ declare class OAuthProxy {
781
779
  * itself is a live upstream credential.
782
780
  */
783
781
  private passthroughRefreshKey;
782
+ private redirectToClient;
784
783
  /**
785
784
  * Redirect to upstream OAuth provider
786
785
  */
@@ -550,11 +550,9 @@ declare class OAuthProxy {
550
550
  private consentManager;
551
551
  private jwtIssuer?;
552
552
  /**
553
- * The fallback storage this proxy created for itself, if any. It runs a
554
- * cleanup timer that keeps the event loop alive, so `destroy()` has to stop
555
- * it — and once the storage is wrapped for encryption it is reachable
556
- * through nothing else. A caller-supplied storage is deliberately not
557
- * recorded here: its lifetime belongs to the caller.
553
+ * The fallback storage this proxy created for itself, if any. Keep a
554
+ * reference so `destroy()` can stop its cleanup timer even when the storage
555
+ * is wrapped for encryption. Caller-supplied storage has its own lifetime.
558
556
  */
559
557
  private ownedTokenStorage;
560
558
  /**
@@ -781,6 +779,7 @@ declare class OAuthProxy {
781
779
  * itself is a live upstream credential.
782
780
  */
783
781
  private passthroughRefreshKey;
782
+ private redirectToClient;
784
783
  /**
785
784
  * Redirect to upstream OAuth provider
786
785
  */
@@ -25,7 +25,7 @@
25
25
 
26
26
 
27
27
 
28
- var _chunkVVAKRLCYcjs = require('../chunk-VVAKRLCY.cjs');
28
+ var _chunkHZJE6ZGHcjs = require('../chunk-HZJE6ZGH.cjs');
29
29
 
30
30
 
31
31
 
@@ -53,5 +53,5 @@ var _chunkVVAKRLCYcjs = require('../chunk-VVAKRLCY.cjs');
53
53
 
54
54
 
55
55
 
56
- exports.AuthProvider = _chunkVVAKRLCYcjs.AuthProvider; exports.AzureProvider = _chunkVVAKRLCYcjs.AzureProvider; exports.ConsentManager = _chunkVVAKRLCYcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkVVAKRLCYcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkVVAKRLCYcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkVVAKRLCYcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkVVAKRLCYcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkVVAKRLCYcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkVVAKRLCYcjs.DiskStore; exports.EncryptedTokenStorage = _chunkVVAKRLCYcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkVVAKRLCYcjs.GitHubProvider; exports.GoogleProvider = _chunkVVAKRLCYcjs.GoogleProvider; exports.JWKSVerifier = _chunkVVAKRLCYcjs.JWKSVerifier; exports.JWTIssuer = _chunkVVAKRLCYcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkVVAKRLCYcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkVVAKRLCYcjs.OAuthProvider; exports.OAuthProxy = _chunkVVAKRLCYcjs.OAuthProxy; exports.OAuthProxyError = _chunkVVAKRLCYcjs.OAuthProxyError; exports.PKCEUtils = _chunkVVAKRLCYcjs.PKCEUtils; exports.TOKEN_ENDPOINT_AUTH_METHODS = _chunkVVAKRLCYcjs.TOKEN_ENDPOINT_AUTH_METHODS; exports.getAuthSession = _chunkVVAKRLCYcjs.getAuthSession; exports.requireAll = _chunkVVAKRLCYcjs.requireAll; exports.requireAny = _chunkVVAKRLCYcjs.requireAny; exports.requireAuth = _chunkVVAKRLCYcjs.requireAuth; exports.requireRole = _chunkVVAKRLCYcjs.requireRole; exports.requireScopes = _chunkVVAKRLCYcjs.requireScopes;
56
+ exports.AuthProvider = _chunkHZJE6ZGHcjs.AuthProvider; exports.AzureProvider = _chunkHZJE6ZGHcjs.AzureProvider; exports.ConsentManager = _chunkHZJE6ZGHcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkHZJE6ZGHcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkHZJE6ZGHcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkHZJE6ZGHcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkHZJE6ZGHcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkHZJE6ZGHcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkHZJE6ZGHcjs.DiskStore; exports.EncryptedTokenStorage = _chunkHZJE6ZGHcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkHZJE6ZGHcjs.GitHubProvider; exports.GoogleProvider = _chunkHZJE6ZGHcjs.GoogleProvider; exports.JWKSVerifier = _chunkHZJE6ZGHcjs.JWKSVerifier; exports.JWTIssuer = _chunkHZJE6ZGHcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkHZJE6ZGHcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkHZJE6ZGHcjs.OAuthProvider; exports.OAuthProxy = _chunkHZJE6ZGHcjs.OAuthProxy; exports.OAuthProxyError = _chunkHZJE6ZGHcjs.OAuthProxyError; exports.PKCEUtils = _chunkHZJE6ZGHcjs.PKCEUtils; exports.TOKEN_ENDPOINT_AUTH_METHODS = _chunkHZJE6ZGHcjs.TOKEN_ENDPOINT_AUTH_METHODS; exports.getAuthSession = _chunkHZJE6ZGHcjs.getAuthSession; exports.requireAll = _chunkHZJE6ZGHcjs.requireAll; exports.requireAny = _chunkHZJE6ZGHcjs.requireAny; exports.requireAuth = _chunkHZJE6ZGHcjs.requireAuth; exports.requireRole = _chunkHZJE6ZGHcjs.requireRole; exports.requireScopes = _chunkHZJE6ZGHcjs.requireScopes;
57
57
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BnQsqcsL.cjs';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BnQsqcsL.cjs';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-DvIxa9N1.cjs';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-DvIxa9N1.cjs';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BnQsqcsL.js';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BnQsqcsL.js';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-DvIxa9N1.js';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, E as DCRClientMetadata, F as DCRRequest, H as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, I as OAuthError, d as OAuthProvider, J as OAuthProviderConfig, a as OAuthProxy, K as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, L as ProxyDCRClient, R as RefreshRequest, y as TOKEN_ENDPOINT_AUTH_METHODS, M as TokenEndpointAuthMethod, N as TokenMapping, Q as TokenRequest, S as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-DvIxa9N1.js';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -25,7 +25,7 @@ import {
25
25
  requireAuth,
26
26
  requireRole,
27
27
  requireScopes
28
- } from "../chunk-4ZSNKIR3.js";
28
+ } from "../chunk-76OY4FEK.js";
29
29
  export {
30
30
  AuthProvider,
31
31
  AzureProvider,
@@ -1322,6 +1322,7 @@ var MemoryTokenStorage = class {
1322
1322
  () => void this.cleanup(),
1323
1323
  cleanupIntervalMs
1324
1324
  );
1325
+ this.cleanupInterval.unref?.();
1325
1326
  }
1326
1327
  async cleanup() {
1327
1328
  const now = Date.now();
@@ -1394,7 +1395,8 @@ var DEFAULT_PORTS = {
1394
1395
  "ws:": "80",
1395
1396
  "wss:": "443"
1396
1397
  };
1397
- var CONSENT_COOKIE_VALUE = /^[\w-]{43}$/;
1398
+ var GENERATED_ID = /^[\w-]{43}$/;
1399
+ var OAUTH_ERROR_TEXT = /^[\x20-\x21\x23-\x5b\x5d-\x7e]+$/;
1398
1400
  var MAX_CLIENT_REGISTRATION_BYTES = 32 * 1024;
1399
1401
  var RESERVED_AUTHORIZATION_PARAMS = /* @__PURE__ */ new Set([
1400
1402
  "client_id",
@@ -1416,11 +1418,9 @@ var OAuthProxy = class {
1416
1418
  consentManager;
1417
1419
  jwtIssuer;
1418
1420
  /**
1419
- * The fallback storage this proxy created for itself, if any. It runs a
1420
- * cleanup timer that keeps the event loop alive, so `destroy()` has to stop
1421
- * it — and once the storage is wrapped for encryption it is reachable
1422
- * through nothing else. A caller-supplied storage is deliberately not
1423
- * recorded here: its lifetime belongs to the caller.
1421
+ * The fallback storage this proxy created for itself, if any. Keep a
1422
+ * reference so `destroy()` can stop its cleanup timer even when the storage
1423
+ * is wrapped for encryption. Caller-supplied storage has its own lifetime.
1424
1424
  */
1425
1425
  ownedTokenStorage = null;
1426
1426
  /**
@@ -1739,20 +1739,24 @@ var OAuthProxy = class {
1739
1739
  */
1740
1740
  async handleCallback(request) {
1741
1741
  const url = new URL(request.url);
1742
- const code = url.searchParams.get("code");
1742
+ const code = url.searchParams.get("code") ?? "";
1743
1743
  const state = url.searchParams.get("state");
1744
1744
  const error = url.searchParams.get("error");
1745
+ const description = url.searchParams.get("error_description") || void 0;
1745
1746
  if (error) {
1746
- const errorDescription = url.searchParams.get("error_description");
1747
- throw new OAuthProxyError(error, errorDescription || void 0);
1748
- }
1749
- if (!code || !state) {
1747
+ if (!state || url.searchParams.getAll("state").length !== 1 || !GENERATED_ID.test(state) || !OAUTH_ERROR_TEXT.test(error) || description && !OAUTH_ERROR_TEXT.test(description) || (await this.stateStore.getTransaction(state))?.id !== state) {
1748
+ throw new OAuthProxyError(error, description);
1749
+ }
1750
+ } else if (!code || !state) {
1750
1751
  throw new OAuthProxyError(
1751
1752
  "invalid_request",
1752
1753
  "Missing code or state parameter"
1753
1754
  );
1754
1755
  }
1755
1756
  const transaction = await this.stateStore.consumeTransaction(state);
1757
+ if (error && (transaction?.id !== state || transaction.expiresAt.getTime() <= Date.now())) {
1758
+ throw new OAuthProxyError(error, description);
1759
+ }
1756
1760
  if (!transaction) {
1757
1761
  throw new OAuthProxyError("invalid_request", "Invalid or expired state");
1758
1762
  }
@@ -1768,23 +1772,18 @@ var OAuthProxy = class {
1768
1772
  "Transaction callback URL is not registered"
1769
1773
  );
1770
1774
  }
1775
+ if (error) {
1776
+ return this.redirectToClient(transaction, {
1777
+ error,
1778
+ error_description: description
1779
+ });
1780
+ }
1771
1781
  const upstreamTokens = await this.exchangeUpstreamCode(code, transaction);
1772
1782
  const clientCode = await this.generateAuthorizationCode(
1773
1783
  transaction,
1774
1784
  upstreamTokens
1775
1785
  );
1776
- const redirectUrl = new URL(transaction.clientCallbackUrl);
1777
- redirectUrl.searchParams.set("code", clientCode);
1778
- redirectUrl.searchParams.set("state", transaction.state);
1779
- if (this.config.authorizationResponseIss) {
1780
- redirectUrl.searchParams.set("iss", this.config.baseUrl);
1781
- }
1782
- return new Response(null, {
1783
- headers: {
1784
- Location: redirectUrl.toString()
1785
- },
1786
- status: 302
1787
- });
1786
+ return this.redirectToClient(transaction, { code: clientCode });
1788
1787
  }
1789
1788
  /**
1790
1789
  * Handle consent form submission
@@ -1823,21 +1822,9 @@ var OAuthProxy = class {
1823
1822
  "Transaction callback URL is not registered"
1824
1823
  );
1825
1824
  }
1826
- const redirectUrl = new URL(transaction.clientCallbackUrl);
1827
- redirectUrl.searchParams.set("error", "access_denied");
1828
- redirectUrl.searchParams.set(
1829
- "error_description",
1830
- "User denied authorization"
1831
- );
1832
- redirectUrl.searchParams.set("state", transaction.state);
1833
- if (this.config.authorizationResponseIss) {
1834
- redirectUrl.searchParams.set("iss", this.config.baseUrl);
1835
- }
1836
- return new Response(null, {
1837
- headers: {
1838
- Location: redirectUrl.toString()
1839
- },
1840
- status: 302
1825
+ return this.redirectToClient(transaction, {
1826
+ error: "access_denied",
1827
+ error_description: "User denied authorization"
1841
1828
  });
1842
1829
  }
1843
1830
  const approvedTransaction = {
@@ -2065,7 +2052,7 @@ var OAuthProxy = class {
2065
2052
  const separator = pair.indexOf("=");
2066
2053
  if (separator !== -1 && withoutOptionalWhitespace(pair.slice(0, separator)) === name) {
2067
2054
  const value = withoutOptionalWhitespace(pair.slice(separator + 1));
2068
- return CONSENT_COOKIE_VALUE.test(value) ? value : void 0;
2055
+ return GENERATED_ID.test(value) ? value : void 0;
2069
2056
  }
2070
2057
  }
2071
2058
  return void 0;
@@ -2696,6 +2683,20 @@ var OAuthProxy = class {
2696
2683
  passthroughRefreshKey(refreshToken) {
2697
2684
  return `passthrough-refresh:${sha256(refreshToken)}`;
2698
2685
  }
2686
+ redirectToClient(transaction, params) {
2687
+ const url = new URL(transaction.clientCallbackUrl);
2688
+ for (const [name, value] of Object.entries(params)) {
2689
+ if (value !== void 0) url.searchParams.set(name, value);
2690
+ }
2691
+ url.searchParams.set("state", transaction.state);
2692
+ if (this.config.authorizationResponseIss) {
2693
+ url.searchParams.set("iss", this.config.baseUrl);
2694
+ }
2695
+ return new Response(null, {
2696
+ headers: { Location: url.toString() },
2697
+ status: 302
2698
+ });
2699
+ }
2699
2700
  /**
2700
2701
  * Redirect to upstream OAuth provider
2701
2702
  */
@@ -2873,6 +2874,7 @@ var OAuthProxy = class {
2873
2874
  this.cleanupInterval = setInterval(() => {
2874
2875
  this.cleanup();
2875
2876
  }, 6e4);
2877
+ this.cleanupInterval.unref?.();
2876
2878
  }
2877
2879
  /**
2878
2880
  * Atomically claim a token mapping, mirroring `OAuthProxyStateStore`: at most
@@ -3042,7 +3044,7 @@ var AuthProvider = class {
3042
3044
  return void 0;
3043
3045
  }
3044
3046
  const authHeader = request.headers?.authorization;
3045
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
3047
+ if (!authHeader || !/^Bearer /i.test(authHeader)) {
3046
3048
  return void 0;
3047
3049
  }
3048
3050
  const token = authHeader.slice(7);
@@ -3259,6 +3261,7 @@ var DiskStore = class {
3259
3261
  this.cleanupInterval = setInterval(() => {
3260
3262
  void this.cleanup();
3261
3263
  }, cleanupIntervalMs);
3264
+ this.cleanupInterval.unref?.();
3262
3265
  }
3263
3266
  /**
3264
3267
  * Clean up expired entries
@@ -3611,4 +3614,4 @@ export {
3611
3614
  DiskStore,
3612
3615
  JWKSVerifier
3613
3616
  };
3614
- //# sourceMappingURL=chunk-4ZSNKIR3.js.map
3617
+ //# sourceMappingURL=chunk-76OY4FEK.js.map