@feltdb/feltkit 0.3.27 → 0.3.29
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/dist/app.d.ts +50 -7
- package/dist/app.js +21 -0
- package/dist/app.js.map +1 -1
- package/dist/cli/deploy-appboundry.d.ts +55 -0
- package/dist/cli/deploy-appboundry.js +77 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/main.js +229 -10
- package/dist/cli/main.js.map +1 -1
- package/dist/dashboard/assets/{index-Clsfddp8.js → index-UuZ63NA6.js} +9 -9
- package/dist/dashboard/index.html +1 -1
- package/dist/runtime/application-authority.d.ts +9 -1
- package/dist/runtime/application-authority.js +7 -1
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/contract.js +4 -0
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/credentials.d.ts +158 -2
- package/dist/runtime/credentials.js +322 -27
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/integrations.d.ts +18 -2
- package/dist/runtime/integrations.js +59 -8
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/oauth-credentials.d.ts +68 -0
- package/dist/runtime/oauth-credentials.js +467 -0
- package/dist/runtime/oauth-credentials.js.map +1 -0
- package/dist/runtime/readiness.js +22 -0
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +3 -0
- package/dist/runtime/runtime.js +19 -3
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +12 -0
- package/dist/runtime/services.js +28 -0
- package/dist/runtime/services.js.map +1 -1
- package/dist/server/admin.d.ts +3 -0
- package/dist/server/admin.js +151 -6
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.js +26 -0
- package/dist/server/index.js.map +1 -1
- package/docs/README.md +2 -2
- package/package.json +2 -2
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth 2.0 grants for integrations: FeltKit keeps an integration's access token current, so the
|
|
3
|
+
* application declares the integration and calls it, and never holds a token.
|
|
4
|
+
*
|
|
5
|
+
* app.integration("x", { baseUrl, credential: { ref: "credential-ref:x", oauth2: { tokenUrl, clientId, … } }, … })
|
|
6
|
+
*
|
|
7
|
+
* The grant lives in FeltKit's custody (runtime/credentials.ts), encrypted in the environment's vault,
|
|
8
|
+
* as one entry of kind "oauth2": access token, refresh token, expiry, scope, lifecycle state, the last
|
|
9
|
+
* failure. Application code has no read of it: `withSecret` refuses a grant, and the only things that
|
|
10
|
+
* use it are this module and the integration call (runtime/integrations.ts), which receives an access
|
|
11
|
+
* token for the one request it sends.
|
|
12
|
+
*
|
|
13
|
+
* Getting a grant:
|
|
14
|
+
* connect `feltkit credential connect <integration>` (or Studio): authorization code with PKCE
|
|
15
|
+
* (S256). A person holding `credential.store` starts it; the provider sends them back to
|
|
16
|
+
* /api/integrations/<name>/oauth/callback, which checks the single-use state, asks again
|
|
17
|
+
* whether that person may store credentials, exchanges the code, and stores the grant
|
|
18
|
+
* through AppPort Services' credential.store, as that person.
|
|
19
|
+
* import `feltkit credential set <ref> --oauth` with the provider's token response on stdin.
|
|
20
|
+
*
|
|
21
|
+
* Keeping it current (deterministic; no model involved):
|
|
22
|
+
* - a token that is not near expiry is used as it is;
|
|
23
|
+
* - one that expires within `refreshBeforeSeconds` (default 120) is renewed before the request;
|
|
24
|
+
* - one whose expiry the provider never stated is used until the API refuses it (401): then it is
|
|
25
|
+
* renewed once and the request sent once more (a 401 is a refusal before any effect, RFC 6750 §3.1);
|
|
26
|
+
* - a renewal is serialized: one at a time per grant in this process (single flight), and across
|
|
27
|
+
* processes sharing the vault (a lock file next to it); whoever waited re-reads the grant and uses
|
|
28
|
+
* the renewed token instead of renewing again;
|
|
29
|
+
* - the replacement is written atomically, and only over the grant it was renewed from (version
|
|
30
|
+
* check): a newer grant (a reconnect) is never overwritten by an older renewal;
|
|
31
|
+
* - a refresh token the provider returns replaces the old one; when it returns none, the old one is
|
|
32
|
+
* kept (RFC 6749 §6). Whether a provider rotates is never assumed.
|
|
33
|
+
*
|
|
34
|
+
* Failures, classified and recorded on the grant (kind, time, a message without provider text):
|
|
35
|
+
* transient network, timeout, 5xx, an unreadable answer: the grant is unchanged; the caller may retry
|
|
36
|
+
* rate_limited 429: no request to the provider until its Retry-After (default 60 s) has passed
|
|
37
|
+
* invalid_grant the refresh token is invalid, expired or revoked: reconnect_required
|
|
38
|
+
* rejected any other refusal of the grant (unauthorized_client, invalid_scope, …): reconnect_required
|
|
39
|
+
* no_refresh_token expired, and nothing to renew it with: reconnect_required
|
|
40
|
+
* client_rejected the client's own credentials were refused (invalid_client): a configuration problem,
|
|
41
|
+
* the grant stays as it was
|
|
42
|
+
* unauthorized_after_refresh the API refused a token just renewed: the call fails, nothing loops
|
|
43
|
+
*
|
|
44
|
+
* Disconnecting (`feltkit credential remove`) asks the provider to revoke both tokens (RFC 7009), when
|
|
45
|
+
* it declares a revocation endpoint, then erases the grant here whatever the provider answered.
|
|
46
|
+
*
|
|
47
|
+
* A process that dies during a renewal leaves the last stored grant as it was (nothing is written
|
|
48
|
+
* before the provider answers) and a lock file that expires. If the provider had already rotated the
|
|
49
|
+
* refresh token, the next renewal is answered invalid_grant and the grant asks to be reconnected: it
|
|
50
|
+
* never silently goes on with a token that cannot work.
|
|
51
|
+
*
|
|
52
|
+
* Every lifecycle event (connected, renewed, failed, disconnected) is activity, with the reference,
|
|
53
|
+
* version and classification, never a token, a header, a request body or the provider's response.
|
|
54
|
+
*/
|
|
55
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
56
|
+
import { FeltKitError } from "../errors.js";
|
|
57
|
+
import { systemPrincipal } from "./authority.js";
|
|
58
|
+
import { credentialId, OAUTH2_KIND, parseGrant } from "./credentials.js";
|
|
59
|
+
const DEFAULT_SKEW_S = 120;
|
|
60
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
61
|
+
const DEFAULT_RETRY_AFTER_MS = 60_000;
|
|
62
|
+
const CONNECT_TTL_MS = 10 * 60_000;
|
|
63
|
+
const REFRESHER = systemPrincipal("oauth-refresh", "custody");
|
|
64
|
+
const b64 = (b) => b.toString("base64url");
|
|
65
|
+
export class OAuthCredentials {
|
|
66
|
+
#runtime;
|
|
67
|
+
#inflight = new Map();
|
|
68
|
+
/** Connections in progress, by state. Single use; in memory (a restart means starting again). */
|
|
69
|
+
#pending = new Map();
|
|
70
|
+
constructor(runtime) {
|
|
71
|
+
this.#runtime = runtime;
|
|
72
|
+
}
|
|
73
|
+
/** The integration's OAuth client as configured in this environment, or what is missing. */
|
|
74
|
+
client(integration) {
|
|
75
|
+
const cred = integration.credential;
|
|
76
|
+
const oauth2 = typeof cred === "object" ? cred.oauth2 : undefined;
|
|
77
|
+
if (!oauth2 || typeof cred !== "object")
|
|
78
|
+
return { client: null, problems: [] };
|
|
79
|
+
const problems = [];
|
|
80
|
+
const value = (what, c, required) => {
|
|
81
|
+
if (c === undefined)
|
|
82
|
+
return null;
|
|
83
|
+
const v = this.#runtime.integrations.resolve(c).value;
|
|
84
|
+
if (!v && required && typeof c !== "string")
|
|
85
|
+
problems.push({ message: `${integration.name}: ${c.env} (the OAuth ${what}) is not set in the ${this.#runtime.environment.name} environment.`, fix: `Set ${c.env} (Studio → Services → Configuration, or the host's environment).` });
|
|
86
|
+
return v;
|
|
87
|
+
};
|
|
88
|
+
const tokenUrl = value("token endpoint", oauth2.tokenUrl, true);
|
|
89
|
+
const clientId = value("client id", oauth2.clientId, true);
|
|
90
|
+
const authorizeUrl = value("authorization endpoint", oauth2.authorizeUrl, false);
|
|
91
|
+
const revokeUrl = value("revocation endpoint", oauth2.revokeUrl, false);
|
|
92
|
+
for (const [what, url] of [["token endpoint", tokenUrl], ["authorization endpoint", authorizeUrl], ["revocation endpoint", revokeUrl]]) {
|
|
93
|
+
if (!url)
|
|
94
|
+
continue;
|
|
95
|
+
try {
|
|
96
|
+
const u = new URL(url);
|
|
97
|
+
if (this.#runtime.environment.production && u.protocol !== "https:")
|
|
98
|
+
problems.push({ message: `${integration.name}: the OAuth ${what} ${u.origin} is not HTTPS.`, fix: "Use the provider's HTTPS endpoint in production." });
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
problems.push({ message: `${integration.name}: the OAuth ${what} "${url}" is not a URL.`, fix: "Correct it." });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const id = credentialId(cred.ref);
|
|
105
|
+
if (oauth2.clientSecret && !this.#runtime.credentials.describe(oauth2.clientSecret).present) {
|
|
106
|
+
problems.push({ message: `${integration.name}: the OAuth client secret ${oauth2.clientSecret} is not set.`, fix: `Run \`feltkit credential set ${oauth2.clientSecret}\`, or set ${this.#runtime.credentials.describe(oauth2.clientSecret).variable}.` });
|
|
107
|
+
}
|
|
108
|
+
if (!tokenUrl || !clientId)
|
|
109
|
+
return { client: null, problems };
|
|
110
|
+
return {
|
|
111
|
+
client: {
|
|
112
|
+
integration: integration.name, ref: `credential-ref:${id}`, id, tokenUrl, authorizeUrl, revokeUrl, clientId, clientSecretRef: oauth2.clientSecret ?? null,
|
|
113
|
+
clientAuthentication: oauth2.clientAuthentication ?? "basic", scopes: oauth2.scopes ?? [], skewMs: (oauth2.refreshBeforeSeconds ?? DEFAULT_SKEW_S) * 1000, timeoutMs: oauth2.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
114
|
+
},
|
|
115
|
+
problems,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Why the grant can't be used here (or kept current), naming the fix; [] when it can. */
|
|
119
|
+
problems(integration) {
|
|
120
|
+
const { client, problems } = this.client(integration);
|
|
121
|
+
if (!client)
|
|
122
|
+
return problems;
|
|
123
|
+
const custody = this.#runtime.credentials;
|
|
124
|
+
const d = custody.describe(client.ref);
|
|
125
|
+
if (d.source === "environment") {
|
|
126
|
+
problems.push({ message: `${integration.name}: ${client.ref} is an OAuth 2.0 grant, which FeltKit renews and stores; it can't come from ${d.variable}.`, fix: `Unset ${d.variable}, then run \`feltkit credential connect ${integration.name}\`.` });
|
|
127
|
+
}
|
|
128
|
+
else if (!custody.writable) {
|
|
129
|
+
problems.push({ message: `${integration.name}: ${client.ref} is an OAuth 2.0 grant, and this environment's credential custody can't store (renewed tokens could not be kept).`, fix: "Opt in to the vault: FELTKIT_CREDENTIAL_VAULT=1 with FELTKIT_CREDENTIAL_VAULT_KEY." });
|
|
130
|
+
}
|
|
131
|
+
else if (d.state !== "set" || (d.kind && d.kind !== OAUTH2_KIND)) {
|
|
132
|
+
problems.push({ message: `${integration.name}: ${client.ref} is not connected${d.state === "revoked" ? " (disconnected)" : d.kind && d.kind !== OAUTH2_KIND ? " (it holds a plain value, not an OAuth 2.0 grant)" : ""}.`, fix: `Run \`feltkit credential connect ${integration.name}\`${client.authorizeUrl ? "" : " (or import a token response: `feltkit credential set " + client.ref + " --oauth`)"}.` });
|
|
133
|
+
}
|
|
134
|
+
else if (!d.kind) {
|
|
135
|
+
problems.push({ message: `${integration.name}: ${client.ref} holds a plain value, not an OAuth 2.0 grant.`, fix: `Run \`feltkit credential connect ${integration.name}\`.` });
|
|
136
|
+
}
|
|
137
|
+
else if (d.oauth?.state === "reconnect_required") {
|
|
138
|
+
problems.push({ message: `${integration.name}: ${client.ref} must be connected again (${d.oauth.failure?.message ?? "the grant can no longer be renewed"}).`, fix: `Run \`feltkit credential connect ${integration.name}\`.` });
|
|
139
|
+
}
|
|
140
|
+
return problems;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A usable access token for one request. `rejected`: the token the API just refused (401): renew
|
|
144
|
+
* it unless someone already has.
|
|
145
|
+
*/
|
|
146
|
+
async accessToken(integration, options = {}) {
|
|
147
|
+
const { client, problems } = this.client(integration);
|
|
148
|
+
if (!client)
|
|
149
|
+
throw new FeltKitError("CONFIGURATION", problems.map((p) => p.message).join(" ") || `${integration.name} has no OAuth 2.0 client.`, { hint: problems.map((p) => p.fix).join(" ") });
|
|
150
|
+
const current = await this.#grant(client, integration);
|
|
151
|
+
if (!this.#needsRenewal(current.grant, client, options.rejected))
|
|
152
|
+
return { token: current.grant.accessToken, renewed: false };
|
|
153
|
+
let flight = this.#inflight.get(client.id);
|
|
154
|
+
if (!flight) {
|
|
155
|
+
flight = this.#renew(client, integration, options.rejected).finally(() => this.#inflight.delete(client.id));
|
|
156
|
+
this.#inflight.set(client.id, flight);
|
|
157
|
+
}
|
|
158
|
+
return { token: await flight, renewed: true };
|
|
159
|
+
}
|
|
160
|
+
/** The API refused a token that was just renewed: recorded, so the call fails without looping. */
|
|
161
|
+
async rejectedAfterRenewal(integration) {
|
|
162
|
+
const { client } = this.client(integration);
|
|
163
|
+
if (!client)
|
|
164
|
+
return;
|
|
165
|
+
const current = await this.#runtime.credentials.grantOf(client.id);
|
|
166
|
+
if (!current)
|
|
167
|
+
return;
|
|
168
|
+
await await this.#mark(client, current, { kind: "unauthorized_after_refresh", at: Date.now(), message: "The API refused an access token that had just been renewed (HTTP 401). Check the grant's scopes and the client's access." }, false);
|
|
169
|
+
}
|
|
170
|
+
async #grant(client, integration) {
|
|
171
|
+
const current = await this.#runtime.credentials.grantOf(client.id);
|
|
172
|
+
if (!current) {
|
|
173
|
+
const p = this.problems(integration);
|
|
174
|
+
throw new FeltKitError("CONFIGURATION", p.map((x) => x.message).join(" ") || `${client.ref} is not connected.`, { hint: p.map((x) => x.fix).join(" ") || `Run \`feltkit credential connect ${integration.name}\`.` });
|
|
175
|
+
}
|
|
176
|
+
if (current.grant.state !== "active")
|
|
177
|
+
throw reconnect(client, current.grant.failure?.message ?? "the grant can no longer be renewed");
|
|
178
|
+
return current;
|
|
179
|
+
}
|
|
180
|
+
#needsRenewal(grant, client, rejected) {
|
|
181
|
+
if (rejected !== undefined)
|
|
182
|
+
return grant.accessToken === rejected;
|
|
183
|
+
return grant.expiresAt !== null && grant.expiresAt - client.skewMs <= Date.now();
|
|
184
|
+
}
|
|
185
|
+
async #renew(client, integration, rejected) {
|
|
186
|
+
const release = await this.#lock(client);
|
|
187
|
+
try {
|
|
188
|
+
// Under the lock: another request (or process) may have renewed it while this one waited.
|
|
189
|
+
const current = await this.#grant(client, integration);
|
|
190
|
+
if (!this.#needsRenewal(current.grant, client, rejected))
|
|
191
|
+
return current.grant.accessToken;
|
|
192
|
+
const failure = current.grant.failure;
|
|
193
|
+
if (failure?.kind === "rate_limited" && failure.retryAt && failure.retryAt > Date.now()) {
|
|
194
|
+
throw new FeltKitError("RATE_LIMITED", `${client.integration}: the provider asked to wait before renewing the token again (until ${new Date(failure.retryAt).toISOString()}).`, { details: { retryAfterMs: failure.retryAt - Date.now() } });
|
|
195
|
+
}
|
|
196
|
+
if (!current.grant.refreshToken) {
|
|
197
|
+
await this.#mark(client, current, { kind: "no_refresh_token", at: Date.now(), message: "The access token expired and the provider issued no refresh token (ask for offline access when connecting)." }, true);
|
|
198
|
+
throw reconnect(client, "the access token expired and there is no refresh token");
|
|
199
|
+
}
|
|
200
|
+
const started = Date.now();
|
|
201
|
+
const answer = await this.#tokenRequest(client, { grant_type: "refresh_token", refresh_token: current.grant.refreshToken });
|
|
202
|
+
if (answer.ok) {
|
|
203
|
+
const fresh = parseGrant(JSON.stringify(answer.body));
|
|
204
|
+
const rotated = Boolean(fresh.refreshToken) && fresh.refreshToken !== current.grant.refreshToken;
|
|
205
|
+
const next = {
|
|
206
|
+
...current.grant,
|
|
207
|
+
accessToken: fresh.accessToken,
|
|
208
|
+
// RFC 6749 §6: a new refresh token replaces the old; none returned means the old one stays valid.
|
|
209
|
+
refreshToken: fresh.refreshToken ?? current.grant.refreshToken,
|
|
210
|
+
tokenType: fresh.tokenType,
|
|
211
|
+
scope: fresh.scope ?? current.grant.scope,
|
|
212
|
+
expiresAt: fresh.expiresAt,
|
|
213
|
+
refreshedAt: Date.now(),
|
|
214
|
+
refreshes: current.grant.refreshes + 1,
|
|
215
|
+
failure: null,
|
|
216
|
+
state: "active",
|
|
217
|
+
};
|
|
218
|
+
const version = await this.#runtime.credentials.replaceGrant(client.id, current.version, next);
|
|
219
|
+
if (version === null) {
|
|
220
|
+
// Replaced meanwhile (a reconnect): the newer grant stands; this renewal is discarded.
|
|
221
|
+
this.#record(client, "credential.refresh", "error", started, { outcome: "superseded" });
|
|
222
|
+
return (await this.#grant(client, integration)).grant.accessToken;
|
|
223
|
+
}
|
|
224
|
+
this.#record(client, "credential.refresh", "success", started, { version, rotated, expiry: next.expiresAt ? new Date(next.expiresAt).toISOString() : "unknown" });
|
|
225
|
+
return next.accessToken;
|
|
226
|
+
}
|
|
227
|
+
const ends = answer.kind === "invalid_grant" || answer.kind === "rejected";
|
|
228
|
+
await this.#mark(client, current, { kind: answer.kind, at: Date.now(), message: answer.message, ...(answer.retryAt ? { retryAt: answer.retryAt } : {}) }, ends);
|
|
229
|
+
this.#record(client, "credential.refresh", "error", started, { failure: answer.kind, ...(ends ? { state: "reconnect_required" } : {}) });
|
|
230
|
+
if (ends)
|
|
231
|
+
throw reconnect(client, answer.message);
|
|
232
|
+
if (answer.kind === "rate_limited")
|
|
233
|
+
throw new FeltKitError("RATE_LIMITED", `${client.integration}: ${answer.message}`, { details: { retryAfterMs: Math.max(0, (answer.retryAt ?? Date.now()) - Date.now()) } });
|
|
234
|
+
if (answer.kind === "client_rejected")
|
|
235
|
+
throw new FeltKitError("CONFIGURATION", `${client.integration}: ${answer.message}`, { hint: `Check the OAuth client id and ${client.clientSecretRef ?? "client authentication"}.` });
|
|
236
|
+
throw new FeltKitError("UNAVAILABLE", `${client.integration}: renewing the access token failed (${answer.message}); the grant is unchanged. Try again.`);
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
await release();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Record a failure on the grant, if it is still the one that failed. */
|
|
243
|
+
async #mark(client, current, failure, ends) {
|
|
244
|
+
try {
|
|
245
|
+
await this.#runtime.credentials.replaceGrant(client.id, current.version, { ...current.grant, failure, ...(ends ? { state: "reconnect_required" } : {}) });
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
this.#runtime.logger.warn(`oauth: could not record ${client.ref}'s failure: ${error.message}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** POST to the token endpoint (form-encoded, RFC 6749 §4.1.3 / §6), with the client's authentication. Classified; no provider text kept. */
|
|
252
|
+
async #tokenRequest(client, params) {
|
|
253
|
+
const body = new URLSearchParams(params);
|
|
254
|
+
const headers = { "content-type": "application/x-www-form-urlencoded", accept: "application/json" };
|
|
255
|
+
const secret = client.clientSecretRef ? await this.#runtime.credentials.withSecret({ reference: { secretId: client.clientSecretRef.slice("credential-ref:".length) }, context: { purpose: `${client.integration} token request` } }, (s) => s.value) : null;
|
|
256
|
+
if (secret && client.clientAuthentication === "basic") {
|
|
257
|
+
// RFC 6749 §2.3.1: client id and secret, each form-urlencoded, as HTTP Basic credentials.
|
|
258
|
+
headers.authorization = `Basic ${Buffer.from(`${encodeURIComponent(client.clientId)}:${encodeURIComponent(secret)}`).toString("base64")}`;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
body.set("client_id", client.clientId);
|
|
262
|
+
if (secret)
|
|
263
|
+
body.set("client_secret", secret);
|
|
264
|
+
}
|
|
265
|
+
let response;
|
|
266
|
+
try {
|
|
267
|
+
response = await fetch(client.tokenUrl, { method: "POST", headers, body: body.toString(), signal: AbortSignal.timeout(client.timeoutMs), redirect: "error" });
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
const timedOut = error?.name === "TimeoutError";
|
|
271
|
+
return { ok: false, kind: "transient", message: timedOut ? `the token endpoint did not answer within ${client.timeoutMs} ms` : "the token endpoint could not be reached" };
|
|
272
|
+
}
|
|
273
|
+
let parsed = null;
|
|
274
|
+
try {
|
|
275
|
+
parsed = (await response.json());
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
parsed = null;
|
|
279
|
+
}
|
|
280
|
+
if (response.ok) {
|
|
281
|
+
if (parsed && typeof parsed.access_token === "string" && parsed.access_token)
|
|
282
|
+
return { ok: true, body: parsed };
|
|
283
|
+
return { ok: false, kind: "transient", message: `the token endpoint answered ${response.status} without an access token` };
|
|
284
|
+
}
|
|
285
|
+
// Only the standard error code is kept (RFC 6749 §5.2), never the description or body.
|
|
286
|
+
const code = parsed && typeof parsed.error === "string" && /^[a-z_]{1,40}$/.test(parsed.error) ? parsed.error : null;
|
|
287
|
+
if (response.status === 429)
|
|
288
|
+
return { ok: false, kind: "rate_limited", message: "the token endpoint is rate limiting (429)", retryAt: Date.now() + retryAfter(response.headers.get("retry-after")) };
|
|
289
|
+
if (response.status >= 500 || response.status === 408)
|
|
290
|
+
return { ok: false, kind: "transient", message: `the token endpoint answered ${response.status}` };
|
|
291
|
+
if (code === "invalid_grant")
|
|
292
|
+
return { ok: false, kind: "invalid_grant", message: "the provider refused the refresh token (invalid_grant: expired, revoked, or already used)" };
|
|
293
|
+
if (code === "invalid_client" || (response.status === 401 && !code))
|
|
294
|
+
return { ok: false, kind: "client_rejected", message: `the provider refused the client's credentials (${code ?? "401"})` };
|
|
295
|
+
return { ok: false, kind: "rejected", message: `the provider refused to renew the grant (${code ?? response.status})` };
|
|
296
|
+
}
|
|
297
|
+
// ── Connecting: authorization code with PKCE ───────────────────────────────────────────────
|
|
298
|
+
/**
|
|
299
|
+
* Begin connecting an integration's grant, for a person who may store credentials. Returns the
|
|
300
|
+
* provider's authorization URL to open; the provider returns to /api/integrations/<name>/oauth/callback.
|
|
301
|
+
*/
|
|
302
|
+
async connect(integrationName, principal, via) {
|
|
303
|
+
await this.#runtime.integrations.refreshConfiguration();
|
|
304
|
+
const integration = this.#integration(integrationName);
|
|
305
|
+
const { client, problems } = this.client(integration);
|
|
306
|
+
if (!client)
|
|
307
|
+
throw new FeltKitError("CONFIGURATION", problems.map((p) => p.message).join(" ") || `${integrationName} has no OAuth 2.0 client.`);
|
|
308
|
+
if (!client.authorizeUrl)
|
|
309
|
+
throw new FeltKitError("FAILED_PRECONDITION", `${integrationName} declares no authorization endpoint (credential.oauth2.authorizeUrl); import a token response with \`feltkit credential set ${client.ref} --oauth\`.`);
|
|
310
|
+
await this.#authorize(principal, via, client);
|
|
311
|
+
const custody = this.#runtime.credentials;
|
|
312
|
+
const readOnly = custody.readOnlyReason(client.ref);
|
|
313
|
+
if (readOnly)
|
|
314
|
+
throw new FeltKitError("CUSTODY_READ_ONLY", readOnly);
|
|
315
|
+
const now = Date.now();
|
|
316
|
+
for (const [k, p] of this.#pending)
|
|
317
|
+
if (p.expiresAt < now)
|
|
318
|
+
this.#pending.delete(k);
|
|
319
|
+
const state = b64(randomBytes(32));
|
|
320
|
+
const verifier = b64(randomBytes(32));
|
|
321
|
+
const redirectUri = `${this.#runtime.publicUrl()}/api/integrations/${integration.name}/oauth/callback`;
|
|
322
|
+
this.#pending.set(state, { integration: integration.name, verifier, principal, redirectUri, expiresAt: now + CONNECT_TTL_MS });
|
|
323
|
+
const url = new URL(client.authorizeUrl);
|
|
324
|
+
url.searchParams.set("response_type", "code");
|
|
325
|
+
url.searchParams.set("client_id", client.clientId);
|
|
326
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
327
|
+
if (client.scopes.length)
|
|
328
|
+
url.searchParams.set("scope", client.scopes.join(" "));
|
|
329
|
+
url.searchParams.set("state", state);
|
|
330
|
+
url.searchParams.set("code_challenge", b64(createHash("sha256").update(verifier).digest()));
|
|
331
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
332
|
+
this.#record(client, "credential.connect", "success", now, { step: "started", by: principal.id });
|
|
333
|
+
return { url: url.toString(), redirectUri, expiresAt: new Date(now + CONNECT_TTL_MS).toISOString() };
|
|
334
|
+
}
|
|
335
|
+
/** The provider sent the person back: check the state, exchange the code, store the grant as that person. */
|
|
336
|
+
async complete(integrationName, params) {
|
|
337
|
+
const state = params.get("state") ?? "";
|
|
338
|
+
const pending = this.#pending.get(state);
|
|
339
|
+
this.#pending.delete(state);
|
|
340
|
+
if (!pending || pending.integration !== integrationName || pending.expiresAt < Date.now())
|
|
341
|
+
throw new FeltKitError("UNAUTHORIZED", "This connection expired, was already used, or was not started here. Start it again.");
|
|
342
|
+
await this.#runtime.integrations.refreshConfiguration();
|
|
343
|
+
const integration = this.#integration(integrationName);
|
|
344
|
+
const { client } = this.client(integration);
|
|
345
|
+
if (!client)
|
|
346
|
+
throw new FeltKitError("CONFIGURATION", `${integrationName} has no OAuth 2.0 client.`);
|
|
347
|
+
if (params.get("error"))
|
|
348
|
+
throw new FeltKitError("UNAUTHORIZED", `The provider did not grant access (${(params.get("error") ?? "").replace(/[^a-z_]/g, "").slice(0, 40)}).`);
|
|
349
|
+
const code = params.get("code");
|
|
350
|
+
if (!code)
|
|
351
|
+
throw new FeltKitError("UNAUTHORIZED", "The provider returned no authorization code.");
|
|
352
|
+
// Authority when it takes effect: the person who started it must still be allowed to store credentials.
|
|
353
|
+
// (FeltKit's own host principal, `feltkit credential connect` on this host, is not a stored identity.)
|
|
354
|
+
const principal = pending.principal.id.startsWith("feltkit:") ? pending.principal : await this.#runtime.resolvePrincipal(pending.principal.id, { devUsers: true });
|
|
355
|
+
if (!principal)
|
|
356
|
+
throw new FeltKitError("FORBIDDEN", "The person who started this connection is no longer known.");
|
|
357
|
+
await this.#authorize(principal, "oauth-callback", client);
|
|
358
|
+
const started = Date.now();
|
|
359
|
+
const answer = await this.#tokenRequest(client, { grant_type: "authorization_code", code, redirect_uri: pending.redirectUri, code_verifier: pending.verifier });
|
|
360
|
+
if (!answer.ok) {
|
|
361
|
+
this.#record(client, "credential.connect", "error", started, { step: "token", failure: answer.kind });
|
|
362
|
+
throw new FeltKitError(answer.kind === "transient" ? "UNAVAILABLE" : "UNAUTHORIZED", `Connecting ${integrationName} failed: ${answer.message}.`);
|
|
363
|
+
}
|
|
364
|
+
const material = JSON.stringify({ ...answer.body, source: "authorization_code" });
|
|
365
|
+
const stored = await this.#runtime.services.storeCredential({ ref: client.ref, value: material, kind: OAUTH2_KIND, provider: integration.name }, principal);
|
|
366
|
+
this.#record(client, "credential.connect", "success", started, { step: "stored", version: stored.version, by: principal.id, renewable: typeof answer.body.refresh_token === "string" });
|
|
367
|
+
return { ref: client.ref, version: stored.version };
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Disconnect: ask the provider to revoke the tokens (RFC 7009), when it declares how, then the grant
|
|
371
|
+
* is erased here (by the caller, runtime custody's remove) whatever the provider answered.
|
|
372
|
+
*/
|
|
373
|
+
async revokeAtProvider(ref) {
|
|
374
|
+
const integration = this.definitions().find((i) => typeof i.credential === "object" && i.credential.oauth2 && credentialId(i.credential.ref) === credentialId(ref));
|
|
375
|
+
if (!integration)
|
|
376
|
+
return { revoked: "not-oauth" };
|
|
377
|
+
const { client } = this.client(integration);
|
|
378
|
+
const current = client ? await this.#runtime.credentials.grantOf(client.id) : null;
|
|
379
|
+
if (!client || !current)
|
|
380
|
+
return { revoked: "not-oauth" };
|
|
381
|
+
if (!client.revokeUrl) {
|
|
382
|
+
this.#record(client, "credential.revoke", "success", Date.now(), { provider: "no revocation endpoint declared" });
|
|
383
|
+
return { revoked: "no-endpoint" };
|
|
384
|
+
}
|
|
385
|
+
const started = Date.now();
|
|
386
|
+
let ok = true;
|
|
387
|
+
for (const [token, hint] of [[current.grant.refreshToken, "refresh_token"], [current.grant.accessToken, "access_token"]]) {
|
|
388
|
+
if (!token)
|
|
389
|
+
continue;
|
|
390
|
+
const answer = await this.#revokeRequest(client, token, hint);
|
|
391
|
+
ok &&= answer;
|
|
392
|
+
}
|
|
393
|
+
this.#record(client, "credential.revoke", ok ? "success" : "error", started, { provider: ok ? "revoked" : "the provider did not confirm" });
|
|
394
|
+
return { revoked: ok ? "yes" : "failed" };
|
|
395
|
+
}
|
|
396
|
+
async #revokeRequest(client, token, hint) {
|
|
397
|
+
const body = new URLSearchParams({ token, token_type_hint: hint });
|
|
398
|
+
const headers = { "content-type": "application/x-www-form-urlencoded", accept: "application/json" };
|
|
399
|
+
const secret = client.clientSecretRef ? await this.#runtime.credentials.withSecret({ reference: { secretId: client.clientSecretRef.slice("credential-ref:".length) }, context: { purpose: `${client.integration} revocation` } }, (s) => s.value).catch(() => null) : null;
|
|
400
|
+
if (secret && client.clientAuthentication === "basic")
|
|
401
|
+
headers.authorization = `Basic ${Buffer.from(`${encodeURIComponent(client.clientId)}:${encodeURIComponent(secret)}`).toString("base64")}`;
|
|
402
|
+
else {
|
|
403
|
+
body.set("client_id", client.clientId);
|
|
404
|
+
if (secret)
|
|
405
|
+
body.set("client_secret", secret);
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const response = await fetch(client.revokeUrl, { method: "POST", headers, body: body.toString(), signal: AbortSignal.timeout(client.timeoutMs), redirect: "error" });
|
|
409
|
+
await response.arrayBuffer().catch(() => undefined);
|
|
410
|
+
return response.ok;
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
definitions() {
|
|
417
|
+
return this.#runtime.integrations.definitions();
|
|
418
|
+
}
|
|
419
|
+
#integration(name) {
|
|
420
|
+
const integration = this.#runtime.app.integrations.get(name);
|
|
421
|
+
if (!integration || typeof integration.credential !== "object" || !integration.credential.oauth2)
|
|
422
|
+
throw new FeltKitError("NOT_FOUND", `No integration "${name}" with an OAuth 2.0 credential.`);
|
|
423
|
+
return integration;
|
|
424
|
+
}
|
|
425
|
+
async #authorize(principal, via, client) {
|
|
426
|
+
const decision = await this.#runtime.authority.authorize({ access: "credential.store", principal, target: { name: "credential.connect" }, transport: via });
|
|
427
|
+
if (!decision.allowed) {
|
|
428
|
+
this.#record(client, "credential.connect", "denied", Date.now(), { by: principal.id });
|
|
429
|
+
throw new FeltKitError("FORBIDDEN", `${principal.id} may not connect credentials (credential.store).`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/** Activity without material: the reference, the integration, and what happened. */
|
|
433
|
+
#record(client, name, outcome, started, detail) {
|
|
434
|
+
this.#runtime.activity.record({
|
|
435
|
+
kind: "service", name, via: "runtime", requestId: `req_${randomBytes(8).toString("hex")}`,
|
|
436
|
+
principal: { id: REFRESHER.id, type: REFRESHER.type, roles: [] }, outcome, durationMs: Date.now() - started,
|
|
437
|
+
detail: { ref: client.ref, integration: client.integration, ...detail },
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* One renewal at a time across every process sharing the vault (a lock file next to a file vault; a
|
|
442
|
+
* lease record in a database vault). A holder that died loses it after twice the request's timeout.
|
|
443
|
+
*/
|
|
444
|
+
async #lock(client) {
|
|
445
|
+
const stale = client.timeoutMs * 2 + 5_000;
|
|
446
|
+
try {
|
|
447
|
+
return await this.#runtime.credentials.lock(`oauth-refresh:${client.id}`, stale, stale + 5_000);
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
throw new FeltKitError(error.code === "CUSTODY_READ_ONLY" ? "CUSTODY_READ_ONLY" : "UNAVAILABLE", `${client.integration}: ${error.message}`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function reconnect(client, why) {
|
|
455
|
+
return new FeltKitError("FAILED_PRECONDITION", `${client.integration}: ${client.ref} must be connected again (${why}). Nothing was sent.`, {
|
|
456
|
+
hint: `Run \`feltkit credential connect ${client.integration}\`.`,
|
|
457
|
+
details: { credential: client.ref, state: "reconnect_required" },
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/** Retry-After: seconds, or an HTTP date (RFC 9110 §10.2.3). Bounded to an hour. */
|
|
461
|
+
function retryAfter(value) {
|
|
462
|
+
if (!value)
|
|
463
|
+
return DEFAULT_RETRY_AFTER_MS;
|
|
464
|
+
const seconds = /^\d+$/.test(value.trim()) ? Number(value.trim()) * 1000 : Date.parse(value) - Date.now();
|
|
465
|
+
return Number.isFinite(seconds) && seconds > 0 ? Math.min(seconds, 3_600_000) : DEFAULT_RETRY_AFTER_MS;
|
|
466
|
+
}
|
|
467
|
+
//# sourceMappingURL=oauth-credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-credentials.js","sourceRoot":"","sources":["../../src/runtime/oauth-credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAA0C,MAAM,kBAAkB,CAAC;AAGjH,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,MAAM,cAAc,GAAG,EAAE,GAAG,MAAM,CAAC;AACnC,MAAM,SAAS,GAAG,eAAe,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAE9D,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AA6BnD,MAAM,OAAO,gBAAgB;IAClB,QAAQ,CAAiB;IACzB,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IACxD,iGAAiG;IACxF,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE/C,YAAY,OAAuB;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,4FAA4F;IAC5F,MAAM,CAAC,WAAkC;QACvC,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC;QACpC,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAClE,IA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AAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC;AACzG,CAAC"}
|
|
@@ -25,6 +25,8 @@ const GUIDE = docRef("PATH-TO-PRODUCTION.md");
|
|
|
25
25
|
export async function assessReadiness(runtime, options = {}) {
|
|
26
26
|
const checks = [];
|
|
27
27
|
const add = (check) => checks.push(check);
|
|
28
|
+
await runtime.integrations.refreshConfiguration();
|
|
29
|
+
await runtime.credentials.refresh();
|
|
28
30
|
const production = runtime.environment.production;
|
|
29
31
|
const env = runtime.environment.name;
|
|
30
32
|
// Persistence and recovery of state.
|
|
@@ -56,11 +58,31 @@ export async function assessReadiness(runtime, options = {}) {
|
|
|
56
58
|
const s = runtime.integrations.status(integration);
|
|
57
59
|
if (s.credential)
|
|
58
60
|
refs.set(s.credential.ref, [...(refs.get(s.credential.ref) ?? []), `integration ${integration.name}`]);
|
|
61
|
+
const secret = typeof integration.credential === "object" ? integration.credential.oauth2?.clientSecret : undefined;
|
|
62
|
+
if (secret)
|
|
63
|
+
refs.set(secret, [...(refs.get(secret) ?? []), `integration ${integration.name} (OAuth client secret)`]);
|
|
59
64
|
}
|
|
60
65
|
for (const p of signInProviders(runtime.app.options.auth?.providers))
|
|
61
66
|
refs.set(p.clientSecret, [...(refs.get(p.clientSecret) ?? []), `sign-in with ${p.name}`]);
|
|
62
67
|
if (!refs.size)
|
|
63
68
|
add({ id: "secrets.credentials", area: "secrets", title: "Credential references", status: "pass", detail: "No credential references are in use." });
|
|
69
|
+
// OAuth 2.0 grants rotate: where the vault is decides whether a renewed grant survives a deploy and is
|
|
70
|
+
// shared by every process (runtime/oauth-credentials.ts).
|
|
71
|
+
const grants = runtime.integrations.definitions().filter((i) => typeof i.credential === "object" && i.credential.oauth2);
|
|
72
|
+
if (grants.length && !runtime.environment.development && runtime.environment.name !== "test") {
|
|
73
|
+
const info = runtime.credentials.vaultInfo;
|
|
74
|
+
const vault = info?.kind === "file" ? runtime.credentials.vaultFile : info?.location ?? null;
|
|
75
|
+
const pinned = Boolean(process.env.FELTKIT_CREDENTIAL_VAULT_DIR);
|
|
76
|
+
const beside = runtime.environment.storage.kind === "local" && Boolean(process.env.FELTKIT_STATE_DIR);
|
|
77
|
+
const names = grants.map((g) => g.name).join(", ");
|
|
78
|
+
add(info?.kind === "database"
|
|
79
|
+
? { id: "secrets.oauth-vault", area: "secrets", title: "OAuth 2.0 grants: where they are kept", status: "pass", detail: `${names}: encrypted in this environment's FeltDB under the host's key, shared by every process; renewals are coordinated there.` }
|
|
80
|
+
: !vault
|
|
81
|
+
? { id: "secrets.oauth-vault", area: "secrets", title: "OAuth 2.0 grants: where they are kept", status: "fail", detail: `${names} hold OAuth 2.0 grants, which FeltKit renews and rewrites; this environment's custody can't store.`, fix: "Opt in to the vault: FELTKIT_CREDENTIAL_VAULT=1 with FELTKIT_CREDENTIAL_VAULT_KEY, on persistent storage (FELTKIT_CREDENTIAL_VAULT_DIR)." }
|
|
82
|
+
: pinned || beside
|
|
83
|
+
? { id: "secrets.oauth-vault", area: "secrets", title: "OAuth 2.0 grants: where they are kept", status: runtime.environment.storage.kind === "remote" ? "warn" : "pass", detail: `${vault}${beside && !pinned ? " (beside FELTKIT_STATE_DIR)" : ""}.${runtime.environment.storage.kind === "remote" ? " State is on a FeltDB server: the vault is a file, so run one process, or every process sees a different grant once one renews it." : ""}`, ...(runtime.environment.storage.kind === "remote" ? { fix: "Run a single machine with FELTKIT_CREDENTIAL_VAULT_DIR on its volume." } : {}) }
|
|
84
|
+
: { id: "secrets.oauth-vault", area: "secrets", title: "OAuth 2.0 grants: where they are kept", status: "warn", detail: `${vault}: inside the application's directory, which a redeploy may replace; a renewed grant would be lost.`, fix: "Set FELTKIT_CREDENTIAL_VAULT_DIR (or FELTKIT_STATE_DIR) to a persistent volume." });
|
|
85
|
+
}
|
|
64
86
|
for (const [ref, usedBy] of refs) {
|
|
65
87
|
const d = runtime.services.credentials.describe(ref);
|
|
66
88
|
add(d.present
|