agent-recall-mcp 3.5.2 → 3.5.4
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 +254 -143
- package/dist/build-server.d.ts +28 -0
- package/dist/build-server.d.ts.map +1 -0
- package/dist/build-server.js +55 -0
- package/dist/build-server.js.map +1 -0
- package/dist/http/activity.d.ts +60 -0
- package/dist/http/activity.d.ts.map +1 -0
- package/dist/http/activity.js +254 -0
- package/dist/http/activity.js.map +1 -0
- package/dist/http/alerts.d.ts +84 -0
- package/dist/http/alerts.d.ts.map +1 -0
- package/dist/http/alerts.js +213 -0
- package/dist/http/alerts.js.map +1 -0
- package/dist/http/cli.d.ts +3 -0
- package/dist/http/cli.d.ts.map +1 -0
- package/dist/http/cli.js +515 -0
- package/dist/http/cli.js.map +1 -0
- package/dist/http/export-tar.d.ts +23 -0
- package/dist/http/export-tar.d.ts.map +1 -0
- package/dist/http/export-tar.js +264 -0
- package/dist/http/export-tar.js.map +1 -0
- package/dist/http/federation.d.ts +45 -0
- package/dist/http/federation.d.ts.map +1 -0
- package/dist/http/federation.js +185 -0
- package/dist/http/federation.js.map +1 -0
- package/dist/http/film/film.css +80 -0
- package/dist/http/film/film.js +446 -0
- package/dist/http/film/human.jpg +0 -0
- package/dist/http/film/m0.jpg +0 -0
- package/dist/http/film/m2.jpg +0 -0
- package/dist/http/film/m3.jpg +0 -0
- package/dist/http/film/wrong.jpg +0 -0
- package/dist/http/film.d.ts +16 -0
- package/dist/http/film.d.ts.map +1 -0
- package/dist/http/film.js +119 -0
- package/dist/http/film.js.map +1 -0
- package/dist/http/home/cabinet.svg +1 -0
- package/dist/http/home/drawer-project.svg +1 -0
- package/dist/http/home/drawer-rules.svg +1 -0
- package/dist/http/home/drawer-you.svg +1 -0
- package/dist/http/home/fig1.svg +242 -0
- package/dist/http/home/fig2-1.svg +61 -0
- package/dist/http/home/fig2-2.svg +92 -0
- package/dist/http/home/fig3.svg +1 -0
- package/dist/http/home/home.css +509 -0
- package/dist/http/home/home.html +517 -0
- package/dist/http/home/icons.svg +15 -0
- package/dist/http/home.d.ts +23 -0
- package/dist/http/home.d.ts.map +1 -0
- package/dist/http/home.js +295 -0
- package/dist/http/home.js.map +1 -0
- package/dist/http/identities.d.ts +29 -0
- package/dist/http/identities.d.ts.map +1 -0
- package/dist/http/identities.js +91 -0
- package/dist/http/identities.js.map +1 -0
- package/dist/http/import-memory.d.ts +161 -0
- package/dist/http/import-memory.d.ts.map +1 -0
- package/dist/http/import-memory.js +718 -0
- package/dist/http/import-memory.js.map +1 -0
- package/dist/http/jsonfile.d.ts +6 -0
- package/dist/http/jsonfile.d.ts.map +1 -0
- package/dist/http/jsonfile.js +60 -0
- package/dist/http/jsonfile.js.map +1 -0
- package/dist/http/legal/PRIVACY.md +70 -0
- package/dist/http/legal.d.ts +10 -0
- package/dist/http/legal.d.ts.map +1 -0
- package/dist/http/legal.js +35 -0
- package/dist/http/legal.js.map +1 -0
- package/dist/http/limits.d.ts +59 -0
- package/dist/http/limits.d.ts.map +1 -0
- package/dist/http/limits.js +163 -0
- package/dist/http/limits.js.map +1 -0
- package/dist/http/markdown-lite.d.ts +2 -0
- package/dist/http/markdown-lite.d.ts.map +1 -0
- package/dist/http/markdown-lite.js +86 -0
- package/dist/http/markdown-lite.js.map +1 -0
- package/dist/http/multipart.d.ts +43 -0
- package/dist/http/multipart.d.ts.map +1 -0
- package/dist/http/multipart.js +152 -0
- package/dist/http/multipart.js.map +1 -0
- package/dist/http/oauth-app.d.ts +75 -0
- package/dist/http/oauth-app.d.ts.map +1 -0
- package/dist/http/oauth-app.js +259 -0
- package/dist/http/oauth-app.js.map +1 -0
- package/dist/http/oauth-config.d.ts +46 -0
- package/dist/http/oauth-config.d.ts.map +1 -0
- package/dist/http/oauth-config.js +122 -0
- package/dist/http/oauth-config.js.map +1 -0
- package/dist/http/oauth-pages.d.ts +40 -0
- package/dist/http/oauth-pages.d.ts.map +1 -0
- package/dist/http/oauth-pages.js +97 -0
- package/dist/http/oauth-pages.js.map +1 -0
- package/dist/http/oauth-provider.d.ts +124 -0
- package/dist/http/oauth-provider.d.ts.map +1 -0
- package/dist/http/oauth-provider.js +486 -0
- package/dist/http/oauth-provider.js.map +1 -0
- package/dist/http/oauth-store.d.ts +128 -0
- package/dist/http/oauth-store.d.ts.map +1 -0
- package/dist/http/oauth-store.js +317 -0
- package/dist/http/oauth-store.js.map +1 -0
- package/dist/http/redirect-policy.d.ts +16 -0
- package/dist/http/redirect-policy.d.ts.map +1 -0
- package/dist/http/redirect-policy.js +83 -0
- package/dist/http/redirect-policy.js.map +1 -0
- package/dist/http/review-pages.d.ts +39 -0
- package/dist/http/review-pages.d.ts.map +1 -0
- package/dist/http/review-pages.js +78 -0
- package/dist/http/review-pages.js.map +1 -0
- package/dist/http/review.d.ts +36 -0
- package/dist/http/review.d.ts.map +1 -0
- package/dist/http/review.js +220 -0
- package/dist/http/review.js.map +1 -0
- package/dist/http/serve.d.ts +58 -0
- package/dist/http/serve.d.ts.map +1 -0
- package/dist/http/serve.js +324 -0
- package/dist/http/serve.js.map +1 -0
- package/dist/http/site-pages.d.ts +110 -0
- package/dist/http/site-pages.d.ts.map +1 -0
- package/dist/http/site-pages.js +630 -0
- package/dist/http/site-pages.js.map +1 -0
- package/dist/http/site-theme.d.ts +13 -0
- package/dist/http/site-theme.d.ts.map +1 -0
- package/dist/http/site-theme.js +22 -0
- package/dist/http/site-theme.js.map +1 -0
- package/dist/http/site.d.ts +52 -0
- package/dist/http/site.d.ts.map +1 -0
- package/dist/http/site.js +353 -0
- package/dist/http/site.js.map +1 -0
- package/dist/http/stats.d.ts +139 -0
- package/dist/http/stats.d.ts.map +1 -0
- package/dist/http/stats.js +599 -0
- package/dist/http/stats.js.map +1 -0
- package/dist/http/tar-import.d.ts +69 -0
- package/dist/http/tar-import.d.ts.map +1 -0
- package/dist/http/tar-import.js +234 -0
- package/dist/http/tar-import.js.map +1 -0
- package/dist/http/tenant-paths.d.ts +14 -0
- package/dist/http/tenant-paths.d.ts.map +1 -0
- package/dist/http/tenant-paths.js +42 -0
- package/dist/http/tenant-paths.js.map +1 -0
- package/dist/http/tokens.d.ts +32 -0
- package/dist/http/tokens.d.ts.map +1 -0
- package/dist/http/tokens.js +137 -0
- package/dist/http/tokens.js.map +1 -0
- package/dist/http/trial.d.ts +55 -0
- package/dist/http/trial.d.ts.map +1 -0
- package/dist/http/trial.js +218 -0
- package/dist/http/trial.js.map +1 -0
- package/dist/http/web-session.d.ts +108 -0
- package/dist/http/web-session.d.ts.map +1 -0
- package/dist/http/web-session.js +267 -0
- package/dist/http/web-session.js.map +1 -0
- package/dist/index.js +12 -65
- package/dist/index.js.map +1 -1
- package/dist/lib/ambient-capture.d.ts.map +1 -1
- package/dist/lib/ambient-capture.js +4 -1
- package/dist/lib/ambient-capture.js.map +1 -1
- package/dist/lib/bookkeeping.d.ts +26 -0
- package/dist/lib/bookkeeping.d.ts.map +1 -0
- package/dist/lib/bookkeeping.js +31 -0
- package/dist/lib/bookkeeping.js.map +1 -0
- package/dist/lib/hosted-redact.d.ts +17 -0
- package/dist/lib/hosted-redact.d.ts.map +1 -0
- package/dist/lib/hosted-redact.js +57 -0
- package/dist/lib/hosted-redact.js.map +1 -0
- package/dist/lib/lifecycle-exit.d.ts +5 -13
- package/dist/lib/lifecycle-exit.d.ts.map +1 -1
- package/dist/lib/lifecycle-exit.js +38 -16
- package/dist/lib/lifecycle-exit.js.map +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.d.ts +65 -0
- package/dist/tools/annotations.d.ts.map +1 -0
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/check-action.d.ts.map +1 -1
- package/dist/tools/check-action.js +2 -0
- package/dist/tools/check-action.js.map +1 -1
- package/dist/tools/check.d.ts.map +1 -1
- package/dist/tools/check.js +6 -2
- package/dist/tools/check.js.map +1 -1
- package/dist/tools/digest.d.ts.map +1 -1
- package/dist/tools/digest.js +2 -0
- package/dist/tools/digest.js.map +1 -1
- package/dist/tools/pipeline-close.d.ts.map +1 -1
- package/dist/tools/pipeline-close.js +2 -0
- package/dist/tools/pipeline-close.js.map +1 -1
- package/dist/tools/pipeline-current.d.ts.map +1 -1
- package/dist/tools/pipeline-current.js +2 -0
- package/dist/tools/pipeline-current.js.map +1 -1
- package/dist/tools/pipeline-list.d.ts.map +1 -1
- package/dist/tools/pipeline-list.js +2 -0
- package/dist/tools/pipeline-list.js.map +1 -1
- package/dist/tools/pipeline-open.d.ts.map +1 -1
- package/dist/tools/pipeline-open.js +2 -0
- package/dist/tools/pipeline-open.js.map +1 -1
- package/dist/tools/pipeline-show.d.ts.map +1 -1
- package/dist/tools/pipeline-show.js +2 -0
- package/dist/tools/pipeline-show.js.map +1 -1
- package/dist/tools/recall.d.ts.map +1 -1
- package/dist/tools/recall.js +4 -1
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/register-rule.d.ts.map +1 -1
- package/dist/tools/register-rule.js +2 -0
- package/dist/tools/register-rule.js.map +1 -1
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +10 -1
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/session-end.d.ts +15 -0
- package/dist/tools/session-end.d.ts.map +1 -1
- package/dist/tools/session-end.js +13 -1
- package/dist/tools/session-end.js.map +1 -1
- package/dist/tools/session-start.d.ts +6 -1
- package/dist/tools/session-start.d.ts.map +1 -1
- package/dist/tools/session-start.js +24 -212
- package/dist/tools/session-start.js.map +1 -1
- package/package.json +11 -8
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-config.ts — OAuth is OFF unless a public URL AND at least one federated
|
|
3
|
+
* login provider are configured; then the server is its own OAuth authorization
|
|
4
|
+
* server and users sign in with GitHub and/or Google. AgentRecall never sees or
|
|
5
|
+
* stores a password.
|
|
6
|
+
*
|
|
7
|
+
* AR_PUBLIC_URL / --public-url public origin = OAuth issuer (https, except localhost)
|
|
8
|
+
* AR_OAUTH_GITHUB_CLIENT_ID / _SECRET GitHub OAuth app (callback: <public>/authorize/callback/github)
|
|
9
|
+
* AR_OAUTH_GOOGLE_CLIENT_ID / _SECRET Google OAuth client (callback: <public>/authorize/callback/google)
|
|
10
|
+
* AR_OAUTH_REDIRECT_ALLOW extra allowed client redirect URI prefixes, comma-separated
|
|
11
|
+
* AR_OAUTH_SIGNUP=invite|open invite (default): only accounts linked with `identity link` may sign in
|
|
12
|
+
* AR_PRIVACY_URL optional https link to the privacy policy, shown on the sign-in page
|
|
13
|
+
* AR_TRUST_PROXY=1|true|yes|on trust ONE proxy hop for the client IP (0|false|no|off or empty = no)
|
|
14
|
+
*
|
|
15
|
+
* Nothing configured → null (server == v1). Anything half-configured (a lone
|
|
16
|
+
* id or secret, a public URL without a provider, a provider without a public
|
|
17
|
+
* URL) throws: fail closed instead of silently running without OAuth.
|
|
18
|
+
*/
|
|
19
|
+
export class OAuthConfigError extends Error {
|
|
20
|
+
}
|
|
21
|
+
export const PROVIDER_NAMES = ["github", "google"];
|
|
22
|
+
function parsePrivacyUrl(raw) {
|
|
23
|
+
const v = clean(raw);
|
|
24
|
+
if (v === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
let u;
|
|
27
|
+
try {
|
|
28
|
+
u = new URL(v);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new OAuthConfigError("AR_PRIVACY_URL is not a valid URL");
|
|
32
|
+
}
|
|
33
|
+
if (u.username || u.password)
|
|
34
|
+
throw new OAuthConfigError("AR_PRIVACY_URL must not contain credentials");
|
|
35
|
+
if (u.protocol !== "https:")
|
|
36
|
+
throw new OAuthConfigError("AR_PRIVACY_URL must be an https URL");
|
|
37
|
+
return u;
|
|
38
|
+
}
|
|
39
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
40
|
+
function clean(v) {
|
|
41
|
+
return v === undefined || v.trim() === "" ? undefined : v.trim();
|
|
42
|
+
}
|
|
43
|
+
/** The value as it may appear in an error message: any userinfo (user:password@) masked. */
|
|
44
|
+
function shown(raw) {
|
|
45
|
+
return raw.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/?#]*@/i, "$1***@");
|
|
46
|
+
}
|
|
47
|
+
export function parseOrigin(name, raw) {
|
|
48
|
+
let u;
|
|
49
|
+
try {
|
|
50
|
+
u = new URL(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new OAuthConfigError(`${name} is not a valid URL: "${shown(raw)}"`);
|
|
54
|
+
}
|
|
55
|
+
// Credentials first, so no later message ever echoes them.
|
|
56
|
+
if (u.username || u.password)
|
|
57
|
+
throw new OAuthConfigError(`${name} must not contain credentials`);
|
|
58
|
+
const secure = u.protocol === "https:" || (u.protocol === "http:" && LOCAL_HOSTS.has(u.hostname));
|
|
59
|
+
if (!secure)
|
|
60
|
+
throw new OAuthConfigError(`${name} must be https (http only for localhost), got "${shown(raw)}"`);
|
|
61
|
+
if (u.search || u.hash || u.pathname !== "/") {
|
|
62
|
+
throw new OAuthConfigError(`${name} must be an origin only (no path, query or fragment), got "${shown(raw)}"`);
|
|
63
|
+
}
|
|
64
|
+
return u;
|
|
65
|
+
}
|
|
66
|
+
const TRUE_WORDS = new Set(["1", "true", "yes", "on"]);
|
|
67
|
+
const FALSE_WORDS = new Set(["", "0", "false", "no", "off"]);
|
|
68
|
+
/** A yes/no setting; an unrecognised value fails closed instead of silently meaning "no". */
|
|
69
|
+
function parseBool(name, raw) {
|
|
70
|
+
const v = (raw ?? "").trim().toLowerCase();
|
|
71
|
+
if (TRUE_WORDS.has(v))
|
|
72
|
+
return true;
|
|
73
|
+
if (FALSE_WORDS.has(v))
|
|
74
|
+
return false;
|
|
75
|
+
throw new OAuthConfigError(`${name} must be one of 1/true/yes/on or 0/false/no/off, got "${raw}"`);
|
|
76
|
+
}
|
|
77
|
+
function parseSignup(raw) {
|
|
78
|
+
const v = (raw ?? "").trim().toLowerCase();
|
|
79
|
+
if (v === "" || v === "invite")
|
|
80
|
+
return "invite";
|
|
81
|
+
if (v === "open")
|
|
82
|
+
return "open";
|
|
83
|
+
throw new OAuthConfigError(`AR_OAUTH_SIGNUP must be "invite" (default) or "open", got "${raw}"`);
|
|
84
|
+
}
|
|
85
|
+
export function loadOAuthConfig(flags = {}, env = process.env) {
|
|
86
|
+
const pub = clean(flags.publicUrl) ?? clean(env.AR_PUBLIC_URL);
|
|
87
|
+
const providers = {};
|
|
88
|
+
for (const name of PROVIDER_NAMES) {
|
|
89
|
+
const up = name.toUpperCase();
|
|
90
|
+
const id = clean(env[`AR_OAUTH_${up}_CLIENT_ID`]);
|
|
91
|
+
const secret = clean(env[`AR_OAUTH_${up}_CLIENT_SECRET`]);
|
|
92
|
+
if (id === undefined && secret === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
if (id === undefined || secret === undefined) {
|
|
95
|
+
throw new OAuthConfigError(`OAuth ${name} login needs both AR_OAUTH_${up}_CLIENT_ID and AR_OAUTH_${up}_CLIENT_SECRET`);
|
|
96
|
+
}
|
|
97
|
+
providers[name] = { clientId: id, clientSecret: secret };
|
|
98
|
+
}
|
|
99
|
+
const anyProvider = Object.keys(providers).length > 0;
|
|
100
|
+
if (pub === undefined && !anyProvider)
|
|
101
|
+
return null;
|
|
102
|
+
if (pub === undefined)
|
|
103
|
+
throw new OAuthConfigError("OAuth needs AR_PUBLIC_URL (--public-url) as well as the provider credentials");
|
|
104
|
+
if (!anyProvider) {
|
|
105
|
+
throw new OAuthConfigError("OAuth needs at least one provider: set AR_OAUTH_GITHUB_CLIENT_ID/_SECRET and/or AR_OAUTH_GOOGLE_CLIENT_ID/_SECRET");
|
|
106
|
+
}
|
|
107
|
+
const publicUrl = parseOrigin("AR_PUBLIC_URL", pub);
|
|
108
|
+
const redirectAllow = (clean(env.AR_OAUTH_REDIRECT_ALLOW) ?? "")
|
|
109
|
+
.split(",")
|
|
110
|
+
.map((s) => s.trim())
|
|
111
|
+
.filter((s) => s.length > 0);
|
|
112
|
+
return {
|
|
113
|
+
publicUrl,
|
|
114
|
+
resourceUrl: new URL("/mcp", publicUrl),
|
|
115
|
+
providers,
|
|
116
|
+
redirectAllow,
|
|
117
|
+
trustProxy: parseBool("AR_TRUST_PROXY", env.AR_TRUST_PROXY),
|
|
118
|
+
signup: parseSignup(env.AR_OAUTH_SIGNUP),
|
|
119
|
+
privacyUrl: parsePrivacyUrl(env.AR_PRIVACY_URL),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=oauth-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-config.js","sourceRoot":"","sources":["../../src/http/oauth-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAG9C,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAqB5E,SAAS,eAAe,CAAC,GAAuB;IAC9C,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtC,IAAI,CAAM,CAAC;IACX,IAAI,CAAC;QACH,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,gBAAgB,CAAC,mCAAmC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ;QAAE,MAAM,IAAI,gBAAgB,CAAC,6CAA6C,CAAC,CAAC;IACxG,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ;QAAE,MAAM,IAAI,gBAAgB,CAAC,qCAAqC,CAAC,CAAC;IAC/F,OAAO,CAAC,CAAC;A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AC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/B,OAAO;QACL,SAAS;QACT,WAAW,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC;QACvC,SAAS;QACT,aAAa;QACb,UAAU,EAAE,SAAS,CAAC,gBAAgB,EAAE,GAAG,CAAC,cAAc,CAAC;QAC3D,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC;QACxC,UAAU,EAAE,eAAe,CAAC,GAAG,CAAC,cAAc,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-pages.ts — the HTML the sign-in flow shows. Plain strings, no template engine.
|
|
3
|
+
*
|
|
4
|
+
* EVERY interpolated value goes through esc(). There is no password or code field
|
|
5
|
+
* anywhere: the page only offers "Continue with GitHub / Google" buttons that POST
|
|
6
|
+
* to this server, which then redirects to the provider. Security headers (see
|
|
7
|
+
* pageHeaders): no framing, no referrer, no caching, no scripts. form-action lists this
|
|
8
|
+
* server and the provider origins and, on the sign-in and retry pages, the client's
|
|
9
|
+
* callback: browsers apply form-action to EVERY redirect after the form POST, and when
|
|
10
|
+
* the provider skips its consent screen the chain ends at the client.
|
|
11
|
+
*/
|
|
12
|
+
export declare function esc(v: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* `formActionOrigins`: extra sources the sign-in form may be redirected to: the providers' origins and the
|
|
15
|
+
* client's redirect target (an http(s) origin, or a bare scheme such as `cursor:` for a custom-scheme callback).
|
|
16
|
+
* `null` leaves form-action out: only for the sign-in form of a client whose callback is an IPv6 literal
|
|
17
|
+
* (`http://[::1]:…`), which no CSP source can name (browsers drop such a source and would block the redirect).
|
|
18
|
+
*/
|
|
19
|
+
export declare function pageHeaders(formActionOrigins?: readonly string[] | null): Record<string, string>;
|
|
20
|
+
/** A custom-scheme callback's CSP source (`cursor:`): a bare scheme, never one of the unsafe ones. */
|
|
21
|
+
export declare function isCustomSchemeSource(o: string): boolean;
|
|
22
|
+
/** A whole page. `body` must already be escaped; `extraStyle` is a constant stylesheet, never user data. */
|
|
23
|
+
export declare function shell(title: string, body: string, extraStyle?: string): string;
|
|
24
|
+
export interface SignInView {
|
|
25
|
+
requestId: string;
|
|
26
|
+
clientName: string;
|
|
27
|
+
redirectHost: string;
|
|
28
|
+
destination: "loopback" | "claude" | "other";
|
|
29
|
+
/** Configured providers only: [{name:"github", label:"GitHub"}]. */
|
|
30
|
+
providers: Array<{
|
|
31
|
+
name: string;
|
|
32
|
+
label: string;
|
|
33
|
+
}>;
|
|
34
|
+
error?: string;
|
|
35
|
+
/** Operator's privacy policy (validated https URL from AR_PRIVACY_URL); omitted = no link. */
|
|
36
|
+
privacyUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function signInPage(v: SignInView): string;
|
|
39
|
+
export declare function errorPage(message: string): string;
|
|
40
|
+
//# sourceMappingURL=oauth-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-pages.d.ts","sourceRoot":"","sources":["../../src/http/oauth-pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,wBAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAUtC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,iBAAiB,GAAE,SAAS,MAAM,EAAE,GAAG,IAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYpG;AAKD,sGAAsG;AACtG,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEvD;AA2BD,4GAA4G;AAC5G,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,SAAK,GAAG,MAAM,CAG1E;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC7C,oEAAoE;IACpE,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAiBhD;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-pages.ts — the HTML the sign-in flow shows. Plain strings, no template engine.
|
|
3
|
+
*
|
|
4
|
+
* EVERY interpolated value goes through esc(). There is no password or code field
|
|
5
|
+
* anywhere: the page only offers "Continue with GitHub / Google" buttons that POST
|
|
6
|
+
* to this server, which then redirects to the provider. Security headers (see
|
|
7
|
+
* pageHeaders): no framing, no referrer, no caching, no scripts. form-action lists this
|
|
8
|
+
* server and the provider origins and, on the sign-in and retry pages, the client's
|
|
9
|
+
* callback: browsers apply form-action to EVERY redirect after the form POST, and when
|
|
10
|
+
* the provider skips its consent screen the chain ends at the client.
|
|
11
|
+
*/
|
|
12
|
+
import { SITE_TOKENS } from "./site-theme.js";
|
|
13
|
+
export function esc(v) {
|
|
14
|
+
return String(v ?? "")
|
|
15
|
+
// eslint-disable-next-line no-control-regex
|
|
16
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, "")
|
|
17
|
+
.replace(/&/g, "&")
|
|
18
|
+
.replace(/</g, "<")
|
|
19
|
+
.replace(/>/g, ">")
|
|
20
|
+
.replace(/"/g, """)
|
|
21
|
+
.replace(/'/g, "'")
|
|
22
|
+
.replace(/`/g, "`");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `formActionOrigins`: extra sources the sign-in form may be redirected to: the providers' origins and the
|
|
26
|
+
* client's redirect target (an http(s) origin, or a bare scheme such as `cursor:` for a custom-scheme callback).
|
|
27
|
+
* `null` leaves form-action out: only for the sign-in form of a client whose callback is an IPv6 literal
|
|
28
|
+
* (`http://[::1]:…`), which no CSP source can name (browsers drop such a source and would block the redirect).
|
|
29
|
+
*/
|
|
30
|
+
export function pageHeaders(formActionOrigins = []) {
|
|
31
|
+
const extra = (formActionOrigins ?? []).filter((o) => /^https?:\/\/[A-Za-z0-9.\-:]+$/.test(o) || isCustomSchemeSource(o));
|
|
32
|
+
const formAction = formActionOrigins === null ? "" : ` form-action 'self'${extra.length ? " " + extra.join(" ") : ""};`;
|
|
33
|
+
return {
|
|
34
|
+
"content-type": "text/html; charset=utf-8",
|
|
35
|
+
"content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; base-uri 'none';${formAction} frame-ancestors 'none'`,
|
|
36
|
+
"x-frame-options": "DENY",
|
|
37
|
+
"referrer-policy": "no-referrer",
|
|
38
|
+
"cache-control": "no-store",
|
|
39
|
+
"x-content-type-options": "nosniff",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Schemes that must never be a bare form-action source: they would allow any web site, a script, or local data. */
|
|
43
|
+
const UNSAFE_SCHEME_SOURCES = new Set(["http:", "https:", "ws:", "wss:", "javascript:", "vbscript:", "data:", "blob:", "file:", "filesystem:", "about:"]);
|
|
44
|
+
/** A custom-scheme callback's CSP source (`cursor:`): a bare scheme, never one of the unsafe ones. */
|
|
45
|
+
export function isCustomSchemeSource(o) {
|
|
46
|
+
return /^[a-z][a-z0-9+.-]*:$/.test(o) && !UNSAFE_SCHEME_SOURCES.has(o);
|
|
47
|
+
}
|
|
48
|
+
const STYLE = SITE_TOKENS + `
|
|
49
|
+
*{box-sizing:border-box}
|
|
50
|
+
html{-webkit-text-size-adjust:100%}
|
|
51
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.6 var(--sans)}
|
|
52
|
+
a{color:var(--cyan);text-underline-offset:3px}
|
|
53
|
+
:focus-visible{outline:3px solid var(--cyan);outline-offset:3px}
|
|
54
|
+
.page{min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;padding:28px 16px}
|
|
55
|
+
.brand{display:flex;align-items:center;gap:10px;font-weight:600;letter-spacing:.02em}
|
|
56
|
+
.mark{width:10px;height:10px;border-radius:50%;background:var(--gold);box-shadow:0 0 14px var(--gold)}
|
|
57
|
+
main{background:var(--card);border:1px solid var(--line);border-top:3px solid var(--gold);border-radius:16px;padding:30px 28px;max-width:440px;width:100%}
|
|
58
|
+
h1{font:500 clamp(26px,5vw,32px)/1.12 var(--serif);letter-spacing:-.01em;margin:0 0 8px}
|
|
59
|
+
p{margin:10px 0;color:var(--muted)}
|
|
60
|
+
strong{color:var(--ink)}
|
|
61
|
+
.dest{font-size:17px;margin:14px 0 6px;color:var(--muted)}.dest strong{color:var(--cyan);font:600 16px var(--mono);overflow-wrap:anywhere}
|
|
62
|
+
.who{background:var(--sunk);border:1px solid var(--line);border-radius:10px;padding:12px 14px;font-size:14.5px;color:var(--muted);margin:12px 0}.who em{color:var(--dim)}
|
|
63
|
+
.note{font-size:14px;color:var(--dim)}
|
|
64
|
+
.warn{background:var(--warn-bg);border:1px solid var(--warn-line);border-left-width:4px;border-radius:10px;padding:10px 14px;font-size:14.5px;color:var(--warn-ink)}
|
|
65
|
+
.err{background:var(--err-bg);border:1px solid var(--err-line);border-left-width:4px;color:var(--err-ink);border-radius:10px;padding:10px 14px;font-size:14.5px;margin:14px 0}
|
|
66
|
+
button{display:block;margin-top:12px;width:100%;padding:14px 22px;border:1px solid var(--gold);border-radius:999px;background:var(--gold);color:var(--bg);font:600 16px/1 var(--sans);cursor:pointer}
|
|
67
|
+
button:hover{filter:brightness(1.08)}
|
|
68
|
+
button.secondary,button.reject{background:transparent;color:var(--ink);border-color:rgba(255,255,255,.4)}
|
|
69
|
+
button.secondary:hover,button.reject:hover{border-color:var(--ink);filter:none}
|
|
70
|
+
@media (max-width:520px){main{padding:24px 20px}}
|
|
71
|
+
`;
|
|
72
|
+
/** A whole page. `body` must already be escaped; `extraStyle` is a constant stylesheet, never user data. */
|
|
73
|
+
export function shell(title, body, extraStyle = "") {
|
|
74
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">` +
|
|
75
|
+
`<meta name="robots" content="noindex"><title>${esc(title)}</title><style>${STYLE}${extraStyle}</style></head><body><div class="page"><div class="brand"><span class="mark"></span>AgentRecall</div><main>${body}</main></div></body></html>`;
|
|
76
|
+
}
|
|
77
|
+
export function signInPage(v) {
|
|
78
|
+
return shell("Sign in to AgentRecall", `<h1>Sign in to AgentRecall</h1>` +
|
|
79
|
+
`<p class="dest">Sign-in result goes to: <strong>${esc(v.redirectHost)}</strong></p>` +
|
|
80
|
+
(v.destination === "loopback" ? `<p class="warn">This connects a program running on this computer. Only continue if you just started the connection yourself.</p>` : "") +
|
|
81
|
+
(v.destination === "claude" ? `<p class="note">This connects Claude (claude.ai).</p>` : "") +
|
|
82
|
+
`<div class="who">Requested by <strong>${esc(v.clientName)}</strong> <em>(self-reported name, not verified)</em>. ` +
|
|
83
|
+
`It wants read and write access to your AgentRecall memory.</div>` +
|
|
84
|
+
`<p>Choose an account to continue.</p>` +
|
|
85
|
+
(v.error ? `<div class="err" role="alert">${esc(v.error)}</div>` : "") +
|
|
86
|
+
`<form method="post" action="/authorize/start">` +
|
|
87
|
+
`<input type="hidden" name="request_id" value="${esc(v.requestId)}">` +
|
|
88
|
+
v.providers.map((p) => `<button type="submit" name="provider" value="${esc(p.name)}">Continue with ${esc(p.label)}</button>`).join("") +
|
|
89
|
+
`</form>` +
|
|
90
|
+
(v.privacyUrl
|
|
91
|
+
? `<p class="note">Your memory is stored on this server. <a href="${esc(v.privacyUrl)}" rel="noopener noreferrer" target="_blank">Privacy policy</a></p>`
|
|
92
|
+
: ""));
|
|
93
|
+
}
|
|
94
|
+
export function errorPage(message) {
|
|
95
|
+
return shell("AgentRecall sign-in", `<h1>Sign-in problem</h1><div class="err" role="alert">${esc(message)}</div><p>You can close this tab and start again from your app.</p>`);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=oauth-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-pages.js","sourceRoot":"","sources":["../../src/http/oauth-pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,UAAU,GAAG,CAAC,CAAU;IAC5B,OAAO,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QACpB,4CAA4C;SAC3C,OAAO,CAAC,8FAA8F,EAAE,EAAE,CAAC;SAC3G,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,oBAA8C,EAAE;IAC1E,MAAM,KAAK,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,MAAM,UAAU,GAAG,i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,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,kIAAkI,CAAC,CAAC,CAAC,EAAE,CAAC;QACxK,CAAC,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,uDAAuD,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3F,yCAAyC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,yDAAyD;QACnH,kEAAkE;QAClE,uCAAuC;QACvC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,iCAAiC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,gDAAgD;QAChD,iDAAiD,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI;QACrE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gDAAgD,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QACtI,SAAS;QACT,CAAC,CAAC,CAAC,UAAU;YACX,CAAC,CAAC,kEAAkE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,oEAAoE;YACzJ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACb,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,KAAK,CAAC,qBAAqB,EAAE,yDAAyD,GAAG,CAAC,OAAO,CAAC,oEAAoE,CAAC,CAAC;AACjL,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-provider.ts — OAuth 2.1 authorization server logic for the hosted server,
|
|
3
|
+
* as an MCP SDK OAuthServerProvider. Identity is federated: the user proves who they
|
|
4
|
+
* are to GitHub or Google (federation.ts); AgentRecall never sees a password.
|
|
5
|
+
*
|
|
6
|
+
* In memory only (a restart just aborts in-flight sign-ins; clients retry):
|
|
7
|
+
* pending requests 32-byte id, 10 min, single use, bound to a browser cookie
|
|
8
|
+
* upstream states 32 bytes, single use, one live state per pending request
|
|
9
|
+
* authorization codes 32 bytes, 60 s, single use, bound to client+redirect+resource+PKCE challenge
|
|
10
|
+
* Persistent (oauth-store.ts): clients, grants, token hashes.
|
|
11
|
+
*/
|
|
12
|
+
import type { Request, Response } from "express";
|
|
13
|
+
import type { OAuthServerProvider, AuthorizationParams } from "@modelcontextprotocol/sdk/server/auth/provider.js";
|
|
14
|
+
import type { OAuthRegisteredClientsStore } from "@modelcontextprotocol/sdk/server/auth/clients.js";
|
|
15
|
+
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
16
|
+
import type { OAuthClientInformationFull, OAuthTokenRevocationRequest, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
17
|
+
import type { OAuthConfig } from "./oauth-config.js";
|
|
18
|
+
import { OAuthStore } from "./oauth-store.js";
|
|
19
|
+
import { Federation } from "./federation.js";
|
|
20
|
+
export declare const OAUTH_SCOPE = "memory";
|
|
21
|
+
export declare const COOKIE_PREFIX = "ar_oauth_";
|
|
22
|
+
/** Longest client-supplied `state` we accept (it is echoed back in redirects). */
|
|
23
|
+
export declare const MAX_CLIENT_STATE_CHARS = 512;
|
|
24
|
+
/** At most this many provider redirects per sign-in request. */
|
|
25
|
+
export declare const MAX_STARTS_PER_REQUEST = 3;
|
|
26
|
+
export declare const PENDING_TTL_MS: number;
|
|
27
|
+
export declare const CODE_TTL_MS: number;
|
|
28
|
+
export type LoginResult = {
|
|
29
|
+
kind: "redirect";
|
|
30
|
+
location: string;
|
|
31
|
+
clearCookieFor?: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "page";
|
|
34
|
+
status: number;
|
|
35
|
+
html: string;
|
|
36
|
+
csp: string[] | null;
|
|
37
|
+
clearCookieFor?: string;
|
|
38
|
+
};
|
|
39
|
+
export interface ProviderDeps {
|
|
40
|
+
config: OAuthConfig;
|
|
41
|
+
dataDir: string;
|
|
42
|
+
store: OAuthStore;
|
|
43
|
+
federation: Federation;
|
|
44
|
+
/** Test seam: cap on live sign-in requests. */
|
|
45
|
+
maxPending?: number;
|
|
46
|
+
/** Test seam: cap on live sign-in requests per client address. */
|
|
47
|
+
maxPendingPerKey?: number;
|
|
48
|
+
/** Client address bucket for an /authorize request (oauth-app passes the rate-limit IP key). */
|
|
49
|
+
keyOf?: (req: Request) => string;
|
|
50
|
+
log: (line: string) => void;
|
|
51
|
+
now: () => number;
|
|
52
|
+
/** A federated account signed in (after the invite check). serve.ts counts first sign-ins; must not throw. */
|
|
53
|
+
onSignIn?: (uid: string) => void;
|
|
54
|
+
}
|
|
55
|
+
export declare class FederatedOAuthProvider implements OAuthServerProvider {
|
|
56
|
+
private readonly d;
|
|
57
|
+
readonly clientsStore: OAuthRegisteredClientsStore;
|
|
58
|
+
private readonly pending;
|
|
59
|
+
private readonly stateIndex;
|
|
60
|
+
private readonly codes;
|
|
61
|
+
private readonly loggedSubjects;
|
|
62
|
+
private readonly pendingPerKey;
|
|
63
|
+
private readonly maxPendingPerKey;
|
|
64
|
+
private readonly providers;
|
|
65
|
+
private readonly maxPending;
|
|
66
|
+
/** Origins the sign-in page may redirect its form to (the providers' authorize endpoints). */
|
|
67
|
+
readonly formOrigins: string[];
|
|
68
|
+
constructor(d: ProviderDeps);
|
|
69
|
+
/** A stored client keeps only the redirect URIs that still pass the policy; none left → unknown client. */
|
|
70
|
+
private allowedClient;
|
|
71
|
+
/** One cookie per sign-in request, so parallel sign-ins in one browser do not clobber each other. */
|
|
72
|
+
cookieName(requestId: string): string;
|
|
73
|
+
private readCookie;
|
|
74
|
+
/** Set-Cookie value for a request's browser-binding cookie (value null clears it). */
|
|
75
|
+
cookieHeader(requestId: string, value: string | null): string;
|
|
76
|
+
private registerClient;
|
|
77
|
+
authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* form-action for a page that holds the sign-in form. Browsers apply form-action to every redirect that follows
|
|
80
|
+
* the POST, the last hop included: when the provider skips its consent screen (an account that already approved
|
|
81
|
+
* the app), POST /authorize/start → provider → /authorize/callback → the client's redirect_uri is one form
|
|
82
|
+
* navigation, and without the client's target here the browser blocks the final redirect and the code is lost.
|
|
83
|
+
* null (no form-action at all) for an IPv6-literal callback, which no CSP source can name. That page still has
|
|
84
|
+
* default-src 'none' (no script), escaped values and one form, posting to this server.
|
|
85
|
+
*/
|
|
86
|
+
private formOriginsFor;
|
|
87
|
+
private signIn;
|
|
88
|
+
private evictExpiredPending;
|
|
89
|
+
/** Live sign-in requests held by one client address (expired ones are dropped first when it looks full). */
|
|
90
|
+
private livePendingFor;
|
|
91
|
+
/** null when full of LIVE sign-ins: expired ones are evicted, live ones never are (no FIFO eviction). */
|
|
92
|
+
private createPending;
|
|
93
|
+
private dropPending;
|
|
94
|
+
private getPending;
|
|
95
|
+
/** Does a live sign-in request with this id exist? (Lets the app spend the global budget only on real requests.) */
|
|
96
|
+
hasPending(id: unknown): boolean;
|
|
97
|
+
/** Live request that may still be sent to a provider (the app spends the global budget only for these). */
|
|
98
|
+
canStart(id: unknown): boolean;
|
|
99
|
+
/** Is this upstream state one we issued and have not consumed? */
|
|
100
|
+
hasState(state: unknown): boolean;
|
|
101
|
+
private cookieMatches;
|
|
102
|
+
private dead;
|
|
103
|
+
private retryPage;
|
|
104
|
+
/** The user chose a provider: bind a fresh upstream state to the pending request and send them there. */
|
|
105
|
+
start(f: {
|
|
106
|
+
requestId: unknown;
|
|
107
|
+
provider: unknown;
|
|
108
|
+
cookies: string | undefined;
|
|
109
|
+
}): LoginResult;
|
|
110
|
+
callback(f: {
|
|
111
|
+
provider: string;
|
|
112
|
+
state: unknown;
|
|
113
|
+
code: unknown;
|
|
114
|
+
error: unknown;
|
|
115
|
+
cookies: string | undefined;
|
|
116
|
+
}): Promise<LoginResult>;
|
|
117
|
+
private issueCode;
|
|
118
|
+
challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise<string>;
|
|
119
|
+
exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, _codeVerifier?: string, redirectUri?: string, resource?: URL): Promise<OAuthTokens>;
|
|
120
|
+
exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, _scopes?: string[], resource?: URL): Promise<OAuthTokens>;
|
|
121
|
+
revokeToken(client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest): Promise<void>;
|
|
122
|
+
verifyAccessToken(token: string): Promise<AuthInfo>;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=oauth-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../src/http/oauth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAClH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,KAAK,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAKrI,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAmD,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAuE,MAAM,iBAAiB,CAAC;AAIlH,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC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