@lostgradient/mcp 0.2.5 → 0.3.0
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 +1 -1
- package/README.md +15 -173
- package/dist/http.d.ts +35 -0
- package/dist/http.js +251 -0
- package/dist/internal/cryptography/encryption.d.ts +108 -0
- package/dist/internal/cryptography/encryption.js +241 -0
- package/dist/internal/cryptography/hash.d.ts +72 -0
- package/dist/internal/cryptography/hash.js +233 -0
- package/dist/internal/cryptography/index.d.ts +4 -0
- package/dist/internal/cryptography/index.js +2 -0
- package/dist/oauth/canonicalize-ip-address.d.ts +0 -6
- package/dist/oauth/canonicalize-ip-address.js +113 -0
- package/dist/oauth/client-metadata-documents.d.ts +2 -22
- package/dist/oauth/client-metadata-documents.js +205 -19
- package/dist/oauth/index.d.ts +9 -213
- package/dist/oauth/index.js +6 -69
- package/dist/oauth/issuer.d.ts +103 -0
- package/dist/oauth/issuer.js +564 -0
- package/dist/oauth/postgres.d.ts +12 -0
- package/dist/oauth/postgres.js +76 -0
- package/dist/oauth/safe-public-https-fetch.d.ts +3 -5
- package/dist/oauth/safe-public-https-fetch.js +114 -0
- package/dist/oauth/security-utilities.d.ts +0 -3
- package/dist/oauth/security-utilities.js +93 -0
- package/dist/oauth-store.d.ts +108 -0
- package/dist/oauth-store.js +321 -0
- package/package.json +50 -124
- package/dist/chunk-3ek3knfm.js +0 -73
- package/dist/chunk-3rr24vhh.js +0 -28
- package/dist/chunk-6ekjtvcq.js +0 -273
- package/dist/chunk-88nhf6xt.js +0 -449
- package/dist/chunk-en76akaq.js +0 -1107
- package/dist/chunk-k6fm3cmk.js +0 -132
- package/dist/chunk-qxwd8est.js +0 -916
- package/dist/chunk-rxnyn7tf.js +0 -19
- package/dist/chunk-taxyscge.js +0 -67
- package/dist/chunk-wsnfttyg.js +0 -4
- package/dist/chunk-xcf742mf.js +0 -14
- package/dist/conformance-fixture-registration.d.ts +0 -30
- package/dist/conformance-server.d.ts +0 -1
- package/dist/conformance.d.ts +0 -43
- package/dist/env.d.ts +0 -59
- package/dist/env.js +0 -9
- package/dist/environment-schema.d.ts +0 -29
- package/dist/environment-schema.js +0 -6
- package/dist/golden-prompts.d.ts +0 -42
- package/dist/handler-context.d.ts +0 -16
- package/dist/http/authenticate.d.ts +0 -35
- package/dist/http/authorization-header.d.ts +0 -5
- package/dist/http/grant-revocation-channel.d.ts +0 -24
- package/dist/http/handler.d.ts +0 -32
- package/dist/http/index.d.ts +0 -27
- package/dist/http/index.js +0 -870
- package/dist/http/listen-inspection.d.ts +0 -11
- package/dist/http/request-context.d.ts +0 -17
- package/dist/http/responses.d.ts +0 -13
- package/dist/http/serving-layer.d.ts +0 -25
- package/dist/http/user-handler-cache.d.ts +0 -37
- package/dist/http/user-server-event-bus.d.ts +0 -35
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -616
- package/dist/localhost-request-validation.d.ts +0 -2
- package/dist/logger.d.ts +0 -59
- package/dist/logger.js +0 -18
- package/dist/long-running-operation-support.d.ts +0 -34
- package/dist/metrics.d.ts +0 -64
- package/dist/metrics.js +0 -6
- package/dist/oauth/authorize-endpoint.d.ts +0 -5
- package/dist/oauth/client-authentication.d.ts +0 -10
- package/dist/oauth/discovery-metadata.d.ts +0 -19
- package/dist/oauth/endpoint-rate-limits.d.ts +0 -10
- package/dist/oauth/endpoint-responses.d.ts +0 -10
- package/dist/oauth/network-identity.d.ts +0 -32
- package/dist/oauth/pkce-validation.d.ts +0 -2
- package/dist/oauth/postgres/client-store.d.ts +0 -12
- package/dist/oauth/postgres/code-store.d.ts +0 -14
- package/dist/oauth/postgres/database.d.ts +0 -59
- package/dist/oauth/postgres/index.d.ts +0 -11
- package/dist/oauth/postgres/index.js +0 -616
- package/dist/oauth/postgres/schema.d.ts +0 -1476
- package/dist/oauth/postgres/token-store.d.ts +0 -16
- package/dist/oauth/postgres/transaction-store.d.ts +0 -14
- package/dist/oauth/redirect-uri-matching.d.ts +0 -2
- package/dist/oauth/registration-endpoint.d.ts +0 -2
- package/dist/oauth/request-body.d.ts +0 -14
- package/dist/oauth/revocation-endpoint.d.ts +0 -2
- package/dist/oauth/scope-utilities.d.ts +0 -15
- package/dist/oauth/stores.d.ts +0 -225
- package/dist/oauth/stores.js +0 -0
- package/dist/oauth/testing/contract-fixtures.d.ts +0 -134
- package/dist/oauth/testing/index.d.ts +0 -56
- package/dist/oauth/testing/index.js +0 -330
- package/dist/oauth/token-endpoint.d.ts +0 -2
- package/dist/oauth-scope-configuration.d.ts +0 -3
- package/dist/prompts/index.d.ts +0 -5
- package/dist/prompts/summarize.d.ts +0 -4
- package/dist/rate-limit/in-memory-sliding-window-store.d.ts +0 -3
- package/dist/rate-limit/index.d.ts +0 -23
- package/dist/rate-limit/index.js +0 -29
- package/dist/rate-limit/mcp-concurrency-limiter.d.ts +0 -26
- package/dist/rate-limit/rate-limit-response.d.ts +0 -1
- package/dist/rate-limit/redis-sliding-window-store.d.ts +0 -2
- package/dist/rate-limit/request-rate-limiter.d.ts +0 -10
- package/dist/rate-limit/sliding-window-rate-limiter.d.ts +0 -16
- package/dist/resources/index.d.ts +0 -4
- package/dist/resources/user-profile.d.ts +0 -1
- package/dist/scope-vocabulary.d.ts +0 -127
- package/dist/scopes.d.ts +0 -49
- package/dist/server.d.ts +0 -113
- package/dist/supported-scopes.d.ts +0 -25
- package/dist/sveltekit-mount-state.d.ts +0 -4
- package/dist/sveltekit-mount.d.ts +0 -43
- package/dist/sveltekit-mount.js +0 -344
- package/dist/template-registry.d.ts +0 -16
- package/dist/tool-response.d.ts +0 -100
- package/dist/tools/get-user-profile.d.ts +0 -8
- package/dist/tools/index.d.ts +0 -16
- package/dist/tools/list-audit-events.d.ts +0 -11
- package/dist/type-assertions.d.ts +0 -1
- package/dist/types/primitives.d.ts +0 -130
- package/dist/ui-extension-support.d.ts +0 -20
- package/dist/version.d.ts +0 -23
- package/dist/version.js +0 -6
package/dist/chunk-en76akaq.js
DELETED
|
@@ -1,1107 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
canonicalizeIpAddress,
|
|
3
|
-
constantTimeEquals,
|
|
4
|
-
expandIpv6Groups,
|
|
5
|
-
fetchClientIdMetadataDocument,
|
|
6
|
-
isAddressInCidr,
|
|
7
|
-
isClientIdMetadataDocumentUrl,
|
|
8
|
-
isExactContentType,
|
|
9
|
-
isValidCidr,
|
|
10
|
-
isValidClientName,
|
|
11
|
-
isValidRedirectUri,
|
|
12
|
-
safeFetchPublicHttpsUrl,
|
|
13
|
-
stripPort,
|
|
14
|
-
withDeadline
|
|
15
|
-
} from "./chunk-88nhf6xt.js";
|
|
16
|
-
import {
|
|
17
|
-
RequestRateLimiter,
|
|
18
|
-
createRateLimitedResponse
|
|
19
|
-
} from "./chunk-3ek3knfm.js";
|
|
20
|
-
import {
|
|
21
|
-
getSupportedScopes,
|
|
22
|
-
hasRegisteredUiExtensionResource
|
|
23
|
-
} from "./chunk-rxnyn7tf.js";
|
|
24
|
-
|
|
25
|
-
// src/oauth/discovery-metadata.ts
|
|
26
|
-
import { EXTENSION_ID } from "@modelcontextprotocol/ext-apps/server";
|
|
27
|
-
var oauthCorsHeaders = {
|
|
28
|
-
"Access-Control-Allow-Origin": "*",
|
|
29
|
-
"Access-Control-Allow-Methods": "GET, POST, DELETE, OPTIONS",
|
|
30
|
-
"Access-Control-Allow-Headers": "Content-Type, Authorization, mcp-session-id, mcp-protocol-version, Last-Event-ID",
|
|
31
|
-
"Access-Control-Expose-Headers": "mcp-session-id, mcp-protocol-version"
|
|
32
|
-
};
|
|
33
|
-
function jsonMetadata(body) {
|
|
34
|
-
return Response.json(body, { headers: oauthCorsHeaders });
|
|
35
|
-
}
|
|
36
|
-
function metadataValues(configuration, registry) {
|
|
37
|
-
const issuer = configuration.issuer;
|
|
38
|
-
const baseUrl = configuration.baseUrl.href.replace(/\/$/, "");
|
|
39
|
-
const resource = configuration.resource.href;
|
|
40
|
-
const scopesSupported = getSupportedScopes(registry);
|
|
41
|
-
return { issuer, baseUrl, resource, scopesSupported };
|
|
42
|
-
}
|
|
43
|
-
function handleOauthAuthorizationMetadataGet(_context, configuration, registry) {
|
|
44
|
-
const { issuer, baseUrl, scopesSupported } = metadataValues(configuration, registry);
|
|
45
|
-
return jsonMetadata({
|
|
46
|
-
issuer,
|
|
47
|
-
authorization_endpoint: `${baseUrl}/oauth/authorize`,
|
|
48
|
-
token_endpoint: `${baseUrl}/oauth/token`,
|
|
49
|
-
registration_endpoint: `${baseUrl}/oauth/register`,
|
|
50
|
-
revocation_endpoint: `${baseUrl}/oauth/revoke`,
|
|
51
|
-
response_types_supported: ["code"],
|
|
52
|
-
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
53
|
-
code_challenge_methods_supported: ["S256"],
|
|
54
|
-
token_endpoint_auth_methods_supported: ["client_secret_post", "none"],
|
|
55
|
-
scopes_supported: scopesSupported,
|
|
56
|
-
client_id_metadata_document_supported: true,
|
|
57
|
-
authorization_response_iss_parameter_supported: true,
|
|
58
|
-
...configuration.serviceDocumentation ? { service_documentation: configuration.serviceDocumentation.href } : {},
|
|
59
|
-
...configuration.privacyPolicy ? { op_policy_uri: configuration.privacyPolicy.href } : {},
|
|
60
|
-
...configuration.termsOfService ? { op_tos_uri: configuration.termsOfService.href } : {},
|
|
61
|
-
extensions: {
|
|
62
|
-
...configuration.mcpUiExtension.enabled && hasRegisteredUiExtensionResource(registry) ? { [EXTENSION_ID]: {} } : {}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function handleOauthProtectedResourceMetadataGet(_context, configuration, registry) {
|
|
67
|
-
const { issuer, resource, scopesSupported } = metadataValues(configuration, registry);
|
|
68
|
-
return jsonMetadata({
|
|
69
|
-
resource,
|
|
70
|
-
authorization_servers: [issuer],
|
|
71
|
-
scopes_supported: scopesSupported,
|
|
72
|
-
resource_name: configuration.serverName,
|
|
73
|
-
...configuration.serviceDocumentation ? { resource_documentation: configuration.serviceDocumentation.href } : {},
|
|
74
|
-
...configuration.privacyPolicy ? { resource_policy_uri: configuration.privacyPolicy.href } : {},
|
|
75
|
-
...configuration.termsOfService ? { resource_tos_uri: configuration.termsOfService.href } : {}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function handleOauthProtectedResourceMcpMetadataGet(_context, configuration, registry) {
|
|
79
|
-
const { issuer, resource, scopesSupported } = metadataValues(configuration, registry);
|
|
80
|
-
return jsonMetadata({
|
|
81
|
-
resource,
|
|
82
|
-
authorization_servers: [issuer],
|
|
83
|
-
bearer_methods_supported: ["header"],
|
|
84
|
-
mcp_protocol_version: configuration.mcpProtocolVersion,
|
|
85
|
-
scopes_supported: scopesSupported,
|
|
86
|
-
resource_name: configuration.serverName,
|
|
87
|
-
...configuration.serviceDocumentation ? { resource_documentation: configuration.serviceDocumentation.href } : {},
|
|
88
|
-
...configuration.privacyPolicy ? { resource_policy_uri: configuration.privacyPolicy.href } : {},
|
|
89
|
-
...configuration.termsOfService ? { resource_tos_uri: configuration.termsOfService.href } : {}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
// src/oauth/client-authentication.ts
|
|
93
|
-
async function authenticateOauthClient(clientId, clientSecret, seams) {
|
|
94
|
-
const client = await seams.stores.clients.findById(clientId);
|
|
95
|
-
if (!client)
|
|
96
|
-
return { ok: false };
|
|
97
|
-
if (client.tokenEndpointAuthMethod === "client_secret_post") {
|
|
98
|
-
if (!clientSecret || !client.clientSecretHash)
|
|
99
|
-
return { ok: false };
|
|
100
|
-
if (!constantTimeEquals(client.clientSecretHash, seams.hashCredential(clientSecret)))
|
|
101
|
-
return { ok: false };
|
|
102
|
-
if (client.clientSecretExpiresAt && client.clientSecretExpiresAt.getTime() <= Date.now())
|
|
103
|
-
return { ok: false };
|
|
104
|
-
return { ok: true, client };
|
|
105
|
-
}
|
|
106
|
-
if (client.tokenEndpointAuthMethod === "none") {
|
|
107
|
-
return clientSecret ? { ok: false } : { ok: true, client };
|
|
108
|
-
}
|
|
109
|
-
return { ok: false };
|
|
110
|
-
}
|
|
111
|
-
// src/oauth/registration-endpoint.ts
|
|
112
|
-
import { randomBytes, randomUUID } from "node:crypto";
|
|
113
|
-
import { z } from "zod";
|
|
114
|
-
|
|
115
|
-
// src/oauth/request-body.ts
|
|
116
|
-
var oauthRegisterMaximumBodyBytes = 16 * 1024;
|
|
117
|
-
var oauthTokenMaximumBodyBytes = 8 * 1024;
|
|
118
|
-
var oauthRevokeMaximumBodyBytes = 4 * 1024;
|
|
119
|
-
var oauthAuthorizeApproveMaximumBodyBytes = 4 * 1024;
|
|
120
|
-
var oauthAuthorizeDenyMaximumBodyBytes = 4 * 1024;
|
|
121
|
-
|
|
122
|
-
class PayloadTooLargeError extends Error {
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
class InvalidOauthRequestBodyError extends Error {
|
|
126
|
-
kind;
|
|
127
|
-
constructor(message, kind = "invalid_request") {
|
|
128
|
-
super(message);
|
|
129
|
-
this.kind = kind;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async function readBoundedText(request, maximumBytes) {
|
|
133
|
-
const declaredLength = request.headers.get("content-length");
|
|
134
|
-
if (declaredLength && (!/^\d+$/.test(declaredLength) || Number(declaredLength) > maximumBytes)) {
|
|
135
|
-
throw new PayloadTooLargeError("Request body too large");
|
|
136
|
-
}
|
|
137
|
-
if (!request.body)
|
|
138
|
-
return "";
|
|
139
|
-
const reader = request.body.getReader();
|
|
140
|
-
const chunks = [];
|
|
141
|
-
let byteCount = 0;
|
|
142
|
-
while (true) {
|
|
143
|
-
const { done, value } = await reader.read();
|
|
144
|
-
if (done)
|
|
145
|
-
break;
|
|
146
|
-
byteCount += value.byteLength;
|
|
147
|
-
if (byteCount > maximumBytes) {
|
|
148
|
-
await reader.cancel().catch(() => {});
|
|
149
|
-
throw new PayloadTooLargeError("Request body too large");
|
|
150
|
-
}
|
|
151
|
-
chunks.push(value);
|
|
152
|
-
}
|
|
153
|
-
const bytes = new Uint8Array(byteCount);
|
|
154
|
-
let offset = 0;
|
|
155
|
-
for (const chunk of chunks) {
|
|
156
|
-
bytes.set(chunk, offset);
|
|
157
|
-
offset += chunk.byteLength;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
161
|
-
} catch {
|
|
162
|
-
throw new InvalidOauthRequestBodyError("Request body is not valid UTF-8");
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async function readOauthJson(request, maximumBytes) {
|
|
166
|
-
if (!isExactContentType(request.headers.get("content-type"), "application/json")) {
|
|
167
|
-
throw new InvalidOauthRequestBodyError("Content-Type must be application/json", "unsupported_content_type");
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
return JSON.parse(await readBoundedText(request, maximumBytes));
|
|
171
|
-
} catch (error) {
|
|
172
|
-
if (error instanceof PayloadTooLargeError || error instanceof InvalidOauthRequestBodyError)
|
|
173
|
-
throw error;
|
|
174
|
-
throw new InvalidOauthRequestBodyError("Invalid JSON body");
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
var knownParameters = new Set([
|
|
178
|
-
"grant_type",
|
|
179
|
-
"code",
|
|
180
|
-
"redirect_uri",
|
|
181
|
-
"client_id",
|
|
182
|
-
"client_secret",
|
|
183
|
-
"code_verifier",
|
|
184
|
-
"refresh_token",
|
|
185
|
-
"token",
|
|
186
|
-
"token_type_hint",
|
|
187
|
-
"resource",
|
|
188
|
-
"scope"
|
|
189
|
-
]);
|
|
190
|
-
async function readOauthParameters(request, maximumBytes) {
|
|
191
|
-
let entries;
|
|
192
|
-
if (isExactContentType(request.headers.get("content-type"), "application/x-www-form-urlencoded")) {
|
|
193
|
-
const parameters = new URLSearchParams(await readBoundedText(request, maximumBytes));
|
|
194
|
-
for (const name of knownParameters) {
|
|
195
|
-
if (parameters.getAll(name).length > 1)
|
|
196
|
-
throw new InvalidOauthRequestBodyError(`Duplicate parameter: ${name}`);
|
|
197
|
-
}
|
|
198
|
-
entries = [...parameters.entries()];
|
|
199
|
-
} else if (isExactContentType(request.headers.get("content-type"), "application/json")) {
|
|
200
|
-
const parsed = await readOauthJson(request, maximumBytes);
|
|
201
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
202
|
-
throw new InvalidOauthRequestBodyError("Request body must be an object");
|
|
203
|
-
entries = Object.entries(parsed);
|
|
204
|
-
} else {
|
|
205
|
-
throw new InvalidOauthRequestBodyError("Unsupported Content-Type", "unsupported_content_type");
|
|
206
|
-
}
|
|
207
|
-
const result = {};
|
|
208
|
-
for (const [name, value] of entries) {
|
|
209
|
-
if (typeof value !== "string")
|
|
210
|
-
throw new InvalidOauthRequestBodyError(`Parameter must be a string: ${name}`);
|
|
211
|
-
result[name] = value;
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/oauth/endpoint-responses.ts
|
|
217
|
-
var oauthNoStoreHeaders = {
|
|
218
|
-
...oauthCorsHeaders,
|
|
219
|
-
"Cache-Control": "no-store",
|
|
220
|
-
Pragma: "no-cache"
|
|
221
|
-
};
|
|
222
|
-
function oauthJson(body, status = 200, headers = {}) {
|
|
223
|
-
return Response.json(body, { status, headers: { ...oauthNoStoreHeaders, ...headers } });
|
|
224
|
-
}
|
|
225
|
-
function oauthBodyError(error) {
|
|
226
|
-
if (error instanceof PayloadTooLargeError) {
|
|
227
|
-
return oauthJson({ error: "invalid_request", error_description: "Request body too large" }, 413);
|
|
228
|
-
}
|
|
229
|
-
if (error instanceof InvalidOauthRequestBodyError) {
|
|
230
|
-
return oauthJson({
|
|
231
|
-
error: error.kind,
|
|
232
|
-
...error.kind === "invalid_request" ? { error_description: error.message } : {}
|
|
233
|
-
}, 400);
|
|
234
|
-
}
|
|
235
|
-
return oauthJson({ error: "invalid_request", error_description: "Malformed request body" }, 400);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// src/oauth/network-identity.ts
|
|
239
|
-
import { isIP } from "node:net";
|
|
240
|
-
function isSocketPeerTrusted(canonicalSocketAddress, configuration) {
|
|
241
|
-
return configuration.trustedProxyCidrs.some((cidr) => isAddressInCidr(canonicalSocketAddress, cidr));
|
|
242
|
-
}
|
|
243
|
-
function parseForwardedForHeaderValue(part) {
|
|
244
|
-
const match = /for=("?)([^;,"]+)\1/i.exec(part.trim());
|
|
245
|
-
return match ? match[2] : null;
|
|
246
|
-
}
|
|
247
|
-
function selectHopFromEnd(entries, hopCount) {
|
|
248
|
-
if (entries.length === 0)
|
|
249
|
-
return null;
|
|
250
|
-
const index = entries.length - hopCount;
|
|
251
|
-
if (index < 0)
|
|
252
|
-
return null;
|
|
253
|
-
return entries[Math.min(index, entries.length - 1)] ?? null;
|
|
254
|
-
}
|
|
255
|
-
function extractForwardedAddress(headers, configuration) {
|
|
256
|
-
if (configuration.trustedProxyHeader === "cf-connecting-ip") {
|
|
257
|
-
const value = headers.get("cf-connecting-ip");
|
|
258
|
-
return value ? stripPort(value) : null;
|
|
259
|
-
}
|
|
260
|
-
if (configuration.trustedProxyHeader === "fly-client-ip") {
|
|
261
|
-
const value = headers.get("fly-client-ip");
|
|
262
|
-
return value ? stripPort(value) : null;
|
|
263
|
-
}
|
|
264
|
-
if (configuration.trustedProxyHeader === "x-forwarded-for") {
|
|
265
|
-
const raw = headers.get("x-forwarded-for");
|
|
266
|
-
if (!raw)
|
|
267
|
-
return null;
|
|
268
|
-
const entries = raw.split(",").map((entry) => {
|
|
269
|
-
const trimmed = entry.trim();
|
|
270
|
-
return trimmed ? stripPort(trimmed) : null;
|
|
271
|
-
});
|
|
272
|
-
return selectHopFromEnd(entries, configuration.trustedProxyHopCount);
|
|
273
|
-
}
|
|
274
|
-
if (configuration.trustedProxyHeader === "forwarded") {
|
|
275
|
-
const raw = headers.get("forwarded");
|
|
276
|
-
if (!raw)
|
|
277
|
-
return null;
|
|
278
|
-
const entries = raw.split(",").map((part) => {
|
|
279
|
-
const value = parseForwardedForHeaderValue(part);
|
|
280
|
-
return value ? stripPort(value) : null;
|
|
281
|
-
});
|
|
282
|
-
return selectHopFromEnd(entries, configuration.trustedProxyHopCount);
|
|
283
|
-
}
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
function resolveOauthNetworkIdentity(input) {
|
|
287
|
-
const canonicalSocketAddress = input.socketAddress ? canonicalizeIpAddress(input.socketAddress) : undefined;
|
|
288
|
-
if (!canonicalSocketAddress || !input.configuration.trustedProxyHeader || input.configuration.trustedProxyCidrs.length === 0 || !isSocketPeerTrusted(canonicalSocketAddress, input.configuration)) {
|
|
289
|
-
return canonicalSocketAddress ?? "unknown-client";
|
|
290
|
-
}
|
|
291
|
-
const forwardedAddress = extractForwardedAddress(input.headers, input.configuration);
|
|
292
|
-
if (!forwardedAddress || isIP(forwardedAddress) === 0) {
|
|
293
|
-
return canonicalSocketAddress;
|
|
294
|
-
}
|
|
295
|
-
return canonicalizeIpAddress(forwardedAddress);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// src/oauth/endpoint-rate-limits.ts
|
|
299
|
-
function limiter(seams) {
|
|
300
|
-
const store = seams.configuration.rateLimitStores?.slidingWindow;
|
|
301
|
-
return store ? new RequestRateLimiter(seams.configuration.rateLimits, () => store) : undefined;
|
|
302
|
-
}
|
|
303
|
-
function networkIdentity(context, seams) {
|
|
304
|
-
return resolveOauthNetworkIdentity({
|
|
305
|
-
socketAddress: context.socketAddress,
|
|
306
|
-
headers: context.request.headers,
|
|
307
|
-
configuration: seams.configuration.trustedProxy
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
async function rateLimitResponse(input) {
|
|
311
|
-
const requestLimiter = limiter(input.seams);
|
|
312
|
-
if (!requestLimiter)
|
|
313
|
-
return;
|
|
314
|
-
const identity = networkIdentity(input.context, input.seams);
|
|
315
|
-
const result = await requestLimiter.consume(input.category, input.identifier ? `${identity}:${input.identifier}` : identity);
|
|
316
|
-
if (result.allowed)
|
|
317
|
-
return;
|
|
318
|
-
return createRateLimitedResponse(result.retryAfterSeconds, {
|
|
319
|
-
"Access-Control-Allow-Origin": "*",
|
|
320
|
-
"Cache-Control": "no-store",
|
|
321
|
-
Pragma: "no-cache"
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
async function isAuthenticationLockedOut(context, seams) {
|
|
325
|
-
const requestLimiter = limiter(seams);
|
|
326
|
-
if (!requestLimiter)
|
|
327
|
-
return false;
|
|
328
|
-
const count = await requestLimiter.peek("failed_authentication", networkIdentity(context, seams));
|
|
329
|
-
return count >= seams.configuration.rateLimits.categories.failed_authentication.maximumRequests;
|
|
330
|
-
}
|
|
331
|
-
async function recordFailedAuthentication(context, seams) {
|
|
332
|
-
await limiter(seams)?.consume("failed_authentication", networkIdentity(context, seams));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// src/oauth/registration-endpoint.ts
|
|
336
|
-
var registrationSchema = z.object({
|
|
337
|
-
client_name: z.string().min(1).max(200).refine(isValidClientName).default("Unknown Client"),
|
|
338
|
-
redirect_uris: z.array(z.string().url().max(2048)).min(1).max(10).refine((values) => values.every(isValidRedirectUri)),
|
|
339
|
-
grant_types: z.array(z.enum(["authorization_code", "refresh_token"])).max(5).default(["authorization_code", "refresh_token"]),
|
|
340
|
-
response_types: z.array(z.literal("code")).max(5).default(["code"]),
|
|
341
|
-
token_endpoint_auth_method: z.enum(["client_secret_post", "none"]).default("client_secret_post"),
|
|
342
|
-
application_type: z.enum(["web", "native"]).optional()
|
|
343
|
-
}).superRefine((value, refinement) => {
|
|
344
|
-
if (value.application_type === "web" && value.redirect_uris.some((uri) => new URL(uri).protocol !== "https:")) {
|
|
345
|
-
refinement.addIssue({
|
|
346
|
-
code: "custom",
|
|
347
|
-
path: ["redirect_uris"],
|
|
348
|
-
message: 'application_type "web" requires HTTPS redirect URIs'
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
async function handleOauthRegisterPost(context, seams) {
|
|
353
|
-
const limited = await rateLimitResponse({ context, seams, category: "oauth_register" });
|
|
354
|
-
if (limited)
|
|
355
|
-
return limited;
|
|
356
|
-
let input;
|
|
357
|
-
try {
|
|
358
|
-
input = await readOauthJson(context.request, oauthRegisterMaximumBodyBytes);
|
|
359
|
-
} catch (error) {
|
|
360
|
-
if (error instanceof PayloadTooLargeError)
|
|
361
|
-
return oauthJson({ error: "invalid_client_metadata", error_description: "Request body too large" }, 413);
|
|
362
|
-
if (error instanceof InvalidOauthRequestBodyError) {
|
|
363
|
-
if (error.kind === "unsupported_content_type")
|
|
364
|
-
return oauthJson({
|
|
365
|
-
error: "invalid_client_metadata",
|
|
366
|
-
error_description: "Content-Type must be application/json"
|
|
367
|
-
}, 400);
|
|
368
|
-
return oauthJson({ error: "invalid_request", error_description: "Invalid JSON body" }, 400);
|
|
369
|
-
}
|
|
370
|
-
return oauthBodyError(error);
|
|
371
|
-
}
|
|
372
|
-
const parsed = registrationSchema.safeParse(input);
|
|
373
|
-
if (!parsed.success)
|
|
374
|
-
return oauthJson({
|
|
375
|
-
error: "invalid_client_metadata",
|
|
376
|
-
error_description: parsed.error.issues.map((issue) => issue.message).join("; ")
|
|
377
|
-
}, 400);
|
|
378
|
-
const now = new Date;
|
|
379
|
-
const publicClient = parsed.data.token_endpoint_auth_method === "none";
|
|
380
|
-
const clientId = randomUUID();
|
|
381
|
-
const clientSecret = publicClient ? null : randomBytes(32).toString("hex");
|
|
382
|
-
const clientSecretExpiresAt = clientSecret ? new Date(now.getTime() + seams.configuration.clientSecretTtlSeconds * 1000) : null;
|
|
383
|
-
await seams.stores.clients.register({
|
|
384
|
-
clientId,
|
|
385
|
-
clientSecretHash: clientSecret ? seams.hashCredential(clientSecret) : null,
|
|
386
|
-
clientSecretExpiresAt,
|
|
387
|
-
clientName: parsed.data.client_name,
|
|
388
|
-
clientType: publicClient ? "public" : "confidential",
|
|
389
|
-
tokenEndpointAuthMethod: parsed.data.token_endpoint_auth_method,
|
|
390
|
-
applicationType: parsed.data.application_type ?? null,
|
|
391
|
-
redirectUris: parsed.data.redirect_uris,
|
|
392
|
-
grantTypes: parsed.data.grant_types,
|
|
393
|
-
responseTypes: parsed.data.response_types,
|
|
394
|
-
clientIdMetadataUrl: null,
|
|
395
|
-
createdAt: now,
|
|
396
|
-
updatedAt: now
|
|
397
|
-
});
|
|
398
|
-
seams.recordEvent?.({
|
|
399
|
-
category: "registration",
|
|
400
|
-
outcome: "success",
|
|
401
|
-
attributes: { clientId, isPublicClient: publicClient }
|
|
402
|
-
});
|
|
403
|
-
return oauthJson({
|
|
404
|
-
client_id: clientId,
|
|
405
|
-
...clientSecret && clientSecretExpiresAt ? {
|
|
406
|
-
client_secret: clientSecret,
|
|
407
|
-
client_secret_expires_at: Math.floor(clientSecretExpiresAt.getTime() / 1000)
|
|
408
|
-
} : {},
|
|
409
|
-
client_name: parsed.data.client_name,
|
|
410
|
-
redirect_uris: parsed.data.redirect_uris,
|
|
411
|
-
grant_types: parsed.data.grant_types,
|
|
412
|
-
response_types: parsed.data.response_types,
|
|
413
|
-
token_endpoint_auth_method: parsed.data.token_endpoint_auth_method,
|
|
414
|
-
...parsed.data.application_type ? { application_type: parsed.data.application_type } : {},
|
|
415
|
-
client_id_issued_at: Math.floor(now.getTime() / 1000)
|
|
416
|
-
}, 201, { "Cache-Control": "no-store, private", Vary: "Cookie" });
|
|
417
|
-
}
|
|
418
|
-
// src/oauth/token-endpoint.ts
|
|
419
|
-
import { createHash, randomBytes as randomBytes2, randomUUID as randomUUID2 } from "node:crypto";
|
|
420
|
-
|
|
421
|
-
// src/oauth/pkce-validation.ts
|
|
422
|
-
var minimumVerifierLength = 43;
|
|
423
|
-
var maximumVerifierLength = 128;
|
|
424
|
-
var challengeLength = 43;
|
|
425
|
-
var verifierPattern = new RegExp(`^[A-Za-z0-9\\-._~]{${minimumVerifierLength},${maximumVerifierLength}}$`);
|
|
426
|
-
var challengePattern = new RegExp(`^[A-Za-z0-9_-]{${challengeLength}}$`);
|
|
427
|
-
function isValidPkceCodeVerifier(value) {
|
|
428
|
-
return verifierPattern.test(value);
|
|
429
|
-
}
|
|
430
|
-
function isValidPkceCodeChallenge(value) {
|
|
431
|
-
return challengePattern.test(value);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// src/oauth/scope-utilities.ts
|
|
435
|
-
function splitScopes(value) {
|
|
436
|
-
return value.split(/\s+/).filter(Boolean);
|
|
437
|
-
}
|
|
438
|
-
function canonicalizeScopes(values) {
|
|
439
|
-
return [...new Set(values)].sort().join(" ");
|
|
440
|
-
}
|
|
441
|
-
function parseRequestedScope(value, supportedScopes) {
|
|
442
|
-
if (value === null)
|
|
443
|
-
return { ok: true, scope: canonicalizeScopes(supportedScopes) };
|
|
444
|
-
if (!value.trim())
|
|
445
|
-
return { ok: false, unknownScopes: [] };
|
|
446
|
-
const values = splitScopes(value);
|
|
447
|
-
const unknownScopes = values.filter((scope) => !supportedScopes.includes(scope));
|
|
448
|
-
if (unknownScopes.length > 0)
|
|
449
|
-
return { ok: false, unknownScopes };
|
|
450
|
-
return { ok: true, scope: canonicalizeScopes(values) };
|
|
451
|
-
}
|
|
452
|
-
function parseRefreshScope(value, supportedScopes) {
|
|
453
|
-
if (value === undefined)
|
|
454
|
-
return { ok: true };
|
|
455
|
-
if (!value.trim())
|
|
456
|
-
return { ok: false };
|
|
457
|
-
const values = splitScopes(value);
|
|
458
|
-
if (values.some((scope) => !supportedScopes.includes(scope)))
|
|
459
|
-
return { ok: false };
|
|
460
|
-
return { ok: true, requestedScope: canonicalizeScopes(values) };
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// src/oauth/token-endpoint.ts
|
|
464
|
-
var maximumTokenLength = 512;
|
|
465
|
-
var maximumUrlLength = 2048;
|
|
466
|
-
function issueCredentials(seams, now) {
|
|
467
|
-
const accessToken = randomBytes2(48).toString("hex");
|
|
468
|
-
const refreshToken = randomBytes2(48).toString("hex");
|
|
469
|
-
return {
|
|
470
|
-
accessToken,
|
|
471
|
-
refreshToken,
|
|
472
|
-
accessTokenHash: seams.hashCredential(accessToken),
|
|
473
|
-
refreshTokenHash: seams.hashCredential(refreshToken),
|
|
474
|
-
accessTokenExpiresAt: new Date(now.getTime() + seams.configuration.accessTokenTtlSeconds * 1000),
|
|
475
|
-
refreshTokenExpiresAt: new Date(now.getTime() + seams.configuration.refreshTokenTtlSeconds * 1000)
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
async function authorizationCodeGrant(body, seams) {
|
|
479
|
-
const {
|
|
480
|
-
code,
|
|
481
|
-
redirect_uri: redirectUri,
|
|
482
|
-
client_id: clientId,
|
|
483
|
-
client_secret: clientSecret,
|
|
484
|
-
code_verifier: verifier,
|
|
485
|
-
resource
|
|
486
|
-
} = body;
|
|
487
|
-
if (!code || !redirectUri || !clientId || !verifier || !resource)
|
|
488
|
-
return oauthJson({ error: "invalid_request", error_description: "Missing required parameters" }, 400);
|
|
489
|
-
if (code.length > maximumTokenLength || redirectUri.length > maximumUrlLength || clientId.length > maximumUrlLength || resource.length > maximumUrlLength)
|
|
490
|
-
return oauthJson({ error: "invalid_request", error_description: "A parameter exceeded its maximum length" }, 400);
|
|
491
|
-
if (resource !== seams.configuration.resource.href) {
|
|
492
|
-
seams.recordEvent?.({
|
|
493
|
-
category: "token_exchange",
|
|
494
|
-
outcome: "invalid_resource",
|
|
495
|
-
attributes: { grantType: "authorization_code" }
|
|
496
|
-
});
|
|
497
|
-
return oauthJson({
|
|
498
|
-
error: "invalid_target",
|
|
499
|
-
error_description: "resource does not match this server resource URL"
|
|
500
|
-
}, 400);
|
|
501
|
-
}
|
|
502
|
-
if (!isValidPkceCodeVerifier(verifier))
|
|
503
|
-
return oauthJson({ error: "invalid_grant", error_description: "Malformed code_verifier" }, 400);
|
|
504
|
-
const authentication = await authenticateOauthClient(clientId, clientSecret, seams);
|
|
505
|
-
if (!authentication.ok) {
|
|
506
|
-
seams.recordEvent?.({
|
|
507
|
-
category: "client_authentication",
|
|
508
|
-
outcome: "invalid_client",
|
|
509
|
-
attributes: { clientId }
|
|
510
|
-
});
|
|
511
|
-
return oauthJson({ error: "invalid_client" }, 401);
|
|
512
|
-
}
|
|
513
|
-
if (!authentication.client.grantTypes.includes("authorization_code"))
|
|
514
|
-
return oauthJson({ error: "unauthorized_client" }, 400);
|
|
515
|
-
const codeHash = seams.hashCredential(code);
|
|
516
|
-
const authorizationCode = await seams.stores.codes.findByHash(codeHash);
|
|
517
|
-
const now = new Date;
|
|
518
|
-
if (!authorizationCode || authorizationCode.clientId !== clientId || authorizationCode.usedAt || authorizationCode.expiresAt <= now)
|
|
519
|
-
return oauthJson({
|
|
520
|
-
error: "invalid_grant",
|
|
521
|
-
error_description: "Authorization code not found, already used, or expired"
|
|
522
|
-
}, 400);
|
|
523
|
-
if (authorizationCode.redirectUri !== redirectUri)
|
|
524
|
-
return oauthJson({ error: "invalid_grant", error_description: "Redirect URI mismatch" }, 400);
|
|
525
|
-
if (authorizationCode.resource !== resource) {
|
|
526
|
-
seams.recordEvent?.({
|
|
527
|
-
category: "token_exchange",
|
|
528
|
-
outcome: "invalid_resource",
|
|
529
|
-
attributes: { grantType: "authorization_code" }
|
|
530
|
-
});
|
|
531
|
-
return oauthJson({
|
|
532
|
-
error: "invalid_target",
|
|
533
|
-
error_description: "resource does not match the authorization code"
|
|
534
|
-
}, 400);
|
|
535
|
-
}
|
|
536
|
-
const challenge = createHash("sha256").update(verifier).digest("base64url");
|
|
537
|
-
if (!constantTimeEquals(challenge, authorizationCode.codeChallenge))
|
|
538
|
-
return oauthJson({ error: "invalid_grant", error_description: "PKCE verification failed" }, 400);
|
|
539
|
-
const consumedCode = await seams.stores.codes.consume(codeHash, now);
|
|
540
|
-
if (!consumedCode)
|
|
541
|
-
return oauthJson({ error: "invalid_grant", error_description: "Authorization code already used" }, 400);
|
|
542
|
-
const credentials = issueCredentials(seams, now);
|
|
543
|
-
const issueRefreshToken = authentication.client.grantTypes.includes("refresh_token");
|
|
544
|
-
try {
|
|
545
|
-
await seams.stores.tokens.issueAuthorizationGrant({
|
|
546
|
-
accessToken: {
|
|
547
|
-
accessTokenHash: credentials.accessTokenHash,
|
|
548
|
-
clientId,
|
|
549
|
-
userId: consumedCode.userId,
|
|
550
|
-
scope: consumedCode.scope ?? "",
|
|
551
|
-
resource,
|
|
552
|
-
expiresAt: credentials.accessTokenExpiresAt,
|
|
553
|
-
revokedAt: null,
|
|
554
|
-
createdAt: now
|
|
555
|
-
},
|
|
556
|
-
...issueRefreshToken ? {
|
|
557
|
-
refreshToken: {
|
|
558
|
-
refreshTokenHash: credentials.refreshTokenHash,
|
|
559
|
-
clientId,
|
|
560
|
-
userId: consumedCode.userId,
|
|
561
|
-
scope: consumedCode.scope ?? "",
|
|
562
|
-
resource,
|
|
563
|
-
accessTokenHash: credentials.accessTokenHash,
|
|
564
|
-
familyId: randomUUID2(),
|
|
565
|
-
expiresAt: credentials.refreshTokenExpiresAt,
|
|
566
|
-
revokedAt: null,
|
|
567
|
-
createdAt: now
|
|
568
|
-
}
|
|
569
|
-
} : {}
|
|
570
|
-
});
|
|
571
|
-
} catch (error) {
|
|
572
|
-
await seams.stores.codes.unconsume(codeHash, consumedCode.usedAt).catch(() => false);
|
|
573
|
-
throw error;
|
|
574
|
-
}
|
|
575
|
-
seams.recordEvent?.({ category: "token_exchange", outcome: "success" });
|
|
576
|
-
return oauthJson({
|
|
577
|
-
access_token: credentials.accessToken,
|
|
578
|
-
token_type: "Bearer",
|
|
579
|
-
expires_in: seams.configuration.accessTokenTtlSeconds,
|
|
580
|
-
...issueRefreshToken ? { refresh_token: credentials.refreshToken } : {},
|
|
581
|
-
scope: consumedCode.scope ?? ""
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
async function refreshTokenGrant(body, seams) {
|
|
585
|
-
const {
|
|
586
|
-
refresh_token: refreshToken,
|
|
587
|
-
client_id: clientId,
|
|
588
|
-
client_secret: clientSecret,
|
|
589
|
-
resource,
|
|
590
|
-
scope
|
|
591
|
-
} = body;
|
|
592
|
-
if (!refreshToken || !clientId || !resource)
|
|
593
|
-
return oauthJson({ error: "invalid_request", error_description: "Missing required parameters" }, 400);
|
|
594
|
-
if (refreshToken.length > maximumTokenLength || clientId.length > maximumUrlLength || resource.length > maximumUrlLength || (scope?.length ?? 0) > 512)
|
|
595
|
-
return oauthJson({ error: "invalid_request", error_description: "A parameter exceeded its maximum length" }, 400);
|
|
596
|
-
if (resource !== seams.configuration.resource.href) {
|
|
597
|
-
seams.recordEvent?.({
|
|
598
|
-
category: "refresh",
|
|
599
|
-
outcome: "invalid_resource",
|
|
600
|
-
attributes: { grantType: "refresh_token" }
|
|
601
|
-
});
|
|
602
|
-
return oauthJson({
|
|
603
|
-
error: "invalid_target",
|
|
604
|
-
error_description: "resource does not match this server resource URL"
|
|
605
|
-
}, 400);
|
|
606
|
-
}
|
|
607
|
-
const parsedScope = parseRefreshScope(scope, seams.scopes.supportedScopes);
|
|
608
|
-
if (!parsedScope.ok)
|
|
609
|
-
return oauthJson({ error: "invalid_scope" }, 400);
|
|
610
|
-
const authentication = await authenticateOauthClient(clientId, clientSecret, seams);
|
|
611
|
-
if (!authentication.ok) {
|
|
612
|
-
seams.recordEvent?.({
|
|
613
|
-
category: "client_authentication",
|
|
614
|
-
outcome: "invalid_client",
|
|
615
|
-
attributes: { clientId }
|
|
616
|
-
});
|
|
617
|
-
return oauthJson({ error: "invalid_client" }, 401);
|
|
618
|
-
}
|
|
619
|
-
if (!authentication.client.grantTypes.includes("refresh_token"))
|
|
620
|
-
return oauthJson({ error: "unauthorized_client" }, 400);
|
|
621
|
-
const now = new Date;
|
|
622
|
-
const credentials = issueCredentials(seams, now);
|
|
623
|
-
const rotation = await seams.stores.tokens.rotateRefreshToken({
|
|
624
|
-
priorHash: seams.hashCredential(refreshToken),
|
|
625
|
-
clientId,
|
|
626
|
-
resource,
|
|
627
|
-
...parsedScope.requestedScope !== undefined ? { requestedScope: parsedScope.requestedScope } : {},
|
|
628
|
-
nextAccessTokenHash: credentials.accessTokenHash,
|
|
629
|
-
nextRefreshTokenHash: credentials.refreshTokenHash,
|
|
630
|
-
accessTokenExpiresAt: credentials.accessTokenExpiresAt,
|
|
631
|
-
refreshTokenExpiresAt: credentials.refreshTokenExpiresAt,
|
|
632
|
-
createdAt: now
|
|
633
|
-
});
|
|
634
|
-
if (rotation.status === "replay_revoked") {
|
|
635
|
-
seams.recordEvent?.({
|
|
636
|
-
category: "refresh",
|
|
637
|
-
outcome: "replay_detected",
|
|
638
|
-
attributes: { familyId: rotation.familyId }
|
|
639
|
-
});
|
|
640
|
-
await seams.publishGrantRevocation?.(rotation.userId);
|
|
641
|
-
return oauthJson({
|
|
642
|
-
error: "invalid_grant",
|
|
643
|
-
error_description: "Refresh token not found, already used, or expired"
|
|
644
|
-
}, 400);
|
|
645
|
-
}
|
|
646
|
-
if (rotation.status === "scope_rejected")
|
|
647
|
-
return oauthJson({ error: "invalid_scope", error_description: "Requested scope exceeds the original grant" }, 400);
|
|
648
|
-
if (rotation.status === "invalid")
|
|
649
|
-
return oauthJson({
|
|
650
|
-
error: "invalid_grant",
|
|
651
|
-
error_description: "Refresh token not found, already used, or expired"
|
|
652
|
-
}, 400);
|
|
653
|
-
seams.recordEvent?.({ category: "refresh", outcome: "success" });
|
|
654
|
-
return oauthJson({
|
|
655
|
-
access_token: credentials.accessToken,
|
|
656
|
-
token_type: "Bearer",
|
|
657
|
-
expires_in: seams.configuration.accessTokenTtlSeconds,
|
|
658
|
-
refresh_token: credentials.refreshToken,
|
|
659
|
-
scope: rotation.accessToken.scope ?? ""
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
async function handleOauthTokenPost(context, seams) {
|
|
663
|
-
if (await isAuthenticationLockedOut(context, seams))
|
|
664
|
-
return oauthJson({ error: "invalid_client", error_description: "Too many failed authentication attempts." }, 429);
|
|
665
|
-
const networkLimit = await rateLimitResponse({ context, seams, category: "oauth_token_network" });
|
|
666
|
-
if (networkLimit)
|
|
667
|
-
return networkLimit;
|
|
668
|
-
let body;
|
|
669
|
-
try {
|
|
670
|
-
body = await readOauthParameters(context.request, oauthTokenMaximumBodyBytes);
|
|
671
|
-
} catch (error) {
|
|
672
|
-
return oauthBodyError(error);
|
|
673
|
-
}
|
|
674
|
-
if (body.client_id) {
|
|
675
|
-
const clientLimit = await rateLimitResponse({
|
|
676
|
-
context,
|
|
677
|
-
seams,
|
|
678
|
-
category: "oauth_token_client",
|
|
679
|
-
identifier: body.client_id
|
|
680
|
-
});
|
|
681
|
-
if (clientLimit)
|
|
682
|
-
return clientLimit;
|
|
683
|
-
}
|
|
684
|
-
let response;
|
|
685
|
-
if (body.grant_type === "authorization_code")
|
|
686
|
-
response = await authorizationCodeGrant(body, seams);
|
|
687
|
-
else if (body.grant_type === "refresh_token")
|
|
688
|
-
response = await refreshTokenGrant(body, seams);
|
|
689
|
-
else
|
|
690
|
-
response = oauthJson({ error: "unsupported_grant_type" }, 400);
|
|
691
|
-
if (response.status === 401)
|
|
692
|
-
await recordFailedAuthentication(context, seams);
|
|
693
|
-
return response;
|
|
694
|
-
}
|
|
695
|
-
// src/oauth/revocation-endpoint.ts
|
|
696
|
-
async function handleOauthRevokePost(context, seams) {
|
|
697
|
-
if (await isAuthenticationLockedOut(context, seams))
|
|
698
|
-
return oauthJson({ error: "invalid_client", error_description: "Too many failed authentication attempts." }, 429);
|
|
699
|
-
const limited = await rateLimitResponse({ context, seams, category: "oauth_revoke" });
|
|
700
|
-
if (limited)
|
|
701
|
-
return limited;
|
|
702
|
-
let body;
|
|
703
|
-
try {
|
|
704
|
-
body = await readOauthParameters(context.request, oauthRevokeMaximumBodyBytes);
|
|
705
|
-
} catch (error) {
|
|
706
|
-
return oauthBodyError(error);
|
|
707
|
-
}
|
|
708
|
-
const { token, token_type_hint: hint, client_id: clientId, client_secret: clientSecret } = body;
|
|
709
|
-
if (!token || !clientId)
|
|
710
|
-
return oauthJson({ error: "invalid_request", error_description: "Missing token or client_id parameter" }, 400);
|
|
711
|
-
if (token.length > 512 || clientId.length > 2048)
|
|
712
|
-
return oauthJson({ error: "invalid_request", error_description: "A parameter exceeded its maximum length" }, 400);
|
|
713
|
-
const authentication = await authenticateOauthClient(clientId, clientSecret, seams);
|
|
714
|
-
if (!authentication.ok) {
|
|
715
|
-
seams.recordEvent?.({
|
|
716
|
-
category: "client_authentication",
|
|
717
|
-
outcome: "invalid_client",
|
|
718
|
-
attributes: { clientId }
|
|
719
|
-
});
|
|
720
|
-
await recordFailedAuthentication(context, seams);
|
|
721
|
-
return oauthJson({ error: "invalid_client" }, 401);
|
|
722
|
-
}
|
|
723
|
-
const tokenHash = seams.hashCredential(token);
|
|
724
|
-
let subjectId;
|
|
725
|
-
let replayFamilyId;
|
|
726
|
-
let outcome = "not_found_or_already_revoked";
|
|
727
|
-
const revokeRefresh = async () => {
|
|
728
|
-
const result = await seams.stores.tokens.revokeRefreshToken(tokenHash, clientId);
|
|
729
|
-
if (result.status === "invalid")
|
|
730
|
-
return false;
|
|
731
|
-
subjectId = result.userId;
|
|
732
|
-
if (result.status === "replay_revoked")
|
|
733
|
-
replayFamilyId = result.familyId;
|
|
734
|
-
outcome = result.status === "replay_revoked" ? "replay_detected" : "refresh_token_revoked";
|
|
735
|
-
return true;
|
|
736
|
-
};
|
|
737
|
-
const revokeAccess = async () => {
|
|
738
|
-
const revoked = await seams.stores.tokens.revokeAccessToken(tokenHash, clientId);
|
|
739
|
-
if (revoked)
|
|
740
|
-
outcome = "access_token_revoked";
|
|
741
|
-
return revoked;
|
|
742
|
-
};
|
|
743
|
-
const attempts = hint === "refresh_token" ? [revokeRefresh, revokeAccess] : [revokeAccess, revokeRefresh];
|
|
744
|
-
for (const attempt of attempts) {
|
|
745
|
-
if (await attempt())
|
|
746
|
-
break;
|
|
747
|
-
}
|
|
748
|
-
seams.recordEvent?.({
|
|
749
|
-
category: "revocation",
|
|
750
|
-
outcome,
|
|
751
|
-
attributes: replayFamilyId ? { familyId: replayFamilyId } : { clientId }
|
|
752
|
-
});
|
|
753
|
-
if (subjectId)
|
|
754
|
-
await seams.publishGrantRevocation?.(subjectId);
|
|
755
|
-
return new Response(null, { status: 200, headers: oauthNoStoreHeaders });
|
|
756
|
-
}
|
|
757
|
-
// src/oauth/authorize-endpoint.ts
|
|
758
|
-
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
759
|
-
|
|
760
|
-
// src/oauth/redirect-uri-matching.ts
|
|
761
|
-
function isLoopbackRedirectUri(parsed) {
|
|
762
|
-
return parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "[::1]");
|
|
763
|
-
}
|
|
764
|
-
function redirectUriMatchesRegistered(requestedUri, registeredUris) {
|
|
765
|
-
if (!isValidRedirectUri(requestedUri))
|
|
766
|
-
return false;
|
|
767
|
-
const validRegisteredUris = registeredUris.filter(isValidRedirectUri);
|
|
768
|
-
if (validRegisteredUris.includes(requestedUri))
|
|
769
|
-
return true;
|
|
770
|
-
const requested = new URL(requestedUri);
|
|
771
|
-
if (!isLoopbackRedirectUri(requested))
|
|
772
|
-
return false;
|
|
773
|
-
return validRegisteredUris.some((registeredUri) => {
|
|
774
|
-
const registered = new URL(registeredUri);
|
|
775
|
-
return isLoopbackRedirectUri(registered) && registered.hostname === requested.hostname && registered.pathname === requested.pathname && registered.search === requested.search;
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// src/oauth/authorize-endpoint.ts
|
|
780
|
-
var authorizationLifetimeMilliseconds = 10 * 60 * 1000;
|
|
781
|
-
var maximumClientIdLength = 2048;
|
|
782
|
-
var maximumRedirectUriLength = 2048;
|
|
783
|
-
var maximumStateLength = 512;
|
|
784
|
-
var maximumScopeLength = 512;
|
|
785
|
-
var maximumResourceLength = 2048;
|
|
786
|
-
var transactionIdLength = 64;
|
|
787
|
-
var csrfTokenLength = 64;
|
|
788
|
-
var authorizeParameterNames = [
|
|
789
|
-
"client_id",
|
|
790
|
-
"redirect_uri",
|
|
791
|
-
"response_type",
|
|
792
|
-
"code_challenge",
|
|
793
|
-
"code_challenge_method",
|
|
794
|
-
"state",
|
|
795
|
-
"resource",
|
|
796
|
-
"scope"
|
|
797
|
-
];
|
|
798
|
-
var authorizeFormParameterNames = ["transaction_id", "csrf_token"];
|
|
799
|
-
function redirect(location, status = 302) {
|
|
800
|
-
return new Response(null, {
|
|
801
|
-
status,
|
|
802
|
-
headers: { Location: location, "Cache-Control": "no-store" }
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
function protocolErrorRedirect(input) {
|
|
806
|
-
const url = new URL(input.redirectUri);
|
|
807
|
-
url.searchParams.set("error", input.error);
|
|
808
|
-
url.searchParams.set("error_description", input.errorDescription);
|
|
809
|
-
if (input.state)
|
|
810
|
-
url.searchParams.set("state", input.state);
|
|
811
|
-
url.searchParams.set("iss", input.issuer);
|
|
812
|
-
return redirect(url.toString());
|
|
813
|
-
}
|
|
814
|
-
function duplicateParameter(parameters, names) {
|
|
815
|
-
return names.find((name) => parameters.getAll(name).length > 1);
|
|
816
|
-
}
|
|
817
|
-
async function readAuthorizeForm(request, maximumBytes) {
|
|
818
|
-
if (!isExactContentType(request.headers.get("content-type"), "application/x-www-form-urlencoded"))
|
|
819
|
-
throw new Error("unsupported_content_type");
|
|
820
|
-
return new URLSearchParams(await readBoundedText(request, maximumBytes));
|
|
821
|
-
}
|
|
822
|
-
function formError(error) {
|
|
823
|
-
if (error instanceof PayloadTooLargeError)
|
|
824
|
-
return oauthJson({ error: "invalid_request", message: "Request body too large." }, 413);
|
|
825
|
-
if (error instanceof Error && error.message === "unsupported_content_type")
|
|
826
|
-
return oauthJson({ error: "unsupported_content_type" }, 400);
|
|
827
|
-
return oauthJson({ error: "invalid_request", message: "Request body is not valid UTF-8." }, 400);
|
|
828
|
-
}
|
|
829
|
-
async function resolveIdentity(context, seams) {
|
|
830
|
-
return context.identity ?? seams.resolveIdentityBinding(context.request);
|
|
831
|
-
}
|
|
832
|
-
function isAuthorizationServerOrigin(origin, baseUrl) {
|
|
833
|
-
try {
|
|
834
|
-
return new URL(origin).origin === baseUrl.origin;
|
|
835
|
-
} catch {
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
async function handleOauthAuthorizeGet(context, seams) {
|
|
840
|
-
const limited = await rateLimitResponse({ context, seams, category: "oauth_authorize" });
|
|
841
|
-
if (limited)
|
|
842
|
-
return limited;
|
|
843
|
-
const identity = await resolveIdentity(context, seams);
|
|
844
|
-
if (!identity)
|
|
845
|
-
return seams.handleUnauthenticatedAuthorization(context.request);
|
|
846
|
-
const duplicate = duplicateParameter(context.requestUrl.searchParams, authorizeParameterNames);
|
|
847
|
-
if (duplicate)
|
|
848
|
-
return seams.renderConsent({
|
|
849
|
-
mode: "error",
|
|
850
|
-
error: `Duplicate OAuth parameter: ${duplicate}.`
|
|
851
|
-
});
|
|
852
|
-
const clientId = context.requestUrl.searchParams.get("client_id");
|
|
853
|
-
const redirectUri = context.requestUrl.searchParams.get("redirect_uri");
|
|
854
|
-
const responseType = context.requestUrl.searchParams.get("response_type");
|
|
855
|
-
const codeChallenge = context.requestUrl.searchParams.get("code_challenge");
|
|
856
|
-
const codeChallengeMethod = context.requestUrl.searchParams.get("code_challenge_method");
|
|
857
|
-
const state = context.requestUrl.searchParams.get("state") || "";
|
|
858
|
-
const resource = context.requestUrl.searchParams.get("resource");
|
|
859
|
-
const rawScope = context.requestUrl.searchParams.get("scope");
|
|
860
|
-
if (!clientId || !redirectUri || !codeChallenge)
|
|
861
|
-
return seams.renderConsent({
|
|
862
|
-
mode: "error",
|
|
863
|
-
error: "Invalid OAuth parameters. Missing required fields."
|
|
864
|
-
});
|
|
865
|
-
if (clientId.length > maximumClientIdLength || redirectUri.length > maximumRedirectUriLength || state.length > maximumStateLength || resource !== null && resource.length > maximumResourceLength || rawScope !== null && rawScope.length > maximumScopeLength)
|
|
866
|
-
return seams.renderConsent({
|
|
867
|
-
mode: "error",
|
|
868
|
-
error: "A parameter exceeded its maximum length."
|
|
869
|
-
});
|
|
870
|
-
let client = null;
|
|
871
|
-
if (isClientIdMetadataDocumentUrl(clientId)) {
|
|
872
|
-
const document = await seams.fetchClientIdMetadataDocument(clientId);
|
|
873
|
-
if (document) {
|
|
874
|
-
const now2 = new Date;
|
|
875
|
-
client = {
|
|
876
|
-
clientId: document.clientId,
|
|
877
|
-
clientSecretHash: null,
|
|
878
|
-
clientSecretExpiresAt: null,
|
|
879
|
-
clientName: document.clientName,
|
|
880
|
-
clientType: "public",
|
|
881
|
-
tokenEndpointAuthMethod: "none",
|
|
882
|
-
applicationType: document.applicationType ?? null,
|
|
883
|
-
redirectUris: document.redirectUris,
|
|
884
|
-
grantTypes: document.grantTypes,
|
|
885
|
-
responseTypes: document.responseTypes,
|
|
886
|
-
clientIdMetadataUrl: document.clientId,
|
|
887
|
-
createdAt: now2,
|
|
888
|
-
updatedAt: now2
|
|
889
|
-
};
|
|
890
|
-
await seams.stores.clients.upsert(client);
|
|
891
|
-
}
|
|
892
|
-
} else {
|
|
893
|
-
client = await seams.stores.clients.findById(clientId);
|
|
894
|
-
}
|
|
895
|
-
if (!client)
|
|
896
|
-
return seams.renderConsent({ mode: "error", error: "Unknown OAuth client." });
|
|
897
|
-
if (!redirectUriMatchesRegistered(redirectUri, client.redirectUris))
|
|
898
|
-
return seams.renderConsent({ mode: "error", error: "Invalid redirect URI." });
|
|
899
|
-
const issuer = seams.configuration.issuer;
|
|
900
|
-
if (!resource || resource !== seams.configuration.resource.href)
|
|
901
|
-
return protocolErrorRedirect({
|
|
902
|
-
redirectUri,
|
|
903
|
-
error: "invalid_target",
|
|
904
|
-
errorDescription: "Missing or unsupported resource parameter. resource must exactly match this server's MCP resource URL.",
|
|
905
|
-
state,
|
|
906
|
-
issuer
|
|
907
|
-
});
|
|
908
|
-
if (responseType !== "code")
|
|
909
|
-
return protocolErrorRedirect({
|
|
910
|
-
redirectUri,
|
|
911
|
-
error: "unsupported_response_type",
|
|
912
|
-
errorDescription: 'Only the "code" response type is supported.',
|
|
913
|
-
state,
|
|
914
|
-
issuer
|
|
915
|
-
});
|
|
916
|
-
const requestedScope = parseRequestedScope(rawScope, seams.scopes.supportedScopes);
|
|
917
|
-
if (!requestedScope.ok)
|
|
918
|
-
return protocolErrorRedirect({
|
|
919
|
-
redirectUri,
|
|
920
|
-
error: "invalid_scope",
|
|
921
|
-
errorDescription: requestedScope.unknownScopes.length > 0 ? `Unsupported scope: ${requestedScope.unknownScopes.join(", ")}.` : "The scope parameter must not be empty.",
|
|
922
|
-
state,
|
|
923
|
-
issuer
|
|
924
|
-
});
|
|
925
|
-
if (codeChallengeMethod && codeChallengeMethod !== "S256")
|
|
926
|
-
return protocolErrorRedirect({
|
|
927
|
-
redirectUri,
|
|
928
|
-
error: "invalid_request",
|
|
929
|
-
errorDescription: "Only S256 code challenge method is supported.",
|
|
930
|
-
state,
|
|
931
|
-
issuer
|
|
932
|
-
});
|
|
933
|
-
if (!isValidPkceCodeChallenge(codeChallenge))
|
|
934
|
-
return protocolErrorRedirect({
|
|
935
|
-
redirectUri,
|
|
936
|
-
error: "invalid_request",
|
|
937
|
-
errorDescription: "Malformed code_challenge.",
|
|
938
|
-
state,
|
|
939
|
-
issuer
|
|
940
|
-
});
|
|
941
|
-
if (!client.responseTypes.includes("code"))
|
|
942
|
-
return protocolErrorRedirect({
|
|
943
|
-
redirectUri,
|
|
944
|
-
error: "unauthorized_client",
|
|
945
|
-
errorDescription: "This client is not registered for the code response type.",
|
|
946
|
-
state,
|
|
947
|
-
issuer
|
|
948
|
-
});
|
|
949
|
-
if (!client.grantTypes.includes("authorization_code"))
|
|
950
|
-
return protocolErrorRedirect({
|
|
951
|
-
redirectUri,
|
|
952
|
-
error: "unauthorized_client",
|
|
953
|
-
errorDescription: "This client is not registered for the authorization_code grant type.",
|
|
954
|
-
state,
|
|
955
|
-
issuer
|
|
956
|
-
});
|
|
957
|
-
const transactionId = randomBytes3(32).toString("hex");
|
|
958
|
-
const csrfToken = randomBytes3(32).toString("hex");
|
|
959
|
-
const now = new Date;
|
|
960
|
-
await seams.stores.transactions.create({
|
|
961
|
-
transactionId,
|
|
962
|
-
csrfToken,
|
|
963
|
-
consentBinding: identity.consentBinding,
|
|
964
|
-
record: {
|
|
965
|
-
userId: identity.subjectId,
|
|
966
|
-
clientId,
|
|
967
|
-
redirectUri,
|
|
968
|
-
codeChallenge,
|
|
969
|
-
codeChallengeMethod: codeChallengeMethod || "S256",
|
|
970
|
-
state: state || null,
|
|
971
|
-
issuer,
|
|
972
|
-
resource,
|
|
973
|
-
scope: requestedScope.scope,
|
|
974
|
-
expiresAt: new Date(now.getTime() + authorizationLifetimeMilliseconds),
|
|
975
|
-
consumedAt: null,
|
|
976
|
-
createdAt: now
|
|
977
|
-
}
|
|
978
|
-
});
|
|
979
|
-
const clientName = isValidClientName(client.clientName) ? client.clientName : "the requesting application";
|
|
980
|
-
const requester = await seams.resolveUserProfile(identity.subjectId);
|
|
981
|
-
if (!requester)
|
|
982
|
-
return seams.renderConsent({
|
|
983
|
-
mode: "error",
|
|
984
|
-
error: "The authenticated account profile could not be resolved."
|
|
985
|
-
});
|
|
986
|
-
return seams.renderConsent({
|
|
987
|
-
mode: "prompt",
|
|
988
|
-
transactionId,
|
|
989
|
-
csrfToken,
|
|
990
|
-
redirectUri,
|
|
991
|
-
client: { id: client.clientId, name: clientName },
|
|
992
|
-
requester,
|
|
993
|
-
scopes: splitScopes(requestedScope.scope).map((scope) => ({
|
|
994
|
-
scope,
|
|
995
|
-
description: seams.scopes.vocabulary.descriptions[scope] ?? scope
|
|
996
|
-
}))
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
async function consumeForm(input) {
|
|
1000
|
-
const identity = await resolveIdentity(input.context, input.seams);
|
|
1001
|
-
if (!identity)
|
|
1002
|
-
return oauthJson({ error: "unauthorized" }, 401);
|
|
1003
|
-
const fetchSite = input.context.request.headers.get("sec-fetch-site")?.toLowerCase();
|
|
1004
|
-
const origin = input.context.request.headers.get("origin");
|
|
1005
|
-
const trustedRequest = fetchSite === "same-origin" || fetchSite === "none" || !fetchSite && origin !== null && isAuthorizationServerOrigin(origin, input.seams.configuration.baseUrl);
|
|
1006
|
-
if (!trustedRequest)
|
|
1007
|
-
return oauthJson({ error: "invalid_request", message: "Cross-site request rejected." }, 403);
|
|
1008
|
-
let parameters;
|
|
1009
|
-
try {
|
|
1010
|
-
parameters = await readAuthorizeForm(input.context.request, input.maximumBytes);
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
return formError(error);
|
|
1013
|
-
}
|
|
1014
|
-
const duplicate = duplicateParameter(parameters, authorizeFormParameterNames);
|
|
1015
|
-
if (duplicate)
|
|
1016
|
-
return oauthJson({ error: "invalid_request", message: `Duplicate parameter: ${duplicate}.` }, 400);
|
|
1017
|
-
const transactionId = parameters.get("transaction_id");
|
|
1018
|
-
const csrfToken = parameters.get("csrf_token");
|
|
1019
|
-
if (!transactionId || !csrfToken)
|
|
1020
|
-
return oauthJson({ error: "invalid_request", message: "Missing transaction_id or csrf_token." }, 400);
|
|
1021
|
-
if (transactionId.length > transactionIdLength || csrfToken.length > csrfTokenLength)
|
|
1022
|
-
return oauthJson({ error: "invalid_request", message: "A parameter exceeded its maximum length." }, 400);
|
|
1023
|
-
const transaction = await input.seams.stores.transactions.consume(transactionId, csrfToken, identity.consentBinding, identity.subjectId);
|
|
1024
|
-
if (!transaction)
|
|
1025
|
-
return oauthJson({
|
|
1026
|
-
error: "invalid_request",
|
|
1027
|
-
message: "Authorization transaction not found, already used, expired, or invalid."
|
|
1028
|
-
}, 400);
|
|
1029
|
-
return { transactionId, transaction, identity };
|
|
1030
|
-
}
|
|
1031
|
-
async function handleOauthAuthorizeApprove(context, seams) {
|
|
1032
|
-
const consumed = await consumeForm({
|
|
1033
|
-
context,
|
|
1034
|
-
seams,
|
|
1035
|
-
maximumBytes: oauthAuthorizeApproveMaximumBodyBytes
|
|
1036
|
-
});
|
|
1037
|
-
if (consumed instanceof Response)
|
|
1038
|
-
return consumed;
|
|
1039
|
-
const { transactionId, transaction } = consumed;
|
|
1040
|
-
if (!transaction)
|
|
1041
|
-
throw new Error("Authorization invariant violated");
|
|
1042
|
-
const code = randomBytes3(32).toString("hex");
|
|
1043
|
-
try {
|
|
1044
|
-
await seams.stores.codes.issue({
|
|
1045
|
-
codeHash: seams.hashCredential(code),
|
|
1046
|
-
clientId: transaction.clientId,
|
|
1047
|
-
userId: consumed.identity.subjectId,
|
|
1048
|
-
redirectUri: transaction.redirectUri,
|
|
1049
|
-
codeChallenge: transaction.codeChallenge,
|
|
1050
|
-
codeChallengeMethod: transaction.codeChallengeMethod,
|
|
1051
|
-
state: transaction.state,
|
|
1052
|
-
resource: transaction.resource,
|
|
1053
|
-
scope: transaction.scope,
|
|
1054
|
-
expiresAt: new Date(Date.now() + authorizationLifetimeMilliseconds),
|
|
1055
|
-
usedAt: null,
|
|
1056
|
-
createdAt: new Date
|
|
1057
|
-
});
|
|
1058
|
-
} catch (error) {
|
|
1059
|
-
await seams.stores.transactions.unconsume(transactionId, transaction.consumedAt).catch(() => false);
|
|
1060
|
-
throw error;
|
|
1061
|
-
}
|
|
1062
|
-
const redirectUrl = new URL(transaction.redirectUri);
|
|
1063
|
-
redirectUrl.searchParams.set("code", code);
|
|
1064
|
-
if (transaction.state)
|
|
1065
|
-
redirectUrl.searchParams.set("state", transaction.state);
|
|
1066
|
-
redirectUrl.searchParams.set("iss", transaction.issuer);
|
|
1067
|
-
return redirect(redirectUrl.toString());
|
|
1068
|
-
}
|
|
1069
|
-
async function handleOauthAuthorizeDeny(context, seams) {
|
|
1070
|
-
const consumed = await consumeForm({
|
|
1071
|
-
context,
|
|
1072
|
-
seams,
|
|
1073
|
-
maximumBytes: oauthAuthorizeDenyMaximumBodyBytes
|
|
1074
|
-
});
|
|
1075
|
-
if (consumed instanceof Response)
|
|
1076
|
-
return consumed;
|
|
1077
|
-
if (!consumed.transaction)
|
|
1078
|
-
throw new Error("Authorization invariant violated");
|
|
1079
|
-
seams.recordEvent?.({
|
|
1080
|
-
category: "authorization",
|
|
1081
|
-
outcome: "user_denied",
|
|
1082
|
-
attributes: { clientId: consumed.transaction.clientId }
|
|
1083
|
-
});
|
|
1084
|
-
const redirectUrl = new URL(consumed.transaction.redirectUri);
|
|
1085
|
-
redirectUrl.searchParams.set("error", "access_denied");
|
|
1086
|
-
redirectUrl.searchParams.set("error_description", "The user denied the authorization request.");
|
|
1087
|
-
if (consumed.transaction.state)
|
|
1088
|
-
redirectUrl.searchParams.set("state", consumed.transaction.state);
|
|
1089
|
-
redirectUrl.searchParams.set("iss", consumed.transaction.issuer);
|
|
1090
|
-
return redirect(redirectUrl.toString());
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
// src/oauth/index.ts
|
|
1094
|
-
var fetchClientIdMetadataDocument2 = fetchClientIdMetadataDocument;
|
|
1095
|
-
var isClientIdMetadataDocumentUrl2 = isClientIdMetadataDocumentUrl;
|
|
1096
|
-
var safeFetchPublicHttpsUrl2 = safeFetchPublicHttpsUrl;
|
|
1097
|
-
var isAddressInCidr2 = isAddressInCidr;
|
|
1098
|
-
var isValidCidr2 = isValidCidr;
|
|
1099
|
-
var isValidRedirectUri2 = isValidRedirectUri;
|
|
1100
|
-
var isValidClientName2 = isValidClientName;
|
|
1101
|
-
var isExactContentType2 = isExactContentType;
|
|
1102
|
-
var withDeadline2 = withDeadline;
|
|
1103
|
-
var canonicalizeIpAddress2 = canonicalizeIpAddress;
|
|
1104
|
-
var expandIpv6Groups2 = expandIpv6Groups;
|
|
1105
|
-
var stripPort2 = stripPort;
|
|
1106
|
-
|
|
1107
|
-
export { oauthCorsHeaders, handleOauthAuthorizationMetadataGet, handleOauthProtectedResourceMetadataGet, handleOauthProtectedResourceMcpMetadataGet, authenticateOauthClient, isSocketPeerTrusted, resolveOauthNetworkIdentity, handleOauthRegisterPost, isValidPkceCodeVerifier, isValidPkceCodeChallenge, handleOauthTokenPost, handleOauthRevokePost, authorizeFormParameterNames, handleOauthAuthorizeGet, handleOauthAuthorizeApprove, handleOauthAuthorizeDeny, fetchClientIdMetadataDocument2 as fetchClientIdMetadataDocument, isClientIdMetadataDocumentUrl2 as isClientIdMetadataDocumentUrl, safeFetchPublicHttpsUrl2 as safeFetchPublicHttpsUrl, isAddressInCidr2 as isAddressInCidr, isValidCidr2 as isValidCidr, isValidRedirectUri2 as isValidRedirectUri, isValidClientName2 as isValidClientName, isExactContentType2 as isExactContentType, withDeadline2 as withDeadline, canonicalizeIpAddress2 as canonicalizeIpAddress, expandIpv6Groups2 as expandIpv6Groups, stripPort2 as stripPort };
|