@herbertgao/pi-extensions 2026.9.11 → 2026.9.13
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 +4 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +8 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +5 -4
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +39 -16
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +21 -4
- package/node_modules/@narumitw/pi-btw/dist/index.ts +1668 -958
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
- package/node_modules/@narumitw/pi-btw/docs/workflows.md +10 -2
- package/node_modules/@narumitw/pi-btw/package.json +1 -1
- package/node_modules/@narumitw/pi-btw/src/btw.ts +17 -79
- package/node_modules/@narumitw/pi-btw/src/conversation-context.ts +74 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +196 -7
- package/node_modules/@narumitw/pi-btw/src/main-thread-updates.ts +40 -0
- package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
- package/node_modules/@narumitw/pi-btw/src/settings.ts +49 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +9 -1
- package/node_modules/@narumitw/pi-btw/src/workspace-layout.ts +559 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +62 -0
- package/node_modules/pi-mcp-adapter/README.md +75 -7
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +193 -0
- package/node_modules/pi-mcp-adapter/cli.js +56 -5
- package/node_modules/pi-mcp-adapter/commands.ts +96 -5
- package/node_modules/pi-mcp-adapter/config.ts +73 -6
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +22 -28
- package/node_modules/pi-mcp-adapter/direct-tools.ts +13 -5
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js +36 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +194 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +5 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +75 -6
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +18 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +316 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +131 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js +278 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +8 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +340 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +77 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +22 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +55 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +56 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +410 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +51 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js +131 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +103 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +118 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +1098 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +168 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +1117 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +7 -140
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +53 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +441 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +148 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +689 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +166 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +102 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +369 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +95 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +242 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +2 -11
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +505 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +10 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +312 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +13 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +97 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +203 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +11 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +172 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +157 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +1743 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +34 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +140 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +142 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +73 -0
- package/node_modules/pi-mcp-adapter/dist/state.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/state.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +36 -0
- package/node_modules/pi-mcp-adapter/dist/types.js +18 -0
- package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +219 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js +13 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +1 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +29 -19
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +85 -0
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +34 -0
- package/node_modules/pi-mcp-adapter/index.ts +129 -6
- package/node_modules/pi-mcp-adapter/init.ts +6 -19
- package/node_modules/pi-mcp-adapter/jev-client.ts +273 -0
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +53 -0
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +79 -0
- package/node_modules/pi-mcp-adapter/lifecycle.ts +14 -3
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +7 -142
- package/node_modules/pi-mcp-adapter/mcp-code.ts +119 -11
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +4 -0
- package/node_modules/pi-mcp-adapter/mcp-references.ts +5 -3
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +5 -0
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +467 -0
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +2 -13
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +1 -1
- package/node_modules/pi-mcp-adapter/package.json +17 -9
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +319 -166
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +6 -3
- package/node_modules/pi-mcp-adapter/search-ranking.ts +38 -7
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +170 -0
- package/node_modules/pi-mcp-adapter/semantic-search.ts +186 -0
- package/node_modules/pi-mcp-adapter/server-manager.ts +293 -50
- package/node_modules/pi-mcp-adapter/session-approvals.ts +14 -0
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +2 -0
- package/node_modules/pi-mcp-adapter/state.ts +3 -1
- package/node_modules/pi-mcp-adapter/tool-approval.ts +26 -4
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +6 -14
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +8 -6
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +4 -1
- package/node_modules/pi-mcp-adapter/types.ts +53 -0
- package/node_modules/pi-mcp-adapter/ui-server.ts +17 -9
- package/node_modules/pi-mcp-adapter/utils.ts +16 -0
- package/node_modules/pi-multi-account/CHANGELOG.md +23 -0
- package/node_modules/pi-multi-account/README.md +38 -11
- package/node_modules/pi-multi-account/index.ts +371 -96
- package/node_modules/pi-multi-account/package.json +5 -4
- package/node_modules/pi-multi-account/provider-payload-stream.ts +36 -28
- package/node_modules/pi-multi-account/usage.ts +31 -2
- package/node_modules/pi-typesafe/README.md +3 -1
- package/node_modules/pi-typesafe/dist/auth.d.ts +10 -3
- package/node_modules/pi-typesafe/dist/auth.js +13 -7
- package/node_modules/pi-typesafe/dist/backends.d.ts +31 -0
- package/node_modules/pi-typesafe/dist/backends.js +33 -0
- package/node_modules/pi-typesafe/dist/client.d.ts +3 -9
- package/node_modules/pi-typesafe/dist/client.js +63 -39
- package/node_modules/pi-typesafe/dist/credentials.d.ts +11 -5
- package/node_modules/pi-typesafe/dist/credentials.js +15 -8
- package/node_modules/pi-typesafe/dist/extension.js +4 -1
- package/node_modules/pi-typesafe/dist/index.d.ts +1 -1
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/login.d.ts +13 -7
- package/node_modules/pi-typesafe/dist/login.js +17 -8
- package/node_modules/pi-typesafe/dist/schema.js +19 -13
- package/node_modules/pi-typesafe/package.json +1 -1
- package/package.json +11 -10
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP OAuth Callback Server
|
|
3
|
+
*
|
|
4
|
+
* HTTP server that handles OAuth callbacks from the authorization server.
|
|
5
|
+
* Uses Node.js http module for compatibility.
|
|
6
|
+
*/
|
|
7
|
+
import { createServer } from "http";
|
|
8
|
+
import { getAppName } from "./agent-dir.js";
|
|
9
|
+
import { DEFAULT_OAUTH_CALLBACK_PATH, getConfiguredOAuthCallbackPort, getOAuthCallbackPath, getOAuthCallbackPort, setOAuthCallbackPath, setOAuthCallbackPort, } from "./mcp-oauth-provider.js";
|
|
10
|
+
// HTML templates for callback responses.
|
|
11
|
+
//
|
|
12
|
+
// These pages are served from localhost during OAuth and are the last thing a
|
|
13
|
+
// user sees before returning to their terminal, so they are self-contained: no
|
|
14
|
+
// webfonts, no external assets, nothing that needs the network. They also name
|
|
15
|
+
// the host rather than hardcoding "Pi", so a distribution that rebrands pi
|
|
16
|
+
// (arc, tau, …) does not send its users back to an app they are not running.
|
|
17
|
+
/** Shared chrome: system fonts, a centred card, and light/dark support. */
|
|
18
|
+
const PAGE_STYLE = `
|
|
19
|
+
:root { color-scheme: light dark; }
|
|
20
|
+
* { box-sizing: border-box; }
|
|
21
|
+
body {
|
|
22
|
+
margin: 0;
|
|
23
|
+
min-height: 100vh;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
padding: 24px;
|
|
28
|
+
font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
29
|
+
background: #0f1117;
|
|
30
|
+
color: #e6e8ee;
|
|
31
|
+
}
|
|
32
|
+
.card {
|
|
33
|
+
width: 100%;
|
|
34
|
+
max-width: 26rem;
|
|
35
|
+
padding: 2.5rem 2rem;
|
|
36
|
+
text-align: center;
|
|
37
|
+
background: #161922;
|
|
38
|
+
border: 1px solid #242938;
|
|
39
|
+
border-radius: 14px;
|
|
40
|
+
box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.25);
|
|
41
|
+
}
|
|
42
|
+
.badge {
|
|
43
|
+
width: 3rem; height: 3rem;
|
|
44
|
+
margin: 0 auto 1.25rem;
|
|
45
|
+
display: grid; place-items: center;
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
}
|
|
48
|
+
.badge svg { width: 1.5rem; height: 1.5rem; display: block; }
|
|
49
|
+
.ok { background: rgba(74,222,128,.12); color: #4ade80; }
|
|
50
|
+
.bad { background: rgba(248,113,113,.12); color: #f87171; }
|
|
51
|
+
h1 { margin: 0 0 .5rem; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; }
|
|
52
|
+
p { margin: 0; color: #9aa1b1; }
|
|
53
|
+
.app { color: #e6e8ee; font-weight: 500; }
|
|
54
|
+
.hint { margin-top: 1.25rem; font-size: .8125rem; color: #6b7280; }
|
|
55
|
+
code {
|
|
56
|
+
display: block;
|
|
57
|
+
margin-top: 1.25rem;
|
|
58
|
+
padding: .75rem .875rem;
|
|
59
|
+
text-align: left;
|
|
60
|
+
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
61
|
+
color: #fca5a5;
|
|
62
|
+
background: rgba(248,113,113,.08);
|
|
63
|
+
border: 1px solid rgba(248,113,113,.2);
|
|
64
|
+
border-radius: 8px;
|
|
65
|
+
overflow-wrap: anywhere;
|
|
66
|
+
}
|
|
67
|
+
@media (prefers-color-scheme: light) {
|
|
68
|
+
body { background: #f6f7f9; color: #121620; }
|
|
69
|
+
.card { background: #fff; border-color: #e4e7ee; }
|
|
70
|
+
p { color: #5b6474; }
|
|
71
|
+
.app { color: #121620; }
|
|
72
|
+
.hint { color: #8b93a3; }
|
|
73
|
+
}`;
|
|
74
|
+
const CHECK_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>';
|
|
75
|
+
const CROSS_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>';
|
|
76
|
+
function page(options) {
|
|
77
|
+
return `<!DOCTYPE html>
|
|
78
|
+
<html lang="en">
|
|
79
|
+
<head>
|
|
80
|
+
<meta charset="utf-8">
|
|
81
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
82
|
+
<title>${options.title}</title>
|
|
83
|
+
<style>${PAGE_STYLE}
|
|
84
|
+
</style>
|
|
85
|
+
</head>
|
|
86
|
+
<body>
|
|
87
|
+
<main class="card">
|
|
88
|
+
<div class="badge ${options.tone}">${options.icon}</div>
|
|
89
|
+
<h1>${options.heading}</h1>
|
|
90
|
+
<p>${options.body}</p>
|
|
91
|
+
${options.extra ?? ""}
|
|
92
|
+
</main>
|
|
93
|
+
${options.autoClose ? " <script>setTimeout(() => window.close(), 2000);</script>\n" : ""}</body>
|
|
94
|
+
</html>`;
|
|
95
|
+
}
|
|
96
|
+
function escapeHtml(value) {
|
|
97
|
+
return value
|
|
98
|
+
.replace(/&/g, "&")
|
|
99
|
+
.replace(/</g, "<")
|
|
100
|
+
.replace(/>/g, ">")
|
|
101
|
+
.replace(/"/g, """)
|
|
102
|
+
.replace(/'/g, "'");
|
|
103
|
+
}
|
|
104
|
+
/** Built per request so a host that sets PI_PACKAGE_DIR late is still named right. */
|
|
105
|
+
function htmlSuccess() {
|
|
106
|
+
const app = escapeHtml(getAppName());
|
|
107
|
+
return page({
|
|
108
|
+
title: `${app} — Authorization Successful`,
|
|
109
|
+
heading: "Authorization Successful",
|
|
110
|
+
body: `You can close this window and return to <span class="app">${app}</span>.`,
|
|
111
|
+
icon: CHECK_ICON,
|
|
112
|
+
tone: "ok",
|
|
113
|
+
autoClose: true,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function htmlManualSuccess() {
|
|
117
|
+
const app = escapeHtml(getAppName());
|
|
118
|
+
return page({
|
|
119
|
+
title: `${app} — Authorization Received`,
|
|
120
|
+
heading: "Authorization Received",
|
|
121
|
+
body: `Copy the full callback URL from your browser address bar and paste it back into <span class="app">${app}</span> with auth-complete.`,
|
|
122
|
+
icon: CHECK_ICON,
|
|
123
|
+
tone: "ok",
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function htmlError(error) {
|
|
127
|
+
const app = escapeHtml(getAppName());
|
|
128
|
+
return page({
|
|
129
|
+
title: `${app} — Authorization Failed`,
|
|
130
|
+
heading: "Authorization Failed",
|
|
131
|
+
body: `Something went wrong during authorization. You can close this window and try again from <span class="app">${app}</span>.`,
|
|
132
|
+
icon: CROSS_ICON,
|
|
133
|
+
tone: "bad",
|
|
134
|
+
extra: `<code>${escapeHtml(error)}</code>`,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Server singleton state */
|
|
138
|
+
let server;
|
|
139
|
+
let bindingPromise;
|
|
140
|
+
let stoppingPromise;
|
|
141
|
+
let restartableStoppingPromise;
|
|
142
|
+
let callbackGeneration = 0;
|
|
143
|
+
const pendingAuths = new Map();
|
|
144
|
+
const reservedAuthStates = new Set();
|
|
145
|
+
/** Timeout for callback completion (5 minutes) */
|
|
146
|
+
const CALLBACK_TIMEOUT_MS = 5 * 60 * 1000;
|
|
147
|
+
const DEFAULT_OAUTH_CALLBACK_HOST = "localhost";
|
|
148
|
+
let callbackServerHost = DEFAULT_OAUTH_CALLBACK_HOST;
|
|
149
|
+
/**
|
|
150
|
+
* Handle incoming HTTP requests to the callback server.
|
|
151
|
+
*/
|
|
152
|
+
function handleRequest(req, res) {
|
|
153
|
+
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
|
154
|
+
// Only handle the callback path
|
|
155
|
+
if (url.pathname !== getOAuthCallbackPath()) {
|
|
156
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
157
|
+
res.end("Not found");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const code = url.searchParams.get("code");
|
|
161
|
+
const iss = url.searchParams.get("iss");
|
|
162
|
+
const state = url.searchParams.get("state");
|
|
163
|
+
const error = url.searchParams.get("error");
|
|
164
|
+
const errorDescription = url.searchParams.get("error_description");
|
|
165
|
+
// Enforce state parameter presence for CSRF protection
|
|
166
|
+
if (!state) {
|
|
167
|
+
const errorMsg = "Missing required state parameter - potential CSRF attack";
|
|
168
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
169
|
+
res.end(htmlError(errorMsg));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const pending = pendingAuths.get(state);
|
|
173
|
+
const isReserved = reservedAuthStates.has(state);
|
|
174
|
+
// Handle OAuth errors only for a state that belongs to an active flow.
|
|
175
|
+
if (error) {
|
|
176
|
+
if (!pending && !isReserved) {
|
|
177
|
+
const errorMsg = "Invalid or expired state parameter - potential CSRF attack";
|
|
178
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
179
|
+
res.end(htmlError(errorMsg));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const errorMsg = errorDescription || error;
|
|
183
|
+
// Send HTTP response first before rejecting promise
|
|
184
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
185
|
+
res.end(htmlError(errorMsg));
|
|
186
|
+
// Reject promise after response is sent (defer to allow test to attach handler)
|
|
187
|
+
if (pending) {
|
|
188
|
+
reservedAuthStates.delete(state);
|
|
189
|
+
clearTimeout(pending.timeout);
|
|
190
|
+
pendingAuths.delete(state);
|
|
191
|
+
setTimeout(() => pending.reject(new Error(errorMsg)), 0);
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Validate state parameter
|
|
196
|
+
if (!pending && !isReserved) {
|
|
197
|
+
const errorMsg = "Invalid or expired state parameter - potential CSRF attack";
|
|
198
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
199
|
+
res.end(htmlError(errorMsg));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Require authorization code
|
|
203
|
+
if (!code) {
|
|
204
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
205
|
+
res.end(htmlError("No authorization code provided"));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!pending) {
|
|
209
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
210
|
+
res.end(htmlManualSuccess());
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Clear timeout and resolve the pending promise
|
|
214
|
+
clearTimeout(pending.timeout);
|
|
215
|
+
pendingAuths.delete(state);
|
|
216
|
+
pending.resolve({ code, ...(iss !== null ? { iss } : {}) });
|
|
217
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
218
|
+
res.end(htmlSuccess());
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Ensure the callback server is running.
|
|
222
|
+
* If strictPort is true, requires binding on the configured callback port.
|
|
223
|
+
* If strictPort is false, asks the OS for an available local port.
|
|
224
|
+
*/
|
|
225
|
+
export async function ensureCallbackServer(options = {}) {
|
|
226
|
+
const generation = callbackGeneration;
|
|
227
|
+
if (stoppingPromise) {
|
|
228
|
+
if (!restartableStoppingPromise) {
|
|
229
|
+
throw new Error("OAuth callback server stopped");
|
|
230
|
+
}
|
|
231
|
+
await restartableStoppingPromise;
|
|
232
|
+
if (generation !== callbackGeneration) {
|
|
233
|
+
throw new Error("OAuth callback server stopped");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
while (bindingPromise) {
|
|
237
|
+
await bindingPromise;
|
|
238
|
+
if (generation !== callbackGeneration) {
|
|
239
|
+
throw new Error("OAuth callback server stopped");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (generation !== callbackGeneration) {
|
|
243
|
+
throw new Error("OAuth callback server stopped");
|
|
244
|
+
}
|
|
245
|
+
const operation = ensureCallbackServerLocked(options);
|
|
246
|
+
bindingPromise = operation;
|
|
247
|
+
try {
|
|
248
|
+
await operation;
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
if (bindingPromise === operation) {
|
|
252
|
+
bindingPromise = undefined;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async function ensureCallbackServerLocked(options = {}) {
|
|
257
|
+
const requiredPort = options.port ?? getConfiguredOAuthCallbackPort();
|
|
258
|
+
const strictPort = options.strictPort === true;
|
|
259
|
+
const requestedHost = options.callbackHost ?? DEFAULT_OAUTH_CALLBACK_HOST;
|
|
260
|
+
const rawRequestedPath = options.callbackPath ?? DEFAULT_OAUTH_CALLBACK_PATH;
|
|
261
|
+
const requestedPath = rawRequestedPath.startsWith("/") ? rawRequestedPath : `/${rawRequestedPath}`;
|
|
262
|
+
if (options.reserveState && !options.oauthState) {
|
|
263
|
+
throw new Error("OAuth callback reservation requires an oauthState");
|
|
264
|
+
}
|
|
265
|
+
let reservedState;
|
|
266
|
+
const previousServer = server;
|
|
267
|
+
const needsStrictRebind = Boolean(previousServer && strictPort && getOAuthCallbackPort() !== requiredPort);
|
|
268
|
+
const needsHostSwitch = Boolean(previousServer && callbackServerHost !== requestedHost);
|
|
269
|
+
const needsPathSwitch = Boolean(previousServer && getOAuthCallbackPath() !== requestedPath);
|
|
270
|
+
if (previousServer) {
|
|
271
|
+
if (!needsStrictRebind && !needsHostSwitch) {
|
|
272
|
+
if (needsPathSwitch) {
|
|
273
|
+
if (pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
274
|
+
throw new Error(`OAuth callback server is using path ${getOAuthCallbackPath()}, but callback path ${requestedPath} is required and cannot be switched while authorizations are pending`);
|
|
275
|
+
}
|
|
276
|
+
setOAuthCallbackPath(requestedPath);
|
|
277
|
+
}
|
|
278
|
+
if (options.reserveState && options.oauthState) {
|
|
279
|
+
reservedAuthStates.add(options.oauthState);
|
|
280
|
+
reservedState = options.oauthState;
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
285
|
+
throw new Error(`OAuth callback server is running on ${callbackServerHost}:${getOAuthCallbackPort()}, but strict callback endpoint ${requestedHost}:${requiredPort} is required and cannot be switched while authorizations are pending`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const candidateServer = createServer(handleRequest);
|
|
289
|
+
const listenPort = strictPort ? requiredPort : 0;
|
|
290
|
+
try {
|
|
291
|
+
await new Promise((resolve, reject) => {
|
|
292
|
+
candidateServer.once("error", (err) => {
|
|
293
|
+
reject(err);
|
|
294
|
+
});
|
|
295
|
+
candidateServer.listen(listenPort, requestedHost, () => {
|
|
296
|
+
resolve();
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
if (strictPort) {
|
|
300
|
+
setOAuthCallbackPort(requiredPort);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const address = candidateServer.address();
|
|
304
|
+
if (!address || typeof address === "string" || typeof address.port !== "number") {
|
|
305
|
+
throw new Error("OAuth callback server did not report an assigned port");
|
|
306
|
+
}
|
|
307
|
+
setOAuthCallbackPort(address.port);
|
|
308
|
+
}
|
|
309
|
+
if (previousServer && (needsStrictRebind || needsHostSwitch)) {
|
|
310
|
+
await new Promise((resolve) => {
|
|
311
|
+
previousServer.close(() => resolve());
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
callbackServerHost = requestedHost;
|
|
315
|
+
setOAuthCallbackPath(requestedPath);
|
|
316
|
+
server = candidateServer;
|
|
317
|
+
if (options.reserveState && options.oauthState) {
|
|
318
|
+
reservedAuthStates.add(options.oauthState);
|
|
319
|
+
reservedState = options.oauthState;
|
|
320
|
+
}
|
|
321
|
+
server.unref();
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
if (reservedState) {
|
|
325
|
+
reservedAuthStates.delete(reservedState);
|
|
326
|
+
}
|
|
327
|
+
const nodeError = error;
|
|
328
|
+
await new Promise((resolve) => {
|
|
329
|
+
candidateServer.close(() => resolve());
|
|
330
|
+
});
|
|
331
|
+
if (strictPort && nodeError.code === "EADDRINUSE") {
|
|
332
|
+
throw new Error(`OAuth callback port ${requiredPort} is already in use. Pre-registered OAuth clients require an exact redirect URI; set MCP_OAUTH_CALLBACK_PORT to your registered port or free port ${requiredPort}`, { cause: error });
|
|
333
|
+
}
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
export function reserveCallbackServer(oauthState) {
|
|
338
|
+
reservedAuthStates.add(oauthState);
|
|
339
|
+
}
|
|
340
|
+
export function releaseCallbackServer(oauthState) {
|
|
341
|
+
reservedAuthStates.delete(oauthState);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Wait for a callback with the given OAuth state.
|
|
345
|
+
* Returns a promise that resolves with the authorization code and, when the
|
|
346
|
+
* authorization server sends one, the RFC 9207 `iss` parameter.
|
|
347
|
+
*/
|
|
348
|
+
export function waitForCallback(oauthState) {
|
|
349
|
+
reservedAuthStates.delete(oauthState);
|
|
350
|
+
return new Promise((resolve, reject) => {
|
|
351
|
+
const timeout = setTimeout(() => {
|
|
352
|
+
if (pendingAuths.has(oauthState)) {
|
|
353
|
+
pendingAuths.delete(oauthState);
|
|
354
|
+
reject(new Error("OAuth callback timeout - authorization took too long"));
|
|
355
|
+
}
|
|
356
|
+
}, CALLBACK_TIMEOUT_MS);
|
|
357
|
+
pendingAuths.set(oauthState, { resolve, reject, timeout });
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Cancel a pending authorization by state.
|
|
362
|
+
*/
|
|
363
|
+
export function cancelPendingCallback(oauthState) {
|
|
364
|
+
reservedAuthStates.delete(oauthState);
|
|
365
|
+
const pending = pendingAuths.get(oauthState);
|
|
366
|
+
if (pending) {
|
|
367
|
+
clearTimeout(pending.timeout);
|
|
368
|
+
pendingAuths.delete(oauthState);
|
|
369
|
+
pending.reject(new Error("Authorization cancelled"));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Stop the callback server and reject all pending authorizations.
|
|
374
|
+
*/
|
|
375
|
+
export function stopCallbackServer() {
|
|
376
|
+
if (stoppingPromise) {
|
|
377
|
+
restartableStoppingPromise = undefined;
|
|
378
|
+
callbackGeneration += 1;
|
|
379
|
+
return stoppingPromise;
|
|
380
|
+
}
|
|
381
|
+
callbackGeneration += 1;
|
|
382
|
+
const cleanup = (async () => {
|
|
383
|
+
while (bindingPromise) {
|
|
384
|
+
await bindingPromise.catch(() => { });
|
|
385
|
+
}
|
|
386
|
+
if (server) {
|
|
387
|
+
await new Promise((resolve) => {
|
|
388
|
+
server.close(() => {
|
|
389
|
+
resolve();
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
server = undefined;
|
|
393
|
+
}
|
|
394
|
+
setOAuthCallbackPort(getConfiguredOAuthCallbackPort());
|
|
395
|
+
callbackServerHost = DEFAULT_OAUTH_CALLBACK_HOST;
|
|
396
|
+
setOAuthCallbackPath(DEFAULT_OAUTH_CALLBACK_PATH);
|
|
397
|
+
// Reject all pending auths (defer to allow any pending operations to complete)
|
|
398
|
+
const pendingList = Array.from(pendingAuths.entries());
|
|
399
|
+
pendingAuths.clear();
|
|
400
|
+
reservedAuthStates.clear();
|
|
401
|
+
setTimeout(() => {
|
|
402
|
+
for (const [, pending] of pendingList) {
|
|
403
|
+
clearTimeout(pending.timeout);
|
|
404
|
+
pending.reject(new Error("OAuth callback server stopped"));
|
|
405
|
+
}
|
|
406
|
+
}, 0);
|
|
407
|
+
})();
|
|
408
|
+
const operation = cleanup.finally(() => {
|
|
409
|
+
if (stoppingPromise === operation)
|
|
410
|
+
stoppingPromise = undefined;
|
|
411
|
+
});
|
|
412
|
+
stoppingPromise = operation;
|
|
413
|
+
return operation;
|
|
414
|
+
}
|
|
415
|
+
/** Stop the callback server only when no bind or authorization owns it. */
|
|
416
|
+
export function stopCallbackServerIfIdle() {
|
|
417
|
+
if (stoppingPromise)
|
|
418
|
+
return stoppingPromise;
|
|
419
|
+
if (bindingPromise || !server || pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
420
|
+
return Promise.resolve();
|
|
421
|
+
}
|
|
422
|
+
const operation = stopCallbackServer().finally(() => {
|
|
423
|
+
if (restartableStoppingPromise === operation)
|
|
424
|
+
restartableStoppingPromise = undefined;
|
|
425
|
+
});
|
|
426
|
+
restartableStoppingPromise = operation;
|
|
427
|
+
return operation;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Check if the callback server is running.
|
|
431
|
+
*/
|
|
432
|
+
export function isCallbackServerRunning() {
|
|
433
|
+
return server !== undefined;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Get the number of pending authorizations.
|
|
437
|
+
*/
|
|
438
|
+
export function getPendingAuthCount() {
|
|
439
|
+
return pendingAuths.size;
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=mcp-callback-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-callback-server.js","sourceRoot":"","sources":["../mcp-callback-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAA0D,MAAM,MAAM,CAAA;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,yBAAyB,CAAA;AAEhC,yCAAyC;AACzC,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,6EAA6E;AAE7E,2EAA2E;AAC3E,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuDb,CAAA;AAEN,MAAM,UAAU,GACd,mLAAmL,CAAA;AAErL,MAAM,UAAU,GACd,wLAAwL,CAAA;AAE1L,SAAS,IAAI,CAAC,OAQb;IACC,OAAO;;;;;WAKE,OAAO,CAAC,KAAK;WACb,UAAU;;;;;wBAKG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;UAC3C,OAAO,CAAC,OAAO;SAChB,OAAO,CAAC,IAAI;MACf,OAAO,CAAC,KAAK,IAAI,EAAE;;EAEvB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,8DAA8D,CAAC,CAAC,CAAC,EAAE;QACjF,CAAA;AACR,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,C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0BAA0B,KAAK,SAAS;YAAE,0BAA0B,GAAG,SAAS,CAAA;IACtF,CAAC,CAAC,CAAA;IACF,0BAA0B,GAAG,SAAS,CAAA;IACtC,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,KAAK,SAAS,CAAA;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,YAAY,CAAC,IAAI,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP OAuth Provider
|
|
3
|
+
*
|
|
4
|
+
* Implementation of the MCP SDK's OAuthClientProvider interface.
|
|
5
|
+
* Handles OAuth client registration, token storage, and authorization redirection.
|
|
6
|
+
*/
|
|
7
|
+
import { type AddClientAuthentication, type OAuthClientInformationContext, type OAuthClientProvider, type OAuthDiscoveryState } from "@modelcontextprotocol/client";
|
|
8
|
+
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/client";
|
|
9
|
+
import { type AuthStorageOptions, type OAuthAuthority } from "./mcp-auth.ts";
|
|
10
|
+
import { type OAuthFetch } from "./mcp-auth-fetch.ts";
|
|
11
|
+
declare const DEFAULT_OAUTH_CALLBACK_PORT = 19876;
|
|
12
|
+
declare const DEFAULT_OAUTH_CALLBACK_PATH = "/callback";
|
|
13
|
+
export declare function getConfiguredOAuthCallbackPort(): number;
|
|
14
|
+
export declare function getOAuthCallbackPort(): number;
|
|
15
|
+
export declare function setOAuthCallbackPort(port: number): void;
|
|
16
|
+
export declare function getOAuthCallbackPath(): string;
|
|
17
|
+
export declare function setOAuthCallbackPath(path: string): void;
|
|
18
|
+
/** Configuration options for OAuth */
|
|
19
|
+
export interface McpOAuthConfig {
|
|
20
|
+
grantType?: "authorization_code" | "client_credentials";
|
|
21
|
+
clientId?: string;
|
|
22
|
+
clientSecret?: string;
|
|
23
|
+
clientMetadataUrl?: string;
|
|
24
|
+
scope?: string;
|
|
25
|
+
authorizationParams?: Record<string, string>;
|
|
26
|
+
redirectUri?: string;
|
|
27
|
+
clientName?: string;
|
|
28
|
+
clientUri?: string;
|
|
29
|
+
logoUri?: string;
|
|
30
|
+
authServerMetadataUrl?: string;
|
|
31
|
+
skipIssuerMetadataValidation?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Callbacks for OAuth flow interactions */
|
|
34
|
+
export interface McpOAuthCallbacks {
|
|
35
|
+
onRedirect: (url: URL) => void | Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* OAuth provider implementation for MCP servers.
|
|
39
|
+
* Implements the OAuthClientProvider interface from the MCP SDK.
|
|
40
|
+
*/
|
|
41
|
+
export declare class McpOAuthProvider implements OAuthClientProvider {
|
|
42
|
+
private serverName;
|
|
43
|
+
private serverUrl;
|
|
44
|
+
private config;
|
|
45
|
+
private callbacks;
|
|
46
|
+
private storageOptions;
|
|
47
|
+
private runtimeSignal?;
|
|
48
|
+
readonly clientMetadataUrl?: string;
|
|
49
|
+
private readonly redirectUrlSnapshot;
|
|
50
|
+
private authFetch;
|
|
51
|
+
private active;
|
|
52
|
+
private flowClientInfo;
|
|
53
|
+
private flowCodeVerifier;
|
|
54
|
+
private flowDiscoveryState;
|
|
55
|
+
private flowIssuerMismatch;
|
|
56
|
+
private flowState;
|
|
57
|
+
private invalidatedAccessToken;
|
|
58
|
+
private invalidatedClientId;
|
|
59
|
+
private staleRedirectClientId;
|
|
60
|
+
private lastObservedClientId;
|
|
61
|
+
private lastSavedAccessToken;
|
|
62
|
+
private pendingAuthAccessToken;
|
|
63
|
+
private readonly assertAuthority;
|
|
64
|
+
constructor(serverName: string, serverUrl: string, config: McpOAuthConfig, callbacks: McpOAuthCallbacks, storageOptions?: AuthStorageOptions, runtimeSignal?: AbortSignal | undefined, initialState?: string, authority?: OAuthAuthority);
|
|
65
|
+
setAuthFetch(fetchFn: OAuthFetch): void;
|
|
66
|
+
private get usesClientCredentials();
|
|
67
|
+
private get discoveredIssuer();
|
|
68
|
+
deactivate(): void;
|
|
69
|
+
private assertStoredIssuerBindings;
|
|
70
|
+
private throwIfInactive;
|
|
71
|
+
/**
|
|
72
|
+
* The redirect URL for OAuth callbacks.
|
|
73
|
+
* This must match the redirect_uri in client metadata.
|
|
74
|
+
*/
|
|
75
|
+
get redirectUrl(): string | undefined;
|
|
76
|
+
/** Configured homepage, else the historical default on stock pi, else nothing. */
|
|
77
|
+
private get clientUri();
|
|
78
|
+
/**
|
|
79
|
+
* Client metadata for dynamic registration.
|
|
80
|
+
* Describes this client to the OAuth authorization server.
|
|
81
|
+
*/
|
|
82
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
83
|
+
/**
|
|
84
|
+
* Get client information (for pre-registered or dynamically registered clients).
|
|
85
|
+
* Returns undefined if no client info exists or if the server URL has changed.
|
|
86
|
+
*/
|
|
87
|
+
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Save client information from dynamic registration.
|
|
90
|
+
*/
|
|
91
|
+
saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Get stored OAuth tokens.
|
|
94
|
+
* Returns undefined if no tokens exist or if the server URL has changed.
|
|
95
|
+
*/
|
|
96
|
+
tokens(ctx?: OAuthClientInformationContext): Promise<OAuthTokens | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* Save OAuth tokens.
|
|
99
|
+
*/
|
|
100
|
+
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Redirect the user to the authorization URL.
|
|
103
|
+
* This opens the browser for the user to authenticate.
|
|
104
|
+
*
|
|
105
|
+
* Throws UnauthorizedError when called outside of a user-initiated flow
|
|
106
|
+
* (no oauthState saved by startAuth). That path is reached when the SDK
|
|
107
|
+
* falls through from a failed refresh into a fresh authorization_code
|
|
108
|
+
* flow, which library hosts cannot complete in-process.
|
|
109
|
+
*/
|
|
110
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Save the PKCE code verifier.
|
|
113
|
+
*/
|
|
114
|
+
saveCodeVerifier(codeVerifier: string): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the stored PKCE code verifier.
|
|
117
|
+
* @throws Error if no code verifier is stored
|
|
118
|
+
*/
|
|
119
|
+
codeVerifier(): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Keep discovery with the in-flight PKCE verifier. The callback leg uses it
|
|
122
|
+
* to validate the authorization response issuer before token exchange.
|
|
123
|
+
*/
|
|
124
|
+
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
125
|
+
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
126
|
+
/** Internal connection-attempt identity check for manager cleanup. */
|
|
127
|
+
/**
|
|
128
|
+
* Save the OAuth state parameter for CSRF protection.
|
|
129
|
+
*/
|
|
130
|
+
saveState(state: string): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the stored OAuth state parameter.
|
|
133
|
+
* @throws UnauthorizedError if no flow is in progress (see redirectToAuthorization)
|
|
134
|
+
*/
|
|
135
|
+
state(): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Invalidate credentials when authentication fails.
|
|
138
|
+
* Clears tokens, client info, or all credentials based on the type.
|
|
139
|
+
*/
|
|
140
|
+
invalidateCredentials(type: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Adds configured authorization-code scope without replacing the SDK's
|
|
143
|
+
* default token endpoint authentication behavior.
|
|
144
|
+
*/
|
|
145
|
+
addClientAuthentication: AddClientAuthentication;
|
|
146
|
+
prepareTokenRequest(scope?: string): URLSearchParams | undefined;
|
|
147
|
+
}
|
|
148
|
+
export { DEFAULT_OAUTH_CALLBACK_PORT, DEFAULT_OAUTH_CALLBACK_PATH };
|