harness-mcp-v2 3.2.34 → 3.2.35
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 +54 -14
- package/build/client/harness-client.d.ts.map +1 -1
- package/build/client/harness-client.js +69 -11
- package/build/client/harness-client.js.map +1 -1
- package/build/config.d.ts +81 -2
- package/build/config.d.ts.map +1 -1
- package/build/config.js +132 -15
- package/build/config.js.map +1 -1
- package/build/data/schemas/v0/pipeline.d.ts.map +1 -1
- package/build/data/schemas/v0/pipeline.js +14861 -14726
- package/build/data/schemas/v0/pipeline.js.map +1 -1
- package/build/data/schemas/v0/template.d.ts.map +1 -1
- package/build/data/schemas/v0/template.js +6977 -6851
- package/build/data/schemas/v0/template.js.map +1 -1
- package/build/data/schemas/v1/pipeline.d.ts.map +1 -1
- package/build/data/schemas/v1/pipeline.js +261 -62
- package/build/data/schemas/v1/pipeline.js.map +1 -1
- package/build/data/schemas/v1/template.d.ts.map +1 -1
- package/build/data/schemas/v1/template.js +261 -62
- package/build/data/schemas/v1/template.js.map +1 -1
- package/build/index.js +25 -7
- package/build/index.js.map +1 -1
- package/build/prompts/run-evaluation.d.ts.map +1 -1
- package/build/prompts/run-evaluation.js +2 -1
- package/build/prompts/run-evaluation.js.map +1 -1
- package/build/registry/extractors.d.ts +32 -0
- package/build/registry/extractors.d.ts.map +1 -1
- package/build/registry/extractors.js +69 -0
- package/build/registry/extractors.js.map +1 -1
- package/build/registry/index.d.ts +23 -3
- package/build/registry/index.d.ts.map +1 -1
- package/build/registry/index.js +119 -6
- package/build/registry/index.js.map +1 -1
- package/build/registry/toolsets/ai-evals.d.ts.map +1 -1
- package/build/registry/toolsets/ai-evals.js +348 -100
- package/build/registry/toolsets/ai-evals.js.map +1 -1
- package/build/registry/toolsets/ccm-cost-category.d.ts +16 -0
- package/build/registry/toolsets/ccm-cost-category.d.ts.map +1 -0
- package/build/registry/toolsets/ccm-cost-category.js +46 -0
- package/build/registry/toolsets/ccm-cost-category.js.map +1 -0
- package/build/registry/toolsets/ccm.d.ts.map +1 -1
- package/build/registry/toolsets/ccm.js +15 -14
- package/build/registry/toolsets/ccm.js.map +1 -1
- package/build/registry/toolsets/chaos-descriptions.d.ts +48 -15
- package/build/registry/toolsets/chaos-descriptions.d.ts.map +1 -1
- package/build/registry/toolsets/chaos-descriptions.js +60 -20
- package/build/registry/toolsets/chaos-descriptions.js.map +1 -1
- package/build/registry/toolsets/chaos.d.ts.map +1 -1
- package/build/registry/toolsets/chaos.js +409 -41
- package/build/registry/toolsets/chaos.js.map +1 -1
- package/build/registry/toolsets/connectors.js +3 -3
- package/build/registry/toolsets/connectors.js.map +1 -1
- package/build/registry/toolsets/registries-v3.d.ts.map +1 -1
- package/build/registry/toolsets/registries-v3.js +80 -2
- package/build/registry/toolsets/registries-v3.js.map +1 -1
- package/build/tools/field-copy.d.ts +51 -0
- package/build/tools/field-copy.d.ts.map +1 -0
- package/build/tools/field-copy.js +46 -0
- package/build/tools/field-copy.js.map +1 -0
- package/build/tools/harness-create.d.ts.map +1 -1
- package/build/tools/harness-create.js +13 -10
- package/build/tools/harness-create.js.map +1 -1
- package/build/tools/harness-delete.d.ts.map +1 -1
- package/build/tools/harness-delete.js +12 -9
- package/build/tools/harness-delete.js.map +1 -1
- package/build/tools/harness-describe.d.ts.map +1 -1
- package/build/tools/harness-describe.js +14 -6
- package/build/tools/harness-describe.js.map +1 -1
- package/build/tools/harness-diagnose.d.ts.map +1 -1
- package/build/tools/harness-diagnose.js +9 -6
- package/build/tools/harness-diagnose.js.map +1 -1
- package/build/tools/harness-execute.d.ts.map +1 -1
- package/build/tools/harness-execute.js +19 -14
- package/build/tools/harness-execute.js.map +1 -1
- package/build/tools/harness-get.d.ts.map +1 -1
- package/build/tools/harness-get.js +10 -8
- package/build/tools/harness-get.js.map +1 -1
- package/build/tools/harness-list.d.ts.map +1 -1
- package/build/tools/harness-list.js +10 -8
- package/build/tools/harness-list.js.map +1 -1
- package/build/tools/harness-schema.d.ts.map +1 -1
- package/build/tools/harness-schema.js +5 -3
- package/build/tools/harness-schema.js.map +1 -1
- package/build/tools/harness-search.d.ts.map +1 -1
- package/build/tools/harness-search.js +10 -8
- package/build/tools/harness-search.js.map +1 -1
- package/build/tools/harness-status.js +4 -4
- package/build/tools/harness-status.js.map +1 -1
- package/build/tools/harness-update.d.ts.map +1 -1
- package/build/tools/harness-update.js +12 -9
- package/build/tools/harness-update.js.map +1 -1
- package/build/tools/input-schemas.d.ts +16 -5
- package/build/tools/input-schemas.d.ts.map +1 -1
- package/build/tools/input-schemas.js +32 -11
- package/build/tools/input-schemas.js.map +1 -1
- package/build/tools/output-schemas.d.ts +8 -0
- package/build/tools/output-schemas.d.ts.map +1 -1
- package/build/tools/output-schemas.js +10 -0
- package/build/tools/output-schemas.js.map +1 -1
- package/build/utils/canonical-resource-type.d.ts +7 -0
- package/build/utils/canonical-resource-type.d.ts.map +1 -0
- package/build/utils/canonical-resource-type.js +16 -0
- package/build/utils/canonical-resource-type.js.map +1 -0
- package/build/utils/http-auth.d.ts +2 -1
- package/build/utils/http-auth.d.ts.map +1 -1
- package/build/utils/http-auth.js +10 -2
- package/build/utils/http-auth.js.map +1 -1
- package/build/utils/oauth-auth.d.ts +1 -0
- package/build/utils/oauth-auth.d.ts.map +1 -1
- package/build/utils/oauth-auth.js +5 -0
- package/build/utils/oauth-auth.js.map +1 -1
- package/build/utils/oauth-broker.d.ts +25 -0
- package/build/utils/oauth-broker.d.ts.map +1 -0
- package/build/utils/oauth-broker.js +606 -0
- package/build/utils/oauth-broker.js.map +1 -0
- package/build/utils/oauth-proxy-redis-vault.d.ts +51 -0
- package/build/utils/oauth-proxy-redis-vault.d.ts.map +1 -0
- package/build/utils/oauth-proxy-redis-vault.js +242 -0
- package/build/utils/oauth-proxy-redis-vault.js.map +1 -0
- package/build/utils/oauth-proxy-vault.d.ts +108 -0
- package/build/utils/oauth-proxy-vault.d.ts.map +1 -0
- package/build/utils/oauth-proxy-vault.js +183 -0
- package/build/utils/oauth-proxy-vault.js.map +1 -0
- package/build/utils/oauth-proxy.d.ts +53 -0
- package/build/utils/oauth-proxy.d.ts.map +1 -0
- package/build/utils/oauth-proxy.js +493 -0
- package/build/utils/oauth-proxy.js.map +1 -0
- package/npm-shrinkwrap.json +178 -31
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-auth.js","sourceRoot":"","sources":["../../src/utils/oauth-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqD,MAAM,aAAa,CAAC;AAEjG,OAAO,GAAwB,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,GAAG,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AACvC,MAAM,iBAAiB,GAAG,CAAC,GAAG,MAAM,CAAC;AACrC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AA2BvC,SAAS,mBAAmB,CAAC,MAAmB;IAQ9C,MAAM,MAAM,GAAG,MAAM,CAAC,wBAAwB,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,0BAA0B,CAAC;IACnD,MAAM,OAAO,GAAG,MAAM,CAAC,0BAA0B,CAAC;IAClD,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;QACR,OAAO;QACP,QAAQ,EAAE,MAAM,CAAC,2BAA2B,IAAI,YAAY;QAC5D,YAAY,EAAE,MAAM,CAAC,+BAA+B,IAAI,YAAY;QACpE,MAAM,EAAE,CAAC,MAAM,CAAC,wBAAwB,IAAI,mCAAmC,CAAC;aAC7E,KAAK,CAAC,KAAK,CAAC;aACZ,MAAM,CAAC,OAAO,CAAC;KACnB,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,C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CAAC;YACH,GAAG,CAAC,SAAS,CACX,kBAAkB,EAClB,oDAAoD,WAAW,GAAG,CACnE,CAAC;YACF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,4BAA4B,EAAE;gBAC9D,EAAE,EAAE,IAAI;aACT,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Express } from "express";
|
|
2
|
+
import type { Config } from "../config.js";
|
|
3
|
+
import { type OAuthProxyRuntime } from "./oauth-proxy.js";
|
|
4
|
+
interface UpstreamMetadata {
|
|
5
|
+
issuer: string;
|
|
6
|
+
authorization_endpoint: string;
|
|
7
|
+
token_endpoint: string;
|
|
8
|
+
}
|
|
9
|
+
export interface OAuthBrokerRuntime {
|
|
10
|
+
proxy: OAuthProxyRuntime;
|
|
11
|
+
metadata?: UpstreamMetadata;
|
|
12
|
+
}
|
|
13
|
+
export declare function createOAuthBrokerRuntime(proxy: OAuthProxyRuntime): OAuthBrokerRuntime;
|
|
14
|
+
export declare function brokerIssuer(config: Config): string;
|
|
15
|
+
export declare function brokerProtectedResourceConfig(config: Config): {
|
|
16
|
+
HARNESS_MCP_OAUTH_ISSUER: string;
|
|
17
|
+
HARNESS_MCP_OAUTH_RESOURCE: string;
|
|
18
|
+
HARNESS_MCP_OAUTH_JWKS_URI: string;
|
|
19
|
+
HARNESS_MCP_OAUTH_SCOPES: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function buildAuthorizationServerMetadata(config: Config): Record<string, unknown>;
|
|
22
|
+
export declare function registerOAuthBrokerRoutes(app: Express, runtime: OAuthBrokerRuntime): void;
|
|
23
|
+
export declare function brokerRedirectAllowed(configured: string, redirectUri: string): boolean;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=oauth-broker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-broker.d.ts","sourceRoot":"","sources":["../../src/utils/oauth-broker.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,OAAO,EAA+B,MAAM,SAAS,CAAC;AAEhF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAOL,KAAK,iBAAiB,EAEvB,MAAM,kBAAkB,CAAC;AAU1B,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,MAAM,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;CACxB;AAaD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAErF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG;IAC7D,wBAAwB,EAAE,MAAM,CAAC;IACjC,0BAA0B,EAAE,MAAM,CAAC;IACnC,0BAA0B,EAAE,MAAM,CAAC;IACnC,wBAAwB,EAAE,MAAM,CAAC;CAClC,CAOA;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAaxF;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAuON;AAiTD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAItF"}
|
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { urlencoded } from "express";
|
|
3
|
+
import { createLogger } from "./logger.js";
|
|
4
|
+
import { buildHarnessAuthorizationUrl, completeHarnessAuthorization, upstreamEmailIdentifiers, oauthPkceChallenge, randomOAuthToken, upstreamSubjectsMatch, verifyUpstreamAccessToken, } from "./oauth-proxy.js";
|
|
5
|
+
const log = createLogger("oauth-broker");
|
|
6
|
+
const FORM_LIMIT = "32kb";
|
|
7
|
+
export function createOAuthBrokerRuntime(proxy) {
|
|
8
|
+
return { proxy };
|
|
9
|
+
}
|
|
10
|
+
export function brokerIssuer(config) {
|
|
11
|
+
return required(config, "HARNESS_MCP_BROKER_ISSUER").replace(/\/+$/, "");
|
|
12
|
+
}
|
|
13
|
+
export function brokerProtectedResourceConfig(config) {
|
|
14
|
+
return {
|
|
15
|
+
HARNESS_MCP_OAUTH_ISSUER: brokerIssuer(config),
|
|
16
|
+
HARNESS_MCP_OAUTH_RESOURCE: config.HARNESS_MCP_OAUTH_RESOURCE,
|
|
17
|
+
HARNESS_MCP_OAUTH_JWKS_URI: required(config, "HARNESS_MCP_UPSTREAM_JWKS_URI"),
|
|
18
|
+
HARNESS_MCP_OAUTH_SCOPES: config.HARNESS_MCP_UPSTREAM_SCOPES,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function buildAuthorizationServerMetadata(config) {
|
|
22
|
+
const issuer = brokerIssuer(config);
|
|
23
|
+
return {
|
|
24
|
+
issuer,
|
|
25
|
+
authorization_endpoint: `${issuer}/oauth/authorize`,
|
|
26
|
+
token_endpoint: `${issuer}/oauth/token`,
|
|
27
|
+
response_types_supported: ["code"],
|
|
28
|
+
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
29
|
+
code_challenge_methods_supported: ["S256"],
|
|
30
|
+
token_endpoint_auth_methods_supported: ["none"],
|
|
31
|
+
scopes_supported: configuredScopes(config),
|
|
32
|
+
authorization_response_iss_parameter_supported: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function registerOAuthBrokerRoutes(app, runtime) {
|
|
36
|
+
const oauthHits = new Map();
|
|
37
|
+
app.use("/oauth", (req, res, next) => {
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
if (oauthHits.size > 1_000) {
|
|
40
|
+
for (const [ip, value] of oauthHits) {
|
|
41
|
+
if (value.resetAt <= now)
|
|
42
|
+
oauthHits.delete(ip);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const key = req.ip ?? "unknown";
|
|
46
|
+
const current = oauthHits.get(key);
|
|
47
|
+
const entry = !current || current.resetAt <= now
|
|
48
|
+
? { count: 0, resetAt: now + 5 * 60_000 }
|
|
49
|
+
: current;
|
|
50
|
+
entry.count++;
|
|
51
|
+
oauthHits.set(key, entry);
|
|
52
|
+
if (entry.count > 120) {
|
|
53
|
+
res.status(429).json({
|
|
54
|
+
error: "temporarily_unavailable",
|
|
55
|
+
error_description: "Too many OAuth requests.",
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
next();
|
|
60
|
+
});
|
|
61
|
+
const metadata = buildAuthorizationServerMetadata(runtime.proxy.config);
|
|
62
|
+
app.get("/.well-known/oauth-authorization-server", (_req, res) => res.json(metadata));
|
|
63
|
+
app.get("/oauth/authorize", async (req, res) => {
|
|
64
|
+
try {
|
|
65
|
+
const config = runtime.proxy.config;
|
|
66
|
+
const clientId = requiredQuery(req, "client_id");
|
|
67
|
+
const redirectUri = requiredQuery(req, "redirect_uri");
|
|
68
|
+
const state = requiredQuery(req, "state");
|
|
69
|
+
const resource = requiredQuery(req, "resource");
|
|
70
|
+
const scope = requiredQuery(req, "scope");
|
|
71
|
+
const codeChallenge = requiredQuery(req, "code_challenge");
|
|
72
|
+
if (requiredQuery(req, "response_type") !== "code") {
|
|
73
|
+
throw new OAuthRequestError("unsupported_response_type", "Only response_type=code is supported.");
|
|
74
|
+
}
|
|
75
|
+
if (clientId !== config.HARNESS_MCP_BROKER_CLIENT_ID) {
|
|
76
|
+
throw new OAuthRequestError("unauthorized_client", "Unknown OAuth client.");
|
|
77
|
+
}
|
|
78
|
+
if (!brokerRedirectAllowed(config.HARNESS_MCP_BROKER_REDIRECT_URIS, redirectUri)) {
|
|
79
|
+
throw new OAuthRequestError("invalid_request", "The redirect_uri is not registered.");
|
|
80
|
+
}
|
|
81
|
+
if (resource !== config.HARNESS_MCP_OAUTH_RESOURCE) {
|
|
82
|
+
throw new OAuthRequestError("invalid_target", "The resource does not identify this MCP server.");
|
|
83
|
+
}
|
|
84
|
+
if (requiredQuery(req, "code_challenge_method") !== "S256" || !validPkceValue(codeChallenge)) {
|
|
85
|
+
throw new OAuthRequestError("invalid_request", "S256 PKCE is required.");
|
|
86
|
+
}
|
|
87
|
+
validateScopes(config, scope);
|
|
88
|
+
const id = randomOAuthToken();
|
|
89
|
+
const upstreamState = randomOAuthToken();
|
|
90
|
+
const upstreamVerifier = randomOAuthToken();
|
|
91
|
+
const upstreamNonce = randomOAuthToken();
|
|
92
|
+
const transaction = {
|
|
93
|
+
clientId,
|
|
94
|
+
redirectUri,
|
|
95
|
+
clientState: state,
|
|
96
|
+
resource,
|
|
97
|
+
scope,
|
|
98
|
+
codeChallenge,
|
|
99
|
+
upstreamState,
|
|
100
|
+
upstreamCodeVerifier: upstreamVerifier,
|
|
101
|
+
upstreamNonce,
|
|
102
|
+
expiresAt: Date.now() + config.HARNESS_MCP_BROKER_TRANSACTION_TTL_MS,
|
|
103
|
+
};
|
|
104
|
+
await runtime.proxy.vault.putBrokerTransaction(id, transaction);
|
|
105
|
+
const expiryTimer = setTimeout(() => {
|
|
106
|
+
runtime.proxy.vault.deleteBrokerTransaction(id).catch((error) => {
|
|
107
|
+
log.warn("Failed to expire OAuth broker transaction", {
|
|
108
|
+
error: errorMessage(error),
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}, config.HARNESS_MCP_BROKER_TRANSACTION_TTL_MS);
|
|
112
|
+
expiryTimer.unref();
|
|
113
|
+
const upstream = await upstreamMetadata(runtime);
|
|
114
|
+
const authorizationUrl = new URL(upstream.authorization_endpoint);
|
|
115
|
+
authorizationUrl.searchParams.set("client_id", required(config, "HARNESS_MCP_UPSTREAM_OAUTH_CLIENT_ID"));
|
|
116
|
+
authorizationUrl.searchParams.set("redirect_uri", upstreamCallbackUrl(config));
|
|
117
|
+
authorizationUrl.searchParams.set("response_type", "code");
|
|
118
|
+
authorizationUrl.searchParams.set("scope", scope);
|
|
119
|
+
authorizationUrl.searchParams.set("state", upstreamState);
|
|
120
|
+
authorizationUrl.searchParams.set("nonce", upstreamNonce);
|
|
121
|
+
authorizationUrl.searchParams.set("code_challenge", oauthPkceChallenge(upstreamVerifier));
|
|
122
|
+
authorizationUrl.searchParams.set("code_challenge_method", "S256");
|
|
123
|
+
res.redirect(authorizationUrl.toString());
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
sendAuthorizationError(res, error);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
app.get("/oauth/upstream/callback", async (req, res) => {
|
|
130
|
+
const state = queryString(req.query.state);
|
|
131
|
+
const found = state
|
|
132
|
+
? await runtime.proxy.vault.takeBrokerTransactionByUpstreamState(state)
|
|
133
|
+
: undefined;
|
|
134
|
+
if (!found) {
|
|
135
|
+
res.status(400).type("html").send(errorPage("Upstream login state is missing or expired."));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const transaction = found.transaction;
|
|
139
|
+
const providerError = queryString(req.query.error);
|
|
140
|
+
if (providerError) {
|
|
141
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, providerError, queryString(req.query.error_description));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const code = queryString(req.query.code);
|
|
145
|
+
if (!code) {
|
|
146
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, "invalid_request", "The upstream provider did not return a code.");
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const tokens = await exchangeUpstreamCode(runtime, code, transaction.upstreamCodeVerifier);
|
|
151
|
+
const identity = await verifyUpstreamAccessToken(runtime.proxy, tokens.accessToken);
|
|
152
|
+
const idClaims = await verifyUpstreamIdToken(runtime, tokens.idToken, transaction.upstreamNonce, identity.claims);
|
|
153
|
+
const linked = await runtime.proxy.vault.getRecord(identity.issuer, identity.subject);
|
|
154
|
+
const next = {
|
|
155
|
+
...transaction,
|
|
156
|
+
upstreamIssuer: identity.issuer,
|
|
157
|
+
upstreamSubject: identity.subject,
|
|
158
|
+
upstreamIdSubject: typeof idClaims.sub === "string" ? idClaims.sub : undefined,
|
|
159
|
+
upstreamLinkIdentifiers: upstreamEmailIdentifiers(runtime.proxy.config, [identity.claims, idClaims]),
|
|
160
|
+
upstreamTokens: {
|
|
161
|
+
accessToken: tokens.accessToken,
|
|
162
|
+
refreshToken: tokens.refreshToken,
|
|
163
|
+
tokenType: tokens.tokenType,
|
|
164
|
+
expiresIn: tokens.expiresIn,
|
|
165
|
+
expiresAt: tokens.expiresAt,
|
|
166
|
+
scope: tokens.scope,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
if (linked?.linked) {
|
|
170
|
+
await issueCursorAuthorizationCode(runtime, next, res);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
next.harnessState = randomOAuthToken();
|
|
174
|
+
next.harnessCodeVerifier = randomOAuthToken();
|
|
175
|
+
await runtime.proxy.vault.putBrokerTransaction(found.id, next);
|
|
176
|
+
res.redirect(buildHarnessAuthorizationUrl(runtime.proxy.config, next.harnessState, next.harnessCodeVerifier, harnessCallbackUrl(runtime.proxy.config)));
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
log.warn("Upstream OAuth callback rejected", { error: errorMessage(error) });
|
|
180
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, "access_denied", "Upstream login could not be verified.");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
app.get("/oauth/harnessid/callback", async (req, res) => {
|
|
184
|
+
const state = queryString(req.query.state);
|
|
185
|
+
const found = state
|
|
186
|
+
? await runtime.proxy.vault.takeBrokerTransactionByHarnessState(state)
|
|
187
|
+
: undefined;
|
|
188
|
+
if (!found) {
|
|
189
|
+
res.status(400).type("html").send(errorPage("HarnessID login state is missing or expired."));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const transaction = found.transaction;
|
|
193
|
+
const providerError = queryString(req.query.error);
|
|
194
|
+
if (providerError) {
|
|
195
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, providerError, queryString(req.query.error_description));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const code = queryString(req.query.code);
|
|
199
|
+
if (!code
|
|
200
|
+
|| !transaction.upstreamSubject
|
|
201
|
+
|| !transaction.upstreamTokens
|
|
202
|
+
|| !transaction.harnessCodeVerifier) {
|
|
203
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, "invalid_request", "The authorization transaction is incomplete.");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
await completeHarnessAuthorization(runtime.proxy, transaction.upstreamSubject, code, transaction.harnessCodeVerifier, harnessCallbackUrl(runtime.proxy.config), [
|
|
208
|
+
...(transaction.upstreamIdSubject ? [transaction.upstreamIdSubject] : []),
|
|
209
|
+
...(transaction.upstreamLinkIdentifiers ?? []),
|
|
210
|
+
]);
|
|
211
|
+
await issueCursorAuthorizationCode(runtime, transaction, res);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
log.warn("HarnessID broker callback rejected", { error: errorMessage(error) });
|
|
215
|
+
redirectOAuthError(runtime.proxy.config, res, transaction, "access_denied", "HarnessID linking could not be verified.");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
app.post("/oauth/token", urlencoded({ extended: false, limit: FORM_LIMIT }), async (req, res) => {
|
|
219
|
+
res.setHeader("Cache-Control", "no-store");
|
|
220
|
+
res.setHeader("Pragma", "no-cache");
|
|
221
|
+
try {
|
|
222
|
+
const grantType = formString(req, "grant_type");
|
|
223
|
+
if (grantType === "authorization_code") {
|
|
224
|
+
await redeemAuthorizationCode(runtime, req, res);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (grantType === "refresh_token") {
|
|
228
|
+
await refreshUpstreamToken(runtime, req, res);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
throw new OAuthRequestError("unsupported_grant_type", "Unsupported grant_type.");
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
sendTokenError(res, error);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async function redeemAuthorizationCode(runtime, req, res) {
|
|
239
|
+
validateTokenClient(runtime.proxy.config, req);
|
|
240
|
+
const rawCode = requiredForm(req, "code");
|
|
241
|
+
const stored = await runtime.proxy.vault.takeBrokerCode(codeDigest(rawCode));
|
|
242
|
+
if (!stored)
|
|
243
|
+
throw new OAuthRequestError("invalid_grant", "Authorization code is invalid or expired.");
|
|
244
|
+
if (requiredForm(req, "redirect_uri") !== stored.redirectUri
|
|
245
|
+
|| optionalForm(req, "resource") !== stored.resource
|
|
246
|
+
|| !pkceMatches(requiredForm(req, "code_verifier"), stored.codeChallenge)) {
|
|
247
|
+
throw new OAuthRequestError("invalid_grant", "Authorization code binding validation failed.");
|
|
248
|
+
}
|
|
249
|
+
const brokerRefresh = await issueBrokerRefresh(runtime, {
|
|
250
|
+
clientId: stored.clientId,
|
|
251
|
+
upstreamIssuer: stored.upstreamIssuer,
|
|
252
|
+
upstreamSubject: stored.upstreamSubject,
|
|
253
|
+
upstreamRefreshToken: stored.upstreamTokens.refreshToken,
|
|
254
|
+
scope: stored.scope,
|
|
255
|
+
});
|
|
256
|
+
sendClientTokens(res, stored.upstreamTokens, brokerRefresh);
|
|
257
|
+
}
|
|
258
|
+
async function refreshUpstreamToken(runtime, req, res) {
|
|
259
|
+
validateTokenClient(runtime.proxy.config, req);
|
|
260
|
+
const refreshToken = requiredForm(req, "refresh_token");
|
|
261
|
+
const requestedScope = optionalForm(req, "scope");
|
|
262
|
+
if (requestedScope)
|
|
263
|
+
validateScopes(runtime.proxy.config, requestedScope);
|
|
264
|
+
const digest = codeDigest(refreshToken);
|
|
265
|
+
const exchange = async () => {
|
|
266
|
+
const stored = await runtime.proxy.vault.getBrokerRefresh(digest);
|
|
267
|
+
if (!stored || stored.clientId !== runtime.proxy.config.HARNESS_MCP_BROKER_CLIENT_ID) {
|
|
268
|
+
throw new OAuthRequestError("invalid_grant", "Refresh token is invalid.");
|
|
269
|
+
}
|
|
270
|
+
const upstream = await upstreamMetadata(runtime);
|
|
271
|
+
const response = await postUpstreamToken(runtime, upstream.token_endpoint, {
|
|
272
|
+
grant_type: "refresh_token",
|
|
273
|
+
refresh_token: stored.upstreamRefreshToken,
|
|
274
|
+
scope: requestedScope ?? stored.scope,
|
|
275
|
+
});
|
|
276
|
+
await runtime.proxy.vault.deleteBrokerRefresh(digest);
|
|
277
|
+
const brokerRefresh = await issueBrokerRefresh(runtime, {
|
|
278
|
+
clientId: stored.clientId,
|
|
279
|
+
upstreamIssuer: stored.upstreamIssuer,
|
|
280
|
+
upstreamSubject: stored.upstreamSubject,
|
|
281
|
+
upstreamRefreshToken: response.refreshToken ?? stored.upstreamRefreshToken,
|
|
282
|
+
scope: requestedScope ?? stored.scope,
|
|
283
|
+
});
|
|
284
|
+
sendClientTokens(res, response, brokerRefresh);
|
|
285
|
+
};
|
|
286
|
+
if (runtime.proxy.vault.withLock) {
|
|
287
|
+
await runtime.proxy.vault.withLock(`broker-refresh\n${digest}`, exchange);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
await exchange();
|
|
291
|
+
}
|
|
292
|
+
async function issueBrokerRefresh(runtime, grant) {
|
|
293
|
+
if (!grant.upstreamRefreshToken)
|
|
294
|
+
return undefined;
|
|
295
|
+
const token = randomOAuthToken();
|
|
296
|
+
await runtime.proxy.vault.putBrokerRefresh(codeDigest(token), {
|
|
297
|
+
clientId: grant.clientId,
|
|
298
|
+
upstreamIssuer: grant.upstreamIssuer,
|
|
299
|
+
upstreamSubject: grant.upstreamSubject,
|
|
300
|
+
upstreamRefreshToken: grant.upstreamRefreshToken,
|
|
301
|
+
scope: grant.scope,
|
|
302
|
+
});
|
|
303
|
+
return token;
|
|
304
|
+
}
|
|
305
|
+
async function exchangeUpstreamCode(runtime, code, verifier) {
|
|
306
|
+
const upstream = await upstreamMetadata(runtime);
|
|
307
|
+
return postUpstreamToken(runtime, upstream.token_endpoint, {
|
|
308
|
+
grant_type: "authorization_code",
|
|
309
|
+
code,
|
|
310
|
+
redirect_uri: upstreamCallbackUrl(runtime.proxy.config),
|
|
311
|
+
code_verifier: verifier,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async function postUpstreamToken(runtime, endpoint, fields) {
|
|
315
|
+
const config = runtime.proxy.config;
|
|
316
|
+
const clientId = required(config, "HARNESS_MCP_UPSTREAM_OAUTH_CLIENT_ID");
|
|
317
|
+
const clientSecret = required(config, "HARNESS_MCP_UPSTREAM_OAUTH_CLIENT_SECRET");
|
|
318
|
+
const response = await runtime.proxy.fetchImpl(endpoint, {
|
|
319
|
+
method: "POST",
|
|
320
|
+
headers: {
|
|
321
|
+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
322
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
323
|
+
Accept: "application/json",
|
|
324
|
+
},
|
|
325
|
+
body: new URLSearchParams(fields),
|
|
326
|
+
signal: AbortSignal.timeout(15_000),
|
|
327
|
+
});
|
|
328
|
+
const body = await response.json();
|
|
329
|
+
if (!response.ok || typeof body.access_token !== "string") {
|
|
330
|
+
log.warn("Upstream token response rejected", {
|
|
331
|
+
grantType: fields.grant_type,
|
|
332
|
+
status: response.status,
|
|
333
|
+
oauthError: typeof body.error === "string" ? body.error : undefined,
|
|
334
|
+
});
|
|
335
|
+
throw new OAuthRequestError(typeof body.error === "string" ? body.error : "invalid_grant", "Upstream token request was rejected.");
|
|
336
|
+
}
|
|
337
|
+
log.info("Upstream token response", {
|
|
338
|
+
grantType: fields.grant_type,
|
|
339
|
+
status: response.status,
|
|
340
|
+
hasRefreshToken: typeof body.refresh_token === "string",
|
|
341
|
+
expiresIn: body.expires_in,
|
|
342
|
+
});
|
|
343
|
+
const expiresIn = typeof body.expires_in === "number" ? body.expires_in : undefined;
|
|
344
|
+
return {
|
|
345
|
+
accessToken: body.access_token,
|
|
346
|
+
refreshToken: typeof body.refresh_token === "string" ? body.refresh_token : undefined,
|
|
347
|
+
idToken: typeof body.id_token === "string" ? body.id_token : undefined,
|
|
348
|
+
tokenType: typeof body.token_type === "string" ? body.token_type : "Bearer",
|
|
349
|
+
expiresIn,
|
|
350
|
+
expiresAt: expiresIn === undefined ? undefined : Date.now() + expiresIn * 1000,
|
|
351
|
+
scope: typeof body.scope === "string" ? body.scope : undefined,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async function verifyUpstreamIdToken(runtime, idToken, nonce, accessClaims) {
|
|
355
|
+
if (!idToken)
|
|
356
|
+
throw new Error("Upstream token response did not include id_token.");
|
|
357
|
+
const claims = await runtime.proxy.upstreamIdVerifier.verify(idToken);
|
|
358
|
+
if (claims.nonce !== nonce) {
|
|
359
|
+
throw new Error("Upstream ID token nonce does not match the authorization transaction.");
|
|
360
|
+
}
|
|
361
|
+
if (!upstreamSubjectsMatch(accessClaims, claims)) {
|
|
362
|
+
log.warn("Upstream identity claims did not match", {
|
|
363
|
+
accessClaims: Object.keys(accessClaims).sort(),
|
|
364
|
+
idClaims: Object.keys(claims).sort(),
|
|
365
|
+
});
|
|
366
|
+
throw new Error("Upstream ID token subject does not match the access token subject or verified email.");
|
|
367
|
+
}
|
|
368
|
+
return claims;
|
|
369
|
+
}
|
|
370
|
+
async function issueCursorAuthorizationCode(runtime, transaction, res) {
|
|
371
|
+
if (!transaction.upstreamIssuer
|
|
372
|
+
|| !transaction.upstreamSubject
|
|
373
|
+
|| !transaction.upstreamTokens) {
|
|
374
|
+
throw new Error("Upstream authorization is incomplete.");
|
|
375
|
+
}
|
|
376
|
+
const rawCode = randomOAuthToken();
|
|
377
|
+
const code = {
|
|
378
|
+
clientId: transaction.clientId,
|
|
379
|
+
redirectUri: transaction.redirectUri,
|
|
380
|
+
resource: transaction.resource,
|
|
381
|
+
scope: transaction.scope,
|
|
382
|
+
codeChallenge: transaction.codeChallenge,
|
|
383
|
+
upstreamIssuer: transaction.upstreamIssuer,
|
|
384
|
+
upstreamSubject: transaction.upstreamSubject,
|
|
385
|
+
upstreamTokens: transaction.upstreamTokens,
|
|
386
|
+
expiresAt: Date.now() + runtime.proxy.config.HARNESS_MCP_BROKER_CODE_TTL_MS,
|
|
387
|
+
};
|
|
388
|
+
const digest = codeDigest(rawCode);
|
|
389
|
+
await runtime.proxy.vault.putBrokerCode(digest, code);
|
|
390
|
+
const expiryTimer = setTimeout(() => {
|
|
391
|
+
runtime.proxy.vault.takeBrokerCode(digest).catch((error) => {
|
|
392
|
+
log.warn("Failed to expire OAuth broker authorization code", {
|
|
393
|
+
error: errorMessage(error),
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}, runtime.proxy.config.HARNESS_MCP_BROKER_CODE_TTL_MS);
|
|
397
|
+
expiryTimer.unref();
|
|
398
|
+
const callback = new URL(transaction.redirectUri);
|
|
399
|
+
callback.searchParams.set("code", rawCode);
|
|
400
|
+
callback.searchParams.set("state", transaction.clientState);
|
|
401
|
+
callback.searchParams.set("iss", brokerIssuer(runtime.proxy.config));
|
|
402
|
+
res.redirect(callback.toString());
|
|
403
|
+
}
|
|
404
|
+
async function upstreamMetadata(runtime) {
|
|
405
|
+
if (runtime.metadata)
|
|
406
|
+
return runtime.metadata;
|
|
407
|
+
const response = await runtime.proxy.fetchImpl(required(runtime.proxy.config, "HARNESS_MCP_UPSTREAM_DISCOVERY_URI"), {
|
|
408
|
+
headers: { Accept: "application/json" },
|
|
409
|
+
signal: AbortSignal.timeout(10_000),
|
|
410
|
+
});
|
|
411
|
+
if (!response.ok) {
|
|
412
|
+
throw new Error(`Upstream discovery returned HTTP ${response.status}.`);
|
|
413
|
+
}
|
|
414
|
+
const value = await response.json();
|
|
415
|
+
const expectedIssuer = required(runtime.proxy.config, "HARNESS_MCP_UPSTREAM_ISSUER").replace(/\/+$/, "");
|
|
416
|
+
if (value.issuer?.replace(/\/+$/, "") !== expectedIssuer
|
|
417
|
+
|| typeof value.authorization_endpoint !== "string"
|
|
418
|
+
|| typeof value.token_endpoint !== "string") {
|
|
419
|
+
throw new Error("Upstream discovery metadata is incomplete or has the wrong issuer.");
|
|
420
|
+
}
|
|
421
|
+
runtime.metadata = {
|
|
422
|
+
issuer: expectedIssuer,
|
|
423
|
+
authorization_endpoint: pinnedIssuerEndpoint(value.authorization_endpoint, expectedIssuer),
|
|
424
|
+
token_endpoint: pinnedIssuerEndpoint(value.token_endpoint, expectedIssuer),
|
|
425
|
+
};
|
|
426
|
+
return runtime.metadata;
|
|
427
|
+
}
|
|
428
|
+
function pinnedIssuerEndpoint(endpoint, issuer) {
|
|
429
|
+
let url;
|
|
430
|
+
let issuerUrl;
|
|
431
|
+
try {
|
|
432
|
+
url = new URL(endpoint);
|
|
433
|
+
issuerUrl = new URL(issuer);
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
throw new Error("Upstream discovery endpoint is not a valid URL.");
|
|
437
|
+
}
|
|
438
|
+
if (url.protocol !== "https:" || url.origin !== issuerUrl.origin) {
|
|
439
|
+
throw new Error("Upstream discovery endpoints must be https on the issuer origin.");
|
|
440
|
+
}
|
|
441
|
+
return url.toString();
|
|
442
|
+
}
|
|
443
|
+
function sendClientTokens(res, tokens, refreshToken) {
|
|
444
|
+
sendUpstreamTokens(res, { ...tokens, refreshToken });
|
|
445
|
+
}
|
|
446
|
+
function sendUpstreamTokens(res, tokens) {
|
|
447
|
+
const expiresIn = tokens.expiresAt === undefined
|
|
448
|
+
? tokens.expiresIn
|
|
449
|
+
: Math.max(1, Math.floor((tokens.expiresAt - Date.now()) / 1000));
|
|
450
|
+
res.json({
|
|
451
|
+
access_token: tokens.accessToken,
|
|
452
|
+
token_type: tokens.tokenType,
|
|
453
|
+
...(tokens.refreshToken ? { refresh_token: tokens.refreshToken } : {}),
|
|
454
|
+
...(expiresIn !== undefined ? { expires_in: expiresIn } : {}),
|
|
455
|
+
...(tokens.scope ? { scope: tokens.scope } : {}),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
function validateTokenClient(config, req) {
|
|
459
|
+
if (requiredForm(req, "client_id") !== config.HARNESS_MCP_BROKER_CLIENT_ID) {
|
|
460
|
+
throw new OAuthRequestError("invalid_client", "Unknown OAuth client.");
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function validateScopes(config, scope) {
|
|
464
|
+
const allowed = new Set(configuredScopes(config));
|
|
465
|
+
const requested = scope.split(/\s+/).filter(Boolean);
|
|
466
|
+
if (requested.length === 0 || requested.some((value) => !allowed.has(value))) {
|
|
467
|
+
throw new OAuthRequestError("invalid_scope", "One or more requested scopes are not allowed.");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function configuredScopes(config) {
|
|
471
|
+
return config.HARNESS_MCP_UPSTREAM_SCOPES.split(/\s+/).filter(Boolean);
|
|
472
|
+
}
|
|
473
|
+
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
474
|
+
const BLOCKED_REDIRECT_SCHEMES = new Set([
|
|
475
|
+
"javascript",
|
|
476
|
+
"data",
|
|
477
|
+
"file",
|
|
478
|
+
"blob",
|
|
479
|
+
"vbscript",
|
|
480
|
+
"about",
|
|
481
|
+
]);
|
|
482
|
+
export function brokerRedirectAllowed(configured, redirectUri) {
|
|
483
|
+
const entries = configured.split(",").map((value) => value.trim()).filter(Boolean);
|
|
484
|
+
if (entries.includes(redirectUri))
|
|
485
|
+
return true;
|
|
486
|
+
return entries.includes("*") && ideRedirectAllowed(redirectUri);
|
|
487
|
+
}
|
|
488
|
+
function ideRedirectAllowed(redirectUri) {
|
|
489
|
+
let url;
|
|
490
|
+
try {
|
|
491
|
+
url = new URL(redirectUri);
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
if (url.username || url.password)
|
|
497
|
+
return false;
|
|
498
|
+
const scheme = url.protocol.replace(/:$/, "").toLowerCase();
|
|
499
|
+
if (!/^[a-z][a-z0-9+.-]*$/.test(scheme) || BLOCKED_REDIRECT_SCHEMES.has(scheme)) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
if (scheme === "http" || scheme === "https") {
|
|
503
|
+
return LOOPBACK_HOSTS.has(url.hostname.toLowerCase());
|
|
504
|
+
}
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
function upstreamCallbackUrl(config) {
|
|
508
|
+
return `${brokerIssuer(config)}/oauth/upstream/callback`;
|
|
509
|
+
}
|
|
510
|
+
function harnessCallbackUrl(config) {
|
|
511
|
+
return `${brokerIssuer(config)}/oauth/harnessid/callback`;
|
|
512
|
+
}
|
|
513
|
+
function redirectOAuthError(config, res, transaction, error, description) {
|
|
514
|
+
const callback = new URL(transaction.redirectUri);
|
|
515
|
+
callback.searchParams.set("error", error);
|
|
516
|
+
if (description)
|
|
517
|
+
callback.searchParams.set("error_description", description);
|
|
518
|
+
callback.searchParams.set("state", transaction.clientState);
|
|
519
|
+
callback.searchParams.set("iss", brokerIssuer(config));
|
|
520
|
+
res.redirect(callback.toString());
|
|
521
|
+
}
|
|
522
|
+
function sendAuthorizationError(res, error) {
|
|
523
|
+
const requestError = oauthRequestError(error);
|
|
524
|
+
res.status(400).json({
|
|
525
|
+
error: requestError.code,
|
|
526
|
+
error_description: requestError.message,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function sendTokenError(res, error) {
|
|
530
|
+
const requestError = oauthRequestError(error);
|
|
531
|
+
const status = requestError.code === "invalid_client" ? 401 : 400;
|
|
532
|
+
res.status(status).json({
|
|
533
|
+
error: requestError.code,
|
|
534
|
+
error_description: requestError.message,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
class OAuthRequestError extends Error {
|
|
538
|
+
code;
|
|
539
|
+
constructor(code, message) {
|
|
540
|
+
super(message);
|
|
541
|
+
this.code = code;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function oauthRequestError(error) {
|
|
545
|
+
return error instanceof OAuthRequestError
|
|
546
|
+
? error
|
|
547
|
+
: new OAuthRequestError("server_error", "The authorization server could not complete the request.");
|
|
548
|
+
}
|
|
549
|
+
function required(config, name) {
|
|
550
|
+
const value = config[name];
|
|
551
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
552
|
+
throw new Error(`OAuth broker configuration is missing ${String(name)}.`);
|
|
553
|
+
}
|
|
554
|
+
return value;
|
|
555
|
+
}
|
|
556
|
+
function requiredQuery(req, name) {
|
|
557
|
+
const value = queryString(req.query[name]);
|
|
558
|
+
if (!value)
|
|
559
|
+
throw new OAuthRequestError("invalid_request", `Missing ${name}.`);
|
|
560
|
+
return value;
|
|
561
|
+
}
|
|
562
|
+
function queryString(value) {
|
|
563
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
564
|
+
}
|
|
565
|
+
function formString(req, name) {
|
|
566
|
+
const value = req.body?.[name];
|
|
567
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
568
|
+
}
|
|
569
|
+
function optionalForm(req, name) {
|
|
570
|
+
return formString(req, name);
|
|
571
|
+
}
|
|
572
|
+
function requiredForm(req, name) {
|
|
573
|
+
const value = formString(req, name);
|
|
574
|
+
if (!value)
|
|
575
|
+
throw new OAuthRequestError("invalid_request", `Missing ${name}.`);
|
|
576
|
+
return value;
|
|
577
|
+
}
|
|
578
|
+
function validPkceValue(value) {
|
|
579
|
+
return /^[A-Za-z0-9._~-]{43,128}$/.test(value);
|
|
580
|
+
}
|
|
581
|
+
function pkceMatches(verifier, expectedChallenge) {
|
|
582
|
+
if (!validPkceValue(verifier))
|
|
583
|
+
return false;
|
|
584
|
+
const actual = Buffer.from(oauthPkceChallenge(verifier));
|
|
585
|
+
const expected = Buffer.from(expectedChallenge);
|
|
586
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
587
|
+
}
|
|
588
|
+
function codeDigest(code) {
|
|
589
|
+
return createHash("sha256").update(code).digest("base64url");
|
|
590
|
+
}
|
|
591
|
+
function errorMessage(error) {
|
|
592
|
+
return error instanceof Error ? error.message : String(error);
|
|
593
|
+
}
|
|
594
|
+
function errorPage(message) {
|
|
595
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>OAuth login failed</title></head><body><h1>OAuth login failed</h1><p>${escapeHtml(message)}</p></body></html>`;
|
|
596
|
+
}
|
|
597
|
+
function escapeHtml(value) {
|
|
598
|
+
return value.replace(/[&<>"']/g, (char) => ({
|
|
599
|
+
"&": "&",
|
|
600
|
+
"<": "<",
|
|
601
|
+
">": ">",
|
|
602
|
+
"\"": """,
|
|
603
|
+
"'": "'",
|
|
604
|
+
}[char] ?? char));
|
|
605
|
+
}
|
|
606
|
+
//# sourceMappingURL=oauth-broker.js.map
|