@mcpfn/auth 0.0.1 → 0.0.3
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 +57 -3
- package/dist/index.cjs +1816 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +371 -1
- package/dist/index.d.ts +371 -1
- package/dist/index.js +1800 -36
- package/dist/index.js.map +1 -1
- package/package.json +15 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import { OAuthProtectedResourceMetadata, AuthorizationServerMetadata, OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
2
|
+
import { OAuthClientProvider, AddClientAuthentication } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
3
|
+
import { TokenCipher } from '@superfunctions/oauth-storage';
|
|
4
|
+
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
|
|
1
5
|
import { OAuthTokenVerifier } from '@modelcontextprotocol/sdk/server/auth/provider.js';
|
|
2
6
|
import { HandleRequestOptions } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
3
7
|
|
|
8
|
+
declare function readBearerToken(request: Request): string | undefined;
|
|
9
|
+
declare function bearerChallengeResponse(status: 401 | 403, metadataUrl: URL, details: {
|
|
10
|
+
error: string;
|
|
11
|
+
description: string;
|
|
12
|
+
scope?: string;
|
|
13
|
+
}): Response;
|
|
14
|
+
|
|
4
15
|
declare const MCP_ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION_ID = "io.modelcontextprotocol/enterprise-managed-authorization";
|
|
5
16
|
declare const MCP_ID_JAG_GRANT_PROFILE = "urn:ietf:params:oauth:grant-profile:id-jag";
|
|
6
17
|
interface McpFnAuthorizationServerMetadata extends Record<string, unknown> {
|
|
@@ -13,6 +24,299 @@ declare function withEnterpriseManagedAuthorization<T extends McpFnAuthorization
|
|
|
13
24
|
/** Metadata clients attach to requests when declaring extension support. */
|
|
14
25
|
declare function enterpriseManagedAuthorizationClientMetadata(): Record<string, unknown>;
|
|
15
26
|
|
|
27
|
+
interface McpFnAuthorizationDiagnosticStep {
|
|
28
|
+
phase: "resource-discovery" | "authorization-server-discovery";
|
|
29
|
+
status: "passed" | "failed";
|
|
30
|
+
durationMs: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
interface McpFnAuthorizationDiagnosticReport {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
target: string;
|
|
36
|
+
resourceMetadata?: OAuthProtectedResourceMetadata;
|
|
37
|
+
authorizationServerMetadata?: AuthorizationServerMetadata;
|
|
38
|
+
steps: McpFnAuthorizationDiagnosticStep[];
|
|
39
|
+
}
|
|
40
|
+
interface DiagnoseMcpAuthorizationOptions {
|
|
41
|
+
fetchImplementation?: typeof fetch;
|
|
42
|
+
protocolVersion?: string;
|
|
43
|
+
resourceMetadataUrl?: string | URL;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Read-only discovery probe. It does not open a browser or exchange credentials. */
|
|
47
|
+
declare function diagnoseMcpAuthorization(target: string | URL, options?: DiagnoseMcpAuthorizationOptions): Promise<McpFnAuthorizationDiagnosticReport>;
|
|
48
|
+
|
|
49
|
+
interface McpFnRedirectPolicy {
|
|
50
|
+
allowDynamicLoopbackPort?: boolean;
|
|
51
|
+
allowLocalhostLoopback?: boolean;
|
|
52
|
+
allowPrivateUseSchemes?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface McpFnRedirectMatch {
|
|
55
|
+
requested: string;
|
|
56
|
+
registered: string;
|
|
57
|
+
kind: "exact" | "loopback-dynamic-port";
|
|
58
|
+
}
|
|
59
|
+
declare class McpFnRedirectMismatchError extends Error {
|
|
60
|
+
readonly code = "MCPFN_REDIRECT_MISMATCH";
|
|
61
|
+
readonly requested: string;
|
|
62
|
+
constructor(requested: string);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Normalize a registered or requested redirect under the MCP OAuth profile.
|
|
66
|
+
* HTTPS is the default. Plain HTTP is restricted to loopback hosts and
|
|
67
|
+
* fragments/userinfo are always rejected.
|
|
68
|
+
*/
|
|
69
|
+
declare function normalizeMcpRedirectUri(value: string | URL, policy?: McpFnRedirectPolicy): string;
|
|
70
|
+
/** Exact matching, with RFC 8252 loopback ports enabled unless explicitly disabled. */
|
|
71
|
+
declare function matchMcpRedirectUri(requested: string | URL, registeredRedirectUris: ReadonlyArray<string | URL>, policy?: McpFnRedirectPolicy): McpFnRedirectMatch;
|
|
72
|
+
|
|
73
|
+
type McpFnClientRegistrationSource = "pre-registered" | "dynamic" | "client-metadata-document" | "enterprise";
|
|
74
|
+
interface McpFnNormalizedClientRegistration {
|
|
75
|
+
clientId: string;
|
|
76
|
+
source: McpFnClientRegistrationSource;
|
|
77
|
+
redirectUris: string[];
|
|
78
|
+
responseTypes: string[];
|
|
79
|
+
grantTypes: string[];
|
|
80
|
+
tokenEndpointAuthMethod: string;
|
|
81
|
+
metadata: OAuthClientMetadata;
|
|
82
|
+
}
|
|
83
|
+
interface McpFnHostedClientRegistry {
|
|
84
|
+
resolve(clientId: string): Promise<McpFnNormalizedClientRegistration | null>;
|
|
85
|
+
register?(metadata: OAuthClientMetadata, request: Request): Promise<McpFnNormalizedClientRegistration>;
|
|
86
|
+
}
|
|
87
|
+
interface McpFnValidatedAuthorizationRequest {
|
|
88
|
+
client: McpFnNormalizedClientRegistration;
|
|
89
|
+
responseType: "code";
|
|
90
|
+
redirectUri: string;
|
|
91
|
+
redirectMatch: "exact" | "loopback-dynamic-port";
|
|
92
|
+
codeChallenge: string;
|
|
93
|
+
codeChallengeMethod: "S256";
|
|
94
|
+
scopes: string[];
|
|
95
|
+
state?: string;
|
|
96
|
+
resource?: string;
|
|
97
|
+
raw: URLSearchParams;
|
|
98
|
+
}
|
|
99
|
+
type McpFnHostedTokenEndpointAuthMethod = "none" | "client_secret_basic" | "client_secret_post";
|
|
100
|
+
interface McpFnHostedTokenSet {
|
|
101
|
+
access_token: string;
|
|
102
|
+
token_type: string;
|
|
103
|
+
expires_in?: number;
|
|
104
|
+
refresh_token?: string;
|
|
105
|
+
scope?: string;
|
|
106
|
+
resource?: string;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
interface McpFnHostedClientAuthentication {
|
|
110
|
+
client: McpFnNormalizedClientRegistration;
|
|
111
|
+
method: McpFnHostedTokenEndpointAuthMethod;
|
|
112
|
+
}
|
|
113
|
+
interface McpFnHostedTokenAuthority {
|
|
114
|
+
/** Exchange and validate a single-use authorization code and its PKCE binding. */
|
|
115
|
+
exchangeAuthorizationCode(input: McpFnHostedClientAuthentication & {
|
|
116
|
+
code: string;
|
|
117
|
+
redirectUri: string;
|
|
118
|
+
codeVerifier: string;
|
|
119
|
+
resource?: string;
|
|
120
|
+
}, request: Request): Promise<McpFnHostedTokenSet> | McpFnHostedTokenSet;
|
|
121
|
+
/** Presence advertises and enables refresh_token. Calls are serialized per credential. */
|
|
122
|
+
refreshToken?(input: McpFnHostedClientAuthentication & {
|
|
123
|
+
refreshToken: string;
|
|
124
|
+
scopes: string[];
|
|
125
|
+
resource?: string;
|
|
126
|
+
}, request: Request): Promise<McpFnHostedTokenSet> | McpFnHostedTokenSet;
|
|
127
|
+
/** Presence advertises and enables RFC 7009 revocation. */
|
|
128
|
+
revokeToken?(input: McpFnHostedClientAuthentication & {
|
|
129
|
+
token: string;
|
|
130
|
+
tokenTypeHint?: "access_token" | "refresh_token";
|
|
131
|
+
}, request: Request): Promise<void> | void;
|
|
132
|
+
/** Required when a secret-based token endpoint authentication method is enabled. */
|
|
133
|
+
authenticateClient?(input: {
|
|
134
|
+
client: McpFnNormalizedClientRegistration;
|
|
135
|
+
method: Exclude<McpFnHostedTokenEndpointAuthMethod, "none">;
|
|
136
|
+
clientSecret: string;
|
|
137
|
+
}, request: Request): Promise<boolean> | boolean;
|
|
138
|
+
}
|
|
139
|
+
interface McpFnHostedAuthorizationCapabilities {
|
|
140
|
+
tokenEndpointAuthMethods?: McpFnHostedTokenEndpointAuthMethod[];
|
|
141
|
+
/** Defaults to true. */
|
|
142
|
+
requireState?: boolean;
|
|
143
|
+
/** Defaults to true when allowedResources is configured. */
|
|
144
|
+
requireResource?: boolean;
|
|
145
|
+
/** Defaults to false so a rotating refresh token can retain its stored audience. */
|
|
146
|
+
requireRefreshResource?: boolean;
|
|
147
|
+
/** Defaults to true when refresh is enabled. */
|
|
148
|
+
rotateRefreshTokens?: boolean;
|
|
149
|
+
}
|
|
150
|
+
declare class McpFnHostedAuthorizationError extends Error {
|
|
151
|
+
readonly code: string;
|
|
152
|
+
readonly status: number;
|
|
153
|
+
readonly details?: Record<string, unknown>;
|
|
154
|
+
constructor(code: string, message: string, options?: {
|
|
155
|
+
status?: number;
|
|
156
|
+
details?: Record<string, unknown>;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
declare function normalizeMcpClientRegistration(input: {
|
|
160
|
+
clientId: string;
|
|
161
|
+
source: McpFnClientRegistrationSource;
|
|
162
|
+
metadata: OAuthClientMetadata;
|
|
163
|
+
redirectPolicy?: McpFnRedirectPolicy;
|
|
164
|
+
}): McpFnNormalizedClientRegistration;
|
|
165
|
+
declare function validateMcpAuthorizationRequest(options: {
|
|
166
|
+
url: string | URL;
|
|
167
|
+
client: McpFnNormalizedClientRegistration;
|
|
168
|
+
redirectPolicy?: McpFnRedirectPolicy;
|
|
169
|
+
allowedResources?: ReadonlyArray<string | URL>;
|
|
170
|
+
supportedScopes?: ReadonlyArray<string>;
|
|
171
|
+
}): McpFnValidatedAuthorizationRequest;
|
|
172
|
+
interface McpFnAuthorizationCompatibilityOptions {
|
|
173
|
+
issuer: string | URL;
|
|
174
|
+
/** Allow HTTP only for literal loopback issuers in controlled local testing. */
|
|
175
|
+
allowInsecureLoopbackIssuer?: boolean;
|
|
176
|
+
/** Route prefix for authorize/token/register/revoke. Defaults to the issuer path. */
|
|
177
|
+
endpointPrefix?: string;
|
|
178
|
+
clients: McpFnHostedClientRegistry;
|
|
179
|
+
/** Runs before any registered or external client lookup at client-bearing endpoints. */
|
|
180
|
+
beforeClientResolution?(input: {
|
|
181
|
+
clientId: string;
|
|
182
|
+
endpoint: "authorization" | "token" | "revocation";
|
|
183
|
+
request: Request;
|
|
184
|
+
}): void | Promise<void>;
|
|
185
|
+
authorize(input: McpFnValidatedAuthorizationRequest, request: Request): Promise<Response> | Response;
|
|
186
|
+
tokenAuthority: McpFnHostedTokenAuthority;
|
|
187
|
+
capabilities?: McpFnHostedAuthorizationCapabilities;
|
|
188
|
+
supportedScopes?: string[];
|
|
189
|
+
allowedResources?: Array<string | URL>;
|
|
190
|
+
redirectPolicy?: McpFnRedirectPolicy;
|
|
191
|
+
clientMetadataDocuments?: {
|
|
192
|
+
enabled: boolean;
|
|
193
|
+
/** Required allowlist/policy hook before fetching an external client document. */
|
|
194
|
+
allow?(url: URL): boolean | Promise<boolean>;
|
|
195
|
+
fetch?: typeof globalThis.fetch;
|
|
196
|
+
maxBytes?: number;
|
|
197
|
+
timeoutMs?: number;
|
|
198
|
+
maxRedirects?: number;
|
|
199
|
+
};
|
|
200
|
+
extraMetadata?: Record<string, unknown>;
|
|
201
|
+
diagnostics?(event: {
|
|
202
|
+
phase: string;
|
|
203
|
+
outcome: "succeeded" | "failed";
|
|
204
|
+
code?: string;
|
|
205
|
+
details?: Record<string, unknown>;
|
|
206
|
+
}): void | Promise<void>;
|
|
207
|
+
}
|
|
208
|
+
interface McpFnAuthorizationServerMetadataOptions {
|
|
209
|
+
issuer: string | URL;
|
|
210
|
+
/** Allow HTTP only for literal loopback issuers in controlled local testing. */
|
|
211
|
+
allowInsecureLoopbackIssuer?: boolean;
|
|
212
|
+
endpointPrefix?: string;
|
|
213
|
+
dynamicRegistration: boolean;
|
|
214
|
+
refreshTokenGrant: boolean;
|
|
215
|
+
tokenRevocation: boolean;
|
|
216
|
+
tokenEndpointAuthMethods?: McpFnHostedTokenEndpointAuthMethod[];
|
|
217
|
+
supportedScopes?: string[];
|
|
218
|
+
clientMetadataDocuments: boolean;
|
|
219
|
+
extraMetadata?: Record<string, unknown>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* MCP-specific authorization compatibility router. Identity, login, consent,
|
|
223
|
+
* signing, token issuance, and durable security state stay in the callbacks.
|
|
224
|
+
*/
|
|
225
|
+
declare function createMcpAuthorizationCompatibilityHandler(options: McpFnAuthorizationCompatibilityOptions): (request: Request) => Promise<Response>;
|
|
226
|
+
declare function createMcpAuthorizationServerMetadata(options: McpFnAuthorizationServerMetadataOptions): Record<string, unknown>;
|
|
227
|
+
|
|
228
|
+
type McpFnOAuthCredentialScope = "all" | "client" | "tokens" | "verifier" | "discovery" | "state";
|
|
229
|
+
interface McpFnOAuthSessionStore {
|
|
230
|
+
readonly security: "memory" | "encrypted";
|
|
231
|
+
getClientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
232
|
+
setClientInformation(value: OAuthClientInformationMixed): Promise<void>;
|
|
233
|
+
getTokens(): Promise<OAuthTokens | undefined>;
|
|
234
|
+
setTokens(value: OAuthTokens): Promise<void>;
|
|
235
|
+
getCodeVerifier(): Promise<string | undefined>;
|
|
236
|
+
setCodeVerifier(value: string): Promise<void>;
|
|
237
|
+
getState(): Promise<string | undefined>;
|
|
238
|
+
setState(value: string): Promise<void>;
|
|
239
|
+
clear(scope: McpFnOAuthCredentialScope): Promise<void>;
|
|
240
|
+
}
|
|
241
|
+
declare class MemoryMcpFnOAuthSessionStore implements McpFnOAuthSessionStore {
|
|
242
|
+
readonly security: "memory";
|
|
243
|
+
private client?;
|
|
244
|
+
private tokenSet?;
|
|
245
|
+
private verifier?;
|
|
246
|
+
private pendingState?;
|
|
247
|
+
getClientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
248
|
+
setClientInformation(value: OAuthClientInformationMixed): Promise<void>;
|
|
249
|
+
getTokens(): Promise<OAuthTokens | undefined>;
|
|
250
|
+
setTokens(value: OAuthTokens): Promise<void>;
|
|
251
|
+
getCodeVerifier(): Promise<string | undefined>;
|
|
252
|
+
setCodeVerifier(value: string): Promise<void>;
|
|
253
|
+
getState(): Promise<string | undefined>;
|
|
254
|
+
setState(value: string): Promise<void>;
|
|
255
|
+
clear(scope: McpFnOAuthCredentialScope): Promise<void>;
|
|
256
|
+
}
|
|
257
|
+
interface McpFnEncryptedSessionRecord {
|
|
258
|
+
ciphertext: string;
|
|
259
|
+
keyRef: string;
|
|
260
|
+
}
|
|
261
|
+
interface McpFnEncryptedSessionRecordStore {
|
|
262
|
+
get(key: string): Promise<McpFnEncryptedSessionRecord | null>;
|
|
263
|
+
put(key: string, value: McpFnEncryptedSessionRecord): Promise<void>;
|
|
264
|
+
delete(key: string): Promise<void>;
|
|
265
|
+
}
|
|
266
|
+
/** Encrypts client registration, tokens, and the transient verifier at rest. */
|
|
267
|
+
declare function createEncryptedMcpFnOAuthSessionStore(options: {
|
|
268
|
+
namespace: string;
|
|
269
|
+
keyRef: string;
|
|
270
|
+
cipher: TokenCipher;
|
|
271
|
+
store: McpFnEncryptedSessionRecordStore;
|
|
272
|
+
}): McpFnOAuthSessionStore;
|
|
273
|
+
type McpFnOAuthClientPhase = "client-registration" | "authorization-request" | "authorization-callback" | "token-exchange" | "token-refresh" | "token-revocation";
|
|
274
|
+
interface McpFnOAuthClientDiagnostic {
|
|
275
|
+
phase: McpFnOAuthClientPhase;
|
|
276
|
+
outcome: "started" | "succeeded" | "failed";
|
|
277
|
+
code?: string;
|
|
278
|
+
at: string;
|
|
279
|
+
details?: Record<string, unknown>;
|
|
280
|
+
}
|
|
281
|
+
interface McpFnOAuthClientProviderOptions {
|
|
282
|
+
redirectUrl: string | URL;
|
|
283
|
+
clientMetadata: OAuthClientMetadata;
|
|
284
|
+
clientMetadataUrl?: string;
|
|
285
|
+
store?: McpFnOAuthSessionStore;
|
|
286
|
+
redirectPolicy?: McpFnRedirectPolicy;
|
|
287
|
+
openAuthorization(url: URL): void | Promise<void>;
|
|
288
|
+
diagnostics?(event: McpFnOAuthClientDiagnostic): void | Promise<void>;
|
|
289
|
+
state?: () => string | Promise<string>;
|
|
290
|
+
addClientAuthentication?: AddClientAuthentication;
|
|
291
|
+
validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
|
|
292
|
+
revoke?(tokens: OAuthTokens): void | Promise<void>;
|
|
293
|
+
clock?: () => Date;
|
|
294
|
+
}
|
|
295
|
+
declare class McpFnOAuthClientProvider implements OAuthClientProvider {
|
|
296
|
+
readonly redirectUrl: string | URL;
|
|
297
|
+
readonly clientMetadata: OAuthClientMetadata;
|
|
298
|
+
readonly clientMetadataUrl?: string;
|
|
299
|
+
readonly addClientAuthentication?: AddClientAuthentication;
|
|
300
|
+
readonly validateResourceURL: McpFnOAuthClientProviderOptions["validateResourceURL"] | undefined;
|
|
301
|
+
private readonly options;
|
|
302
|
+
private readonly store;
|
|
303
|
+
constructor(options: McpFnOAuthClientProviderOptions);
|
|
304
|
+
state(): Promise<string>;
|
|
305
|
+
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
306
|
+
saveClientInformation(value: OAuthClientInformationMixed): Promise<void>;
|
|
307
|
+
tokens(): Promise<OAuthTokens | undefined>;
|
|
308
|
+
saveTokens(value: OAuthTokens): Promise<void>;
|
|
309
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
310
|
+
saveCodeVerifier(value: string): Promise<void>;
|
|
311
|
+
codeVerifier(): Promise<string>;
|
|
312
|
+
validateAuthorizationState(value: string | undefined): Promise<void>;
|
|
313
|
+
invalidateCredentials(scope: McpFnOAuthCredentialScope): Promise<void>;
|
|
314
|
+
invalidatePendingAuthorization(): Promise<void>;
|
|
315
|
+
revoke(): Promise<void>;
|
|
316
|
+
private emit;
|
|
317
|
+
}
|
|
318
|
+
declare function createMcpFnOAuthClientProvider(options: McpFnOAuthClientProviderOptions): McpFnOAuthClientProvider;
|
|
319
|
+
|
|
16
320
|
interface McpFnProtectedResourceMetadata extends Record<string, unknown> {
|
|
17
321
|
resource: string;
|
|
18
322
|
authorization_servers: string[];
|
|
@@ -24,6 +328,8 @@ interface McpFnProtectedResourceMetadata extends Record<string, unknown> {
|
|
|
24
328
|
interface McpFnProtectedResourceOptions {
|
|
25
329
|
resource: string | URL;
|
|
26
330
|
authorizationServers: Array<string | URL>;
|
|
331
|
+
/** Allow HTTP only for literal loopback issuers in controlled local testing. */
|
|
332
|
+
allowInsecureLoopbackAuthorizationServers?: boolean;
|
|
27
333
|
scopesSupported?: string[];
|
|
28
334
|
resourceName?: string;
|
|
29
335
|
resourceDocumentation?: string;
|
|
@@ -39,4 +345,68 @@ declare function protectedResourceMetadataUrl(resource: string | URL): URL;
|
|
|
39
345
|
declare function createProtectedResourceMetadata(options: McpFnProtectedResourceOptions): McpFnProtectedResourceMetadata;
|
|
40
346
|
declare function createOAuthResourceServerHandler(mcpHandler: McpFnWebStandardHandler, options: McpFnOAuthResourceServerOptions): (request: Request) => Promise<Response>;
|
|
41
347
|
|
|
42
|
-
|
|
348
|
+
interface McpFnPrincipal {
|
|
349
|
+
subject: string;
|
|
350
|
+
clientId: string;
|
|
351
|
+
scopes: string[];
|
|
352
|
+
resourceIds: string[];
|
|
353
|
+
expiresAt?: number;
|
|
354
|
+
tenantId?: string;
|
|
355
|
+
regionId?: string;
|
|
356
|
+
authMethods?: string[];
|
|
357
|
+
extra?: Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
/** Structural subset implemented by AuthFn and other authentication providers. */
|
|
360
|
+
interface McpFnAuthSessionLike {
|
|
361
|
+
id: string;
|
|
362
|
+
type: string;
|
|
363
|
+
subject: {
|
|
364
|
+
actorId: string;
|
|
365
|
+
actorType: string;
|
|
366
|
+
tenantId?: string;
|
|
367
|
+
regionId?: string;
|
|
368
|
+
};
|
|
369
|
+
resourceIds?: string[];
|
|
370
|
+
scopes?: string[];
|
|
371
|
+
methods?: string[];
|
|
372
|
+
expiresAt?: Date;
|
|
373
|
+
metadata?: unknown;
|
|
374
|
+
}
|
|
375
|
+
interface McpFnBearerAuthProviderLike<TSession extends McpFnAuthSessionLike> {
|
|
376
|
+
/** Authenticate this exact Bearer token; other request credentials must not satisfy it. */
|
|
377
|
+
authenticateBearer(token: string, request: Request): Promise<TSession | null>;
|
|
378
|
+
authorize?(session: TSession, resourceId: string): Promise<boolean>;
|
|
379
|
+
revoke?(sessionId: string): Promise<void>;
|
|
380
|
+
}
|
|
381
|
+
/** Structural AuthFn contract. McpFn invokes it with only the exact Bearer credential. */
|
|
382
|
+
interface McpFnRequestAuthProviderLike<TSession extends McpFnAuthSessionLike> {
|
|
383
|
+
authenticate(request: Request): Promise<TSession | null>;
|
|
384
|
+
authorize?(session: TSession, resourceId: string): Promise<boolean>;
|
|
385
|
+
revoke?(sessionId: string): Promise<void>;
|
|
386
|
+
}
|
|
387
|
+
/** AuthFn is optional: consumers can pass either supported structural provider contract. */
|
|
388
|
+
type McpFnAuthProviderLike<TSession extends McpFnAuthSessionLike> = McpFnBearerAuthProviderLike<TSession> | McpFnRequestAuthProviderLike<TSession>;
|
|
389
|
+
interface McpFnAuthProviderAdapterOptions<TSession extends McpFnAuthSessionLike> {
|
|
390
|
+
provider: McpFnAuthProviderLike<TSession>;
|
|
391
|
+
resource: string | URL;
|
|
392
|
+
map?(session: TSession, request: Request): McpFnPrincipal | Promise<McpFnPrincipal>;
|
|
393
|
+
authorize?(input: {
|
|
394
|
+
principal: McpFnPrincipal;
|
|
395
|
+
request: Request;
|
|
396
|
+
}): boolean | Promise<boolean>;
|
|
397
|
+
requiredScopes?: string[] | ((input: {
|
|
398
|
+
principal: McpFnPrincipal;
|
|
399
|
+
request: Request;
|
|
400
|
+
}) => string[] | Promise<string[]>);
|
|
401
|
+
}
|
|
402
|
+
interface McpFnAuthProviderAdapter<TSession extends McpFnAuthSessionLike> {
|
|
403
|
+
authenticate(request: Request): Promise<{
|
|
404
|
+
session: TSession;
|
|
405
|
+
principal: McpFnPrincipal;
|
|
406
|
+
authInfo: AuthInfo;
|
|
407
|
+
} | null>;
|
|
408
|
+
}
|
|
409
|
+
declare function createMcpFnAuthProviderAdapter<TSession extends McpFnAuthSessionLike>(options: McpFnAuthProviderAdapterOptions<TSession>): McpFnAuthProviderAdapter<TSession>;
|
|
410
|
+
declare function createAuthProviderMcpHandler<TSession extends McpFnAuthSessionLike>(mcpHandler: McpFnWebStandardHandler, options: McpFnAuthProviderAdapterOptions<TSession>): (request: Request) => Promise<Response>;
|
|
411
|
+
|
|
412
|
+
export { type DiagnoseMcpAuthorizationOptions, MCP_ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION_ID, MCP_ID_JAG_GRANT_PROFILE, type McpFnAuthProviderAdapter, type McpFnAuthProviderAdapterOptions, type McpFnAuthProviderLike, type McpFnAuthSessionLike, type McpFnAuthorizationCompatibilityOptions, type McpFnAuthorizationDiagnosticReport, type McpFnAuthorizationDiagnosticStep, type McpFnAuthorizationServerMetadata, type McpFnAuthorizationServerMetadataOptions, type McpFnBearerAuthProviderLike, type McpFnClientRegistrationSource, type McpFnEncryptedSessionRecord, type McpFnEncryptedSessionRecordStore, type McpFnHostedAuthorizationCapabilities, McpFnHostedAuthorizationError, type McpFnHostedClientAuthentication, type McpFnHostedClientRegistry, type McpFnHostedTokenAuthority, type McpFnHostedTokenEndpointAuthMethod, type McpFnHostedTokenSet, type McpFnNormalizedClientRegistration, type McpFnOAuthClientDiagnostic, type McpFnOAuthClientPhase, McpFnOAuthClientProvider, type McpFnOAuthClientProviderOptions, type McpFnOAuthCredentialScope, type McpFnOAuthResourceServerOptions, type McpFnOAuthSessionStore, type McpFnPrincipal, type McpFnProtectedResourceMetadata, type McpFnProtectedResourceOptions, type McpFnRedirectMatch, McpFnRedirectMismatchError, type McpFnRedirectPolicy, type McpFnRequestAuthProviderLike, type McpFnValidatedAuthorizationRequest, type McpFnWebStandardHandler, MemoryMcpFnOAuthSessionStore, bearerChallengeResponse, createAuthProviderMcpHandler, createEncryptedMcpFnOAuthSessionStore, createMcpAuthorizationCompatibilityHandler, createMcpAuthorizationServerMetadata, createMcpFnAuthProviderAdapter, createMcpFnOAuthClientProvider, createOAuthResourceServerHandler, createProtectedResourceMetadata, diagnoseMcpAuthorization, enterpriseManagedAuthorizationClientMetadata, matchMcpRedirectUri, normalizeMcpClientRegistration, normalizeMcpRedirectUri, protectedResourceMetadataUrl, readBearerToken, validateMcpAuthorizationRequest, withEnterpriseManagedAuthorization };
|