@broberg/sso 0.14.1 → 0.14.2
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/chunk-JGIO7XPR.cjs +833 -0
- package/dist/chunk-JGIO7XPR.cjs.map +1 -0
- package/dist/chunk-ZPRWYUFG.js +805 -0
- package/dist/chunk-ZPRWYUFG.js.map +1 -0
- package/dist/hono.cjs +37 -815
- package/dist/hono.cjs.map +1 -1
- package/dist/hono.d.cts +2 -386
- package/dist/hono.d.ts +2 -386
- package/dist/hono.js +1 -779
- package/dist/hono.js.map +1 -1
- package/dist/index.cjs +114 -827
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -579
- package/dist/index.d.ts +3 -579
- package/dist/index.js +6 -787
- package/dist/index.js.map +1 -1
- package/dist/session-DsjOyCJb.d.cts +580 -0
- package/dist/session-DsjOyCJb.d.ts +580 -0
- package/package.json +1 -1
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jose = require('jose');
|
|
4
|
+
|
|
5
|
+
// src/config.ts
|
|
6
|
+
var SsoConfigError = class extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "SsoConfigError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function required(env, name, hint) {
|
|
13
|
+
const raw = env[name];
|
|
14
|
+
if (typeof raw !== "string" || raw.trim() === "") {
|
|
15
|
+
throw new SsoConfigError(`${name} is not set (or is blank). ${hint}`);
|
|
16
|
+
}
|
|
17
|
+
return raw.trim();
|
|
18
|
+
}
|
|
19
|
+
var DEFAULT_SESSION_MAX_AGE = 60 * 60 * 24 * 7;
|
|
20
|
+
function loadSsoConfig(env = process.env) {
|
|
21
|
+
const rawIssuer = required(
|
|
22
|
+
env,
|
|
23
|
+
"BID_ISSUER",
|
|
24
|
+
"It is Broberg ID's bare origin, e.g. https://id.broberg.ai"
|
|
25
|
+
);
|
|
26
|
+
let issuer;
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(rawIssuer);
|
|
29
|
+
if (url.protocol !== "https:" && url.hostname !== "localhost") {
|
|
30
|
+
throw new SsoConfigError(
|
|
31
|
+
`BID_ISSUER must be https (got ${url.protocol}//). Only localhost may be http.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
issuer = url.origin;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
if (err instanceof SsoConfigError) throw err;
|
|
37
|
+
throw new SsoConfigError(`BID_ISSUER is not a valid URL: ${rawIssuer}`);
|
|
38
|
+
}
|
|
39
|
+
const cookieSecret = required(
|
|
40
|
+
env,
|
|
41
|
+
"SSO_COOKIE_SECRET",
|
|
42
|
+
"Generate one with `openssl rand -hex 32`. It signs this app's session cookie."
|
|
43
|
+
);
|
|
44
|
+
if (cookieSecret.length < 32) {
|
|
45
|
+
throw new SsoConfigError(
|
|
46
|
+
`SSO_COOKIE_SECRET is ${cookieSecret.length} characters; it must be at least 32. A short secret is a forgeable session, and a forged session is any user you like.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const rawMaxAge = env.SSO_SESSION_MAX_AGE?.trim();
|
|
50
|
+
let sessionMaxAge = DEFAULT_SESSION_MAX_AGE;
|
|
51
|
+
if (rawMaxAge) {
|
|
52
|
+
const n = Number(rawMaxAge);
|
|
53
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
54
|
+
throw new SsoConfigError(
|
|
55
|
+
`SSO_SESSION_MAX_AGE must be a positive number of seconds (got ${JSON.stringify(rawMaxAge)}).`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
sessionMaxAge = Math.floor(n);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
issuer,
|
|
62
|
+
clientId: required(env, "SSO_CLIENT_ID", "The id this app is registered under in Broberg ID."),
|
|
63
|
+
redirectUri: required(
|
|
64
|
+
env,
|
|
65
|
+
"SSO_REDIRECT_URI",
|
|
66
|
+
"Must match the registered redirect EXACTLY \u2014 one trailing slash is a different address."
|
|
67
|
+
),
|
|
68
|
+
scopes: (env.SSO_SCOPES?.trim() || "openid profile email").split(/\s+/),
|
|
69
|
+
cookieSecret,
|
|
70
|
+
cookieName: env.SSO_COOKIE_NAME?.trim() || "bid_session",
|
|
71
|
+
sessionMaxAge,
|
|
72
|
+
postLogoutRedirectUri: env.SSO_POST_LOGOUT_REDIRECT_URI?.trim() || void 0,
|
|
73
|
+
clientSecret: env.SSO_CLIENT_SECRET?.trim() || void 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var JwksError = class extends Error {
|
|
77
|
+
constructor(message) {
|
|
78
|
+
super(message);
|
|
79
|
+
this.name = "JwksError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var JwksUnavailableError = class extends JwksError {
|
|
83
|
+
constructor(message) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = "JwksUnavailableError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var JwksUnknownKeyError = class extends JwksError {
|
|
89
|
+
constructor(message) {
|
|
90
|
+
super(message);
|
|
91
|
+
this.name = "JwksUnknownKeyError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
function createJwksCache(options) {
|
|
95
|
+
const {
|
|
96
|
+
jwksUri,
|
|
97
|
+
minRefetchIntervalMs = 1e4,
|
|
98
|
+
warmUp = false,
|
|
99
|
+
fetchImpl = fetch,
|
|
100
|
+
now = () => Date.now()
|
|
101
|
+
} = options;
|
|
102
|
+
let keys = [];
|
|
103
|
+
let lastFetchAt = -Infinity;
|
|
104
|
+
let fetchCount = 0;
|
|
105
|
+
let inFlight = null;
|
|
106
|
+
async function refresh() {
|
|
107
|
+
if (inFlight) return inFlight;
|
|
108
|
+
inFlight = (async () => {
|
|
109
|
+
let res;
|
|
110
|
+
try {
|
|
111
|
+
res = await fetchImpl(jwksUri);
|
|
112
|
+
} catch (cause) {
|
|
113
|
+
throw new JwksUnavailableError(
|
|
114
|
+
`${jwksUri} could not be reached: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (!res.ok) {
|
|
118
|
+
throw new JwksUnavailableError(
|
|
119
|
+
`${jwksUri} answered ${res.status} \u2014 cannot verify any token right now`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
let body;
|
|
123
|
+
try {
|
|
124
|
+
body = await res.json();
|
|
125
|
+
} catch {
|
|
126
|
+
throw new JwksUnavailableError(`${jwksUri} answered 200 with a body that is not JSON`);
|
|
127
|
+
}
|
|
128
|
+
if (!Array.isArray(body?.keys)) {
|
|
129
|
+
throw new JwksUnavailableError(`${jwksUri} returned no "keys" array`);
|
|
130
|
+
}
|
|
131
|
+
keys = body.keys;
|
|
132
|
+
lastFetchAt = now();
|
|
133
|
+
fetchCount++;
|
|
134
|
+
})().finally(() => {
|
|
135
|
+
inFlight = null;
|
|
136
|
+
});
|
|
137
|
+
return inFlight;
|
|
138
|
+
}
|
|
139
|
+
if (warmUp) {
|
|
140
|
+
void refresh().catch(() => {
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
get fetchCount() {
|
|
145
|
+
return fetchCount;
|
|
146
|
+
},
|
|
147
|
+
async getKey(kid, alg) {
|
|
148
|
+
let jwk = keys.find((k) => k.kid === kid);
|
|
149
|
+
if (!jwk) {
|
|
150
|
+
const sinceLast = now() - lastFetchAt;
|
|
151
|
+
if (sinceLast < minRefetchIntervalMs) {
|
|
152
|
+
throw new JwksUnavailableError(
|
|
153
|
+
`kid ${kid} is not in the key set we hold, fetched ${sinceLast}ms ago (we do not ask the issuer again within ${minRefetchIntervalMs}ms). A key set this fresh that lacks the kid means the token was not signed by this issuer \u2014 reject it. Only a key rotation within the last ${minRefetchIntervalMs}ms could make that wrong.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
await refresh();
|
|
157
|
+
jwk = keys.find((k) => k.kid === kid);
|
|
158
|
+
}
|
|
159
|
+
if (!jwk) {
|
|
160
|
+
throw new JwksUnknownKeyError(
|
|
161
|
+
`Broberg ID does not publish a signing key with kid ${kid}. The token was not signed by this issuer.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return jose.importJWK(jwk, alg);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
var SsoError = class extends Error {
|
|
169
|
+
constructor(message) {
|
|
170
|
+
super(message);
|
|
171
|
+
this.name = "SsoError";
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
var SsoReauthError = class extends SsoError {
|
|
175
|
+
constructor(message, reason) {
|
|
176
|
+
super(message);
|
|
177
|
+
this.reason = reason;
|
|
178
|
+
this.name = "SsoReauthError";
|
|
179
|
+
}
|
|
180
|
+
reason;
|
|
181
|
+
};
|
|
182
|
+
var SsoAppApiError = class extends SsoError {
|
|
183
|
+
constructor(message, status, code) {
|
|
184
|
+
super(message);
|
|
185
|
+
this.status = status;
|
|
186
|
+
this.code = code;
|
|
187
|
+
this.name = "SsoAppApiError";
|
|
188
|
+
}
|
|
189
|
+
status;
|
|
190
|
+
code;
|
|
191
|
+
};
|
|
192
|
+
var SsoInsufficientScopeError = class extends SsoAppApiError {
|
|
193
|
+
constructor(message, scope) {
|
|
194
|
+
super(message, 403, "insufficient_scope");
|
|
195
|
+
this.scope = scope;
|
|
196
|
+
this.name = "SsoInsufficientScopeError";
|
|
197
|
+
}
|
|
198
|
+
scope;
|
|
199
|
+
};
|
|
200
|
+
var SsoAvatarRejectedError = class extends SsoError {
|
|
201
|
+
constructor(message, reason) {
|
|
202
|
+
super(message);
|
|
203
|
+
this.reason = reason;
|
|
204
|
+
this.name = "SsoAvatarRejectedError";
|
|
205
|
+
}
|
|
206
|
+
reason;
|
|
207
|
+
};
|
|
208
|
+
var MAX_AVATAR_BYTES = 2 * 1024 * 1024;
|
|
209
|
+
var AVATAR_TYPES = ["image/png", "image/jpeg", "image/webp"];
|
|
210
|
+
function mediaType(contentType) {
|
|
211
|
+
return (contentType ?? "").split(";")[0].trim().toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
var b64url = (bytes) => {
|
|
214
|
+
const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
215
|
+
let s = "";
|
|
216
|
+
for (const b of view) s += String.fromCharCode(b);
|
|
217
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
218
|
+
};
|
|
219
|
+
var randomToken = (bytes = 32) => b64url(crypto.getRandomValues(new Uint8Array(bytes)));
|
|
220
|
+
async function challengeFor(verifier) {
|
|
221
|
+
return b64url(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier)));
|
|
222
|
+
}
|
|
223
|
+
var ADDRESS_OWNERSHIP = /* @__PURE__ */ new Set(["verified", "unverified", "not_on_account"]);
|
|
224
|
+
var INVITATION_OUTCOMES = /* @__PURE__ */ new Set([
|
|
225
|
+
"invited",
|
|
226
|
+
"already_invited",
|
|
227
|
+
"existing",
|
|
228
|
+
"invalid",
|
|
229
|
+
"too_soon",
|
|
230
|
+
"too_many_today",
|
|
231
|
+
"send_failed"
|
|
232
|
+
]);
|
|
233
|
+
var MIGRATION_STATES = /* @__PURE__ */ new Set(["ready", "invited", "expired", "not_invited"]);
|
|
234
|
+
var BACKCHANNEL_EVENT = "http://schemas.openid.net/event/backchannel-logout";
|
|
235
|
+
var MAX_INVITATIONS = 500;
|
|
236
|
+
function excerptForLog(raw, clientSecret) {
|
|
237
|
+
let text = raw.replace(/\s+/g, " ").trim();
|
|
238
|
+
if (clientSecret) text = text.split(clientSecret).join("[redacted client_secret]");
|
|
239
|
+
if (text === "") return "(empty body)";
|
|
240
|
+
return text.length > 200 ? `${text.slice(0, 200)}\u2026` : text;
|
|
241
|
+
}
|
|
242
|
+
function invalidClientHint(error, weSentASecret) {
|
|
243
|
+
if (error !== "invalid_client") return "";
|
|
244
|
+
return weSentASecret ? " \u2014 we DID send a client_secret, so either it is wrong or this client is registered as PUBLIC (in which case unset SSO_CLIENT_SECRET)." : " \u2014 we sent NO client_secret, so this client is likely registered as CONFIDENTIAL (set SSO_CLIENT_SECRET to the value it was registered with).";
|
|
245
|
+
}
|
|
246
|
+
var ALLOWED_ALGS = [
|
|
247
|
+
// FIRST, because it is what Broberg ID actually signs with. Measured on the
|
|
248
|
+
// live issuer 2026-09-20:
|
|
249
|
+
// /jwks kid=Iodh… kty=OKP alg=EdDSA crv=Ed25519
|
|
250
|
+
// discovery id_token_signing_alg_values_supported: ["EdDSA"]
|
|
251
|
+
//
|
|
252
|
+
// 0.2.1 SHIPPED THIS LIST WITHOUT IT and rejected every real token for an
|
|
253
|
+
// hour. The list was written from what an OIDC client usually allows rather
|
|
254
|
+
// than from what our issuer uses — and the whole suite missed it because the
|
|
255
|
+
// fake issuer in the tests signs RS256. A fake agrees with whoever wrote it.
|
|
256
|
+
// There is now a test that mints EdDSA, the algorithm production uses.
|
|
257
|
+
"EdDSA",
|
|
258
|
+
"RS256",
|
|
259
|
+
"RS384",
|
|
260
|
+
"RS512",
|
|
261
|
+
"PS256",
|
|
262
|
+
"PS384",
|
|
263
|
+
"PS512",
|
|
264
|
+
"ES256",
|
|
265
|
+
"ES384",
|
|
266
|
+
"ES512"
|
|
267
|
+
];
|
|
268
|
+
function createSsoClient(config, options = {}) {
|
|
269
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
270
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
271
|
+
async function appPost(path, bearer, payload, what) {
|
|
272
|
+
const url = new URL(path, config.issuer).toString();
|
|
273
|
+
const ctrl = new AbortController();
|
|
274
|
+
let timer;
|
|
275
|
+
const timedOut = new Promise((_, reject) => {
|
|
276
|
+
timer = setTimeout(() => {
|
|
277
|
+
ctrl.abort();
|
|
278
|
+
reject(new SsoError(`${url} did not answer within ${timeoutMs} ms \u2014 ${what} is unknown.`));
|
|
279
|
+
}, timeoutMs);
|
|
280
|
+
});
|
|
281
|
+
try {
|
|
282
|
+
const res = await Promise.race([
|
|
283
|
+
fetchImpl(url, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
headers: { authorization: `Bearer ${bearer}`, "content-type": "application/json" },
|
|
286
|
+
body: JSON.stringify(payload),
|
|
287
|
+
signal: ctrl.signal
|
|
288
|
+
}),
|
|
289
|
+
timedOut
|
|
290
|
+
]);
|
|
291
|
+
if (!res.ok) {
|
|
292
|
+
const detail = await res.text().catch(() => "");
|
|
293
|
+
const hint = detail.includes("invalid_app_key") ? " (invalid_app_key: this app's bidk_ key was refused)" : "";
|
|
294
|
+
throw new SsoError(`${url} answered ${res.status}${hint} \u2014 ${what} is unknown.`);
|
|
295
|
+
}
|
|
296
|
+
return await Promise.race([res.json().catch(() => null), timedOut]);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
if (e instanceof SsoError) throw e;
|
|
299
|
+
throw new SsoError(`${url} could not be reached: ${e instanceof Error ? e.message : String(e)} \u2014 ${what} is unknown.`);
|
|
300
|
+
} finally {
|
|
301
|
+
clearTimeout(timer);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function appRequest(path, bearer, init, what) {
|
|
305
|
+
const url = new URL(path, config.issuer).toString();
|
|
306
|
+
const ctrl = new AbortController();
|
|
307
|
+
let timer;
|
|
308
|
+
const timedOut = new Promise((_, reject) => {
|
|
309
|
+
timer = setTimeout(() => {
|
|
310
|
+
reject(new SsoAppApiError(`${url} did not answer within ${timeoutMs} ms \u2014 ${what} is unknown.`, null, void 0));
|
|
311
|
+
ctrl.abort();
|
|
312
|
+
}, timeoutMs);
|
|
313
|
+
});
|
|
314
|
+
const headers = { authorization: `Bearer ${bearer}` };
|
|
315
|
+
let body;
|
|
316
|
+
if (init.json !== void 0) {
|
|
317
|
+
headers["content-type"] = "application/json";
|
|
318
|
+
body = JSON.stringify(init.json);
|
|
319
|
+
} else if (init.bytes !== void 0) {
|
|
320
|
+
headers["content-type"] = init.contentType ?? "application/octet-stream";
|
|
321
|
+
body = init.bytes;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const res = await Promise.race([
|
|
325
|
+
fetchImpl(url, { method: init.method, headers, ...body !== void 0 ? { body } : {}, signal: ctrl.signal }),
|
|
326
|
+
timedOut
|
|
327
|
+
]);
|
|
328
|
+
const raw = await Promise.race([res.text(), timedOut]);
|
|
329
|
+
let parsed;
|
|
330
|
+
try {
|
|
331
|
+
parsed = raw.trim() === "" ? void 0 : JSON.parse(raw);
|
|
332
|
+
} catch {
|
|
333
|
+
parsed = void 0;
|
|
334
|
+
}
|
|
335
|
+
const fields = parsed && typeof parsed === "object" ? parsed : {};
|
|
336
|
+
const code = typeof fields.error === "string" ? fields.error : void 0;
|
|
337
|
+
if (!res.ok) {
|
|
338
|
+
if (res.status === 403 && code === "insufficient_scope") {
|
|
339
|
+
const scope = typeof fields.scope === "string" && fields.scope ? fields.scope : init.method === "GET" ? "profile" : "profile:write";
|
|
340
|
+
throw new SsoInsufficientScopeError(
|
|
341
|
+
`${url} answered 403 insufficient_scope \u2014 the user's token lacks scope "${scope}"; log in again with it requested.`,
|
|
342
|
+
scope
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
throw new SsoAppApiError(`${url} answered ${res.status}${code ? ` (${code})` : ""} \u2014 ${what} is unknown.`, res.status, code);
|
|
346
|
+
}
|
|
347
|
+
if (parsed === void 0) {
|
|
348
|
+
throw new SsoAppApiError(`${url} answered ${res.status} with a body that is not JSON \u2014 ${what} is unknown.`, res.status, void 0);
|
|
349
|
+
}
|
|
350
|
+
return parsed;
|
|
351
|
+
} catch (e) {
|
|
352
|
+
if (e instanceof SsoError) throw e;
|
|
353
|
+
throw new SsoAppApiError(`${url} could not be reached (${e instanceof Error ? e.name : "error"}) \u2014 ${what} is unknown.`, null, void 0);
|
|
354
|
+
} finally {
|
|
355
|
+
clearTimeout(timer);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function asProfile(body, path) {
|
|
359
|
+
const b = body ?? {};
|
|
360
|
+
if (typeof b.sub !== "string" || b.sub === "" || typeof b.account_url !== "string") {
|
|
361
|
+
throw new SsoAppApiError(`${path} returned no "sub" or "account_url" \u2014 the profile is unknown.`, 200, void 0);
|
|
362
|
+
}
|
|
363
|
+
const opt = (v) => typeof v === "string" ? v : null;
|
|
364
|
+
return { sub: b.sub, name: opt(b.name), picture: opt(b.picture), email: opt(b.email), account_url: b.account_url };
|
|
365
|
+
}
|
|
366
|
+
let discoveryPromise = null;
|
|
367
|
+
let jwksCache = null;
|
|
368
|
+
async function discovery() {
|
|
369
|
+
discoveryPromise ??= (async () => {
|
|
370
|
+
const url = `${config.issuer}/.well-known/openid-configuration`;
|
|
371
|
+
const res = await fetchImpl(url);
|
|
372
|
+
if (!res.ok) throw new SsoError(`${url} answered ${res.status}`);
|
|
373
|
+
const doc = await res.json();
|
|
374
|
+
const advertised = doc.id_token_signing_alg_values_supported;
|
|
375
|
+
if (Array.isArray(advertised) && advertised.length > 0) {
|
|
376
|
+
const usable = advertised.filter((a) => ALLOWED_ALGS.includes(a));
|
|
377
|
+
if (usable.length === 0) {
|
|
378
|
+
throw new SsoError(
|
|
379
|
+
`${config.issuer} signs ID tokens with ${advertised.join(", ")}, and this client accepts none of those (it allows ${ALLOWED_ALGS.join(", ")}). Every token would be rejected. This is a mismatch between the package and the issuer \u2014 report it rather than working around it.`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (doc.issuer !== config.issuer) {
|
|
384
|
+
throw new SsoError(
|
|
385
|
+
`BID_ISSUER is ${config.issuer} but ${url} says its issuer is ${doc.issuer}. These must match exactly \u2014 tokens are validated against the issuer string.`
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
return doc;
|
|
389
|
+
})().catch((err) => {
|
|
390
|
+
discoveryPromise = null;
|
|
391
|
+
throw err;
|
|
392
|
+
});
|
|
393
|
+
return discoveryPromise;
|
|
394
|
+
}
|
|
395
|
+
async function keys() {
|
|
396
|
+
if (!jwksCache) {
|
|
397
|
+
const { jwks_uri } = await discovery();
|
|
398
|
+
jwksCache = createJwksCache({
|
|
399
|
+
jwksUri: jwks_uri,
|
|
400
|
+
fetchImpl,
|
|
401
|
+
...options.minRefetchIntervalMs !== void 0 ? { minRefetchIntervalMs: options.minRefetchIntervalMs } : {}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
return jwksCache;
|
|
405
|
+
}
|
|
406
|
+
async function verifyLogoutToken(token) {
|
|
407
|
+
const cache = await keys();
|
|
408
|
+
let header;
|
|
409
|
+
try {
|
|
410
|
+
header = jose.decodeProtectedHeader(token);
|
|
411
|
+
} catch {
|
|
412
|
+
throw new SsoError("logout_token is not a JWS");
|
|
413
|
+
}
|
|
414
|
+
if (!header.kid) throw new SsoError("logout_token has no kid \u2014 cannot pick a signing key");
|
|
415
|
+
let payload;
|
|
416
|
+
try {
|
|
417
|
+
({ payload } = await jose.jwtVerify(token, async () => cache.getKey(header.kid, header.alg ?? "RS256"), {
|
|
418
|
+
issuer: config.issuer,
|
|
419
|
+
audience: config.clientId,
|
|
420
|
+
algorithms: ALLOWED_ALGS,
|
|
421
|
+
typ: "logout+jwt",
|
|
422
|
+
requiredClaims: ["iat", "exp", "jti"]
|
|
423
|
+
}));
|
|
424
|
+
} catch (e) {
|
|
425
|
+
throw new SsoError(`logout_token rejected: ${e instanceof Error ? e.message : String(e)}`);
|
|
426
|
+
}
|
|
427
|
+
const events = payload.events;
|
|
428
|
+
if (!events || typeof events !== "object" || !(BACKCHANNEL_EVENT in events)) {
|
|
429
|
+
throw new SsoError("logout_token has no back-channel logout event");
|
|
430
|
+
}
|
|
431
|
+
if ("nonce" in payload) throw new SsoError("logout_token carries a nonce \u2014 that is an ID token, not a logout token");
|
|
432
|
+
if ("sid" in payload) {
|
|
433
|
+
throw new SsoError("logout_token carries sid \u2014 only sub-wide \xABLog ud overalt\xBB is accepted (D-376ffa)");
|
|
434
|
+
}
|
|
435
|
+
if (typeof payload.sub !== "string" || payload.sub === "") throw new SsoError("logout_token has no sub");
|
|
436
|
+
return { sub: payload.sub, iat: payload.iat, jti: String(payload.jti), exp: payload.exp };
|
|
437
|
+
}
|
|
438
|
+
async function verifyIdToken(idToken, opts = {}) {
|
|
439
|
+
const cache = await keys();
|
|
440
|
+
const header = jose.decodeProtectedHeader(idToken);
|
|
441
|
+
if (!header.kid) throw new SsoError("ID token has no kid \u2014 cannot pick a signing key");
|
|
442
|
+
const { payload } = await jose.jwtVerify(
|
|
443
|
+
idToken,
|
|
444
|
+
async () => cache.getKey(header.kid, header.alg ?? "RS256"),
|
|
445
|
+
{ issuer: config.issuer, audience: config.clientId, algorithms: ALLOWED_ALGS }
|
|
446
|
+
);
|
|
447
|
+
if (opts.nonce !== void 0 && payload.nonce !== opts.nonce) {
|
|
448
|
+
throw new SsoError(
|
|
449
|
+
"ID token nonce does not match this login request \u2014 refusing a token minted for another sign-in."
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (typeof payload.sub !== "string" || payload.sub === "") {
|
|
453
|
+
throw new SsoError("ID token has no sub \u2014 there is no user to be");
|
|
454
|
+
}
|
|
455
|
+
return payload;
|
|
456
|
+
}
|
|
457
|
+
async function withUserInfo(claims, accessToken) {
|
|
458
|
+
const doc = await discovery();
|
|
459
|
+
if (!doc.userinfo_endpoint) return { claims, unverifiedClaims: [] };
|
|
460
|
+
const res = await fetchImpl(doc.userinfo_endpoint, {
|
|
461
|
+
headers: { authorization: `Bearer ${accessToken}` }
|
|
462
|
+
});
|
|
463
|
+
if (!res.ok) return { claims, unverifiedClaims: [] };
|
|
464
|
+
const info = await res.json();
|
|
465
|
+
if (info.sub !== claims.sub) {
|
|
466
|
+
throw new SsoError(
|
|
467
|
+
`userinfo describes ${String(info.sub)} but the ID token is for ${claims.sub} \u2014 refusing to merge another user's profile onto this session.`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
const unverifiedClaims = Object.keys(info).filter((k) => k !== "sub" && info[k] !== void 0 && !(k in claims)).sort();
|
|
471
|
+
return { claims: { ...info, ...claims, sub: claims.sub }, unverifiedClaims };
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
discovery,
|
|
475
|
+
get jwks() {
|
|
476
|
+
if (!jwksCache) throw new SsoError("the key cache is created on first verification");
|
|
477
|
+
return jwksCache;
|
|
478
|
+
},
|
|
479
|
+
verifyIdToken,
|
|
480
|
+
async beginLogin(opts = {}) {
|
|
481
|
+
const { authorization_endpoint } = await discovery();
|
|
482
|
+
const codeVerifier = randomToken();
|
|
483
|
+
const state = randomToken(16);
|
|
484
|
+
const nonce = randomToken(16);
|
|
485
|
+
const params = new URLSearchParams({
|
|
486
|
+
response_type: "code",
|
|
487
|
+
client_id: config.clientId,
|
|
488
|
+
redirect_uri: config.redirectUri,
|
|
489
|
+
scope: [.../* @__PURE__ */ new Set([...config.scopes, ...opts.scopes ?? []])].join(" "),
|
|
490
|
+
state,
|
|
491
|
+
nonce,
|
|
492
|
+
code_challenge: await challengeFor(codeVerifier),
|
|
493
|
+
code_challenge_method: "S256"
|
|
494
|
+
});
|
|
495
|
+
if (opts.prompt) params.set("prompt", opts.prompt);
|
|
496
|
+
return { url: `${authorization_endpoint}?${params}`, state, codeVerifier, nonce };
|
|
497
|
+
},
|
|
498
|
+
async completeLogin({ params, state, codeVerifier, nonce }) {
|
|
499
|
+
const error = params.get("error");
|
|
500
|
+
if (error) {
|
|
501
|
+
throw new SsoError(
|
|
502
|
+
`Broberg ID refused this login: ${error}` + (params.get("error_description") ? ` \u2014 ${params.get("error_description")}` : "")
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
const returned = params.get("state");
|
|
506
|
+
if (!returned || returned !== state) {
|
|
507
|
+
throw new SsoError(
|
|
508
|
+
"state does not match the login this browser started \u2014 refusing the callback."
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
const code = params.get("code");
|
|
512
|
+
if (!code) throw new SsoError("callback carried neither an error nor a code");
|
|
513
|
+
const { token_endpoint } = await discovery();
|
|
514
|
+
const res = await fetchImpl(token_endpoint, {
|
|
515
|
+
method: "POST",
|
|
516
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
517
|
+
body: new URLSearchParams({
|
|
518
|
+
grant_type: "authorization_code",
|
|
519
|
+
code,
|
|
520
|
+
redirect_uri: config.redirectUri,
|
|
521
|
+
client_id: config.clientId,
|
|
522
|
+
// ALWAYS sent, secret or not. See SsoConfig.clientSecret: the two
|
|
523
|
+
// prove different things, so a confidential client keeps PKCE.
|
|
524
|
+
code_verifier: codeVerifier,
|
|
525
|
+
...config.clientSecret ? { client_secret: config.clientSecret } : {}
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
const raw = await res.text();
|
|
529
|
+
let body;
|
|
530
|
+
try {
|
|
531
|
+
body = raw.trim() === "" ? {} : JSON.parse(raw);
|
|
532
|
+
} catch {
|
|
533
|
+
throw new SsoError(
|
|
534
|
+
`token exchange failed (${res.status}): the response body is not JSON${res.headers.get("content-type") ? ` (content-type: ${res.headers.get("content-type")})` : ""} \u2014 ${excerptForLog(raw, config.clientSecret)}`
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
if (!res.ok || !body.id_token) {
|
|
538
|
+
throw new SsoError(
|
|
539
|
+
`token exchange failed (${res.status}): ${body.error ?? "no id_token in response"}` + (body.error_description ? ` \u2014 ${body.error_description}` : "") + invalidClientHint(body.error, config.clientSecret !== void 0)
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const claims = await verifyIdToken(body.id_token, { nonce });
|
|
543
|
+
const merged = body.access_token ? await withUserInfo(claims, body.access_token) : { claims, unverifiedClaims: [] };
|
|
544
|
+
return {
|
|
545
|
+
claims: merged.claims,
|
|
546
|
+
unverifiedClaims: merged.unverifiedClaims,
|
|
547
|
+
idToken: body.id_token,
|
|
548
|
+
...body.access_token ? { accessToken: body.access_token } : {},
|
|
549
|
+
...body.refresh_token ? { refreshToken: body.refresh_token } : {},
|
|
550
|
+
...typeof body.expires_in === "number" ? { expiresIn: body.expires_in } : {}
|
|
551
|
+
};
|
|
552
|
+
},
|
|
553
|
+
async refreshTokens(refreshToken) {
|
|
554
|
+
const { token_endpoint } = await discovery();
|
|
555
|
+
const res = await fetchImpl(token_endpoint, {
|
|
556
|
+
method: "POST",
|
|
557
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
558
|
+
body: new URLSearchParams({
|
|
559
|
+
grant_type: "refresh_token",
|
|
560
|
+
refresh_token: refreshToken,
|
|
561
|
+
client_id: config.clientId,
|
|
562
|
+
...config.clientSecret ? { client_secret: config.clientSecret } : {}
|
|
563
|
+
})
|
|
564
|
+
});
|
|
565
|
+
const raw = await res.text();
|
|
566
|
+
let body;
|
|
567
|
+
try {
|
|
568
|
+
body = raw.trim() === "" ? {} : JSON.parse(raw);
|
|
569
|
+
} catch {
|
|
570
|
+
throw new SsoError(`token refresh failed (${res.status}): the response body is not JSON`);
|
|
571
|
+
}
|
|
572
|
+
if (!res.ok || typeof body.access_token !== "string" || body.access_token === "") {
|
|
573
|
+
throw new SsoError(`token refresh failed (${res.status}): ${body.error ?? "no access_token in response"}`);
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
accessToken: body.access_token,
|
|
577
|
+
...typeof body.refresh_token === "string" && body.refresh_token ? { refreshToken: body.refresh_token } : {},
|
|
578
|
+
...typeof body.expires_in === "number" ? { expiresIn: body.expires_in } : {}
|
|
579
|
+
};
|
|
580
|
+
},
|
|
581
|
+
async logoutUrl(opts = {}) {
|
|
582
|
+
const doc = await discovery();
|
|
583
|
+
if (!doc.end_session_endpoint) {
|
|
584
|
+
throw new SsoError(
|
|
585
|
+
`${config.issuer} does not advertise end_session_endpoint \u2014 central logout is unavailable.`
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
const params = new URLSearchParams();
|
|
589
|
+
if (opts.idTokenHint) params.set("id_token_hint", opts.idTokenHint);
|
|
590
|
+
const post = opts.postLogoutRedirectUri ?? config.postLogoutRedirectUri;
|
|
591
|
+
if (post) params.set("post_logout_redirect_uri", post);
|
|
592
|
+
params.set("client_id", config.clientId);
|
|
593
|
+
return `${doc.end_session_endpoint}?${params}`;
|
|
594
|
+
},
|
|
595
|
+
async addressOwnership(accessToken, address) {
|
|
596
|
+
const body = await appPost(
|
|
597
|
+
"/api/app/address-ownership",
|
|
598
|
+
accessToken,
|
|
599
|
+
{ address },
|
|
600
|
+
'address ownership (not "unverified")'
|
|
601
|
+
);
|
|
602
|
+
const status = body?.status;
|
|
603
|
+
if (typeof status !== "string" || !ADDRESS_OWNERSHIP.has(status)) {
|
|
604
|
+
throw new SsoError(`address-ownership returned status ${JSON.stringify(status)} \u2014 expected verified, unverified or not_on_account.`);
|
|
605
|
+
}
|
|
606
|
+
return status;
|
|
607
|
+
},
|
|
608
|
+
verifyLogoutToken,
|
|
609
|
+
async getProfile(accessToken) {
|
|
610
|
+
const path = "/api/app/profile";
|
|
611
|
+
return asProfile(await appRequest(path, accessToken, { method: "GET" }, "the profile"), path);
|
|
612
|
+
},
|
|
613
|
+
async updateProfile(accessToken, name) {
|
|
614
|
+
const path = "/api/app/profile";
|
|
615
|
+
return asProfile(await appRequest(path, accessToken, { method: "POST", json: { name } }, "the new name"), path);
|
|
616
|
+
},
|
|
617
|
+
async uploadAvatar(accessToken, bytes, contentType) {
|
|
618
|
+
const type = mediaType(contentType);
|
|
619
|
+
if (!AVATAR_TYPES.includes(type)) {
|
|
620
|
+
throw new SsoAvatarRejectedError(
|
|
621
|
+
`uploadAvatar: "${type}" is not accepted \u2014 BID takes ${AVATAR_TYPES.join(", ")}.`,
|
|
622
|
+
"unsupported_type"
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
if (bytes.byteLength > MAX_AVATAR_BYTES) {
|
|
626
|
+
throw new SsoAvatarRejectedError(
|
|
627
|
+
`uploadAvatar: ${bytes.byteLength} bytes \u2014 BID takes at most ${MAX_AVATAR_BYTES}.`,
|
|
628
|
+
"too_large"
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
const path = "/api/app/profile/avatar";
|
|
632
|
+
return asProfile(await appRequest(path, accessToken, { method: "POST", bytes, contentType: type }, "the new picture"), path);
|
|
633
|
+
},
|
|
634
|
+
async removeAvatar(accessToken) {
|
|
635
|
+
const path = "/api/app/profile/avatar/remove";
|
|
636
|
+
return asProfile(await appRequest(path, accessToken, { method: "POST" }, "the removed picture"), path);
|
|
637
|
+
},
|
|
638
|
+
async inviteUsers(appKey, input) {
|
|
639
|
+
if (input.users.length > MAX_INVITATIONS) {
|
|
640
|
+
throw new SsoError(`inviteUsers: ${input.users.length} users, BID accepts at most ${MAX_INVITATIONS} per call.`);
|
|
641
|
+
}
|
|
642
|
+
const body = await appPost("/api/app/invitations", appKey, input, "the invitation outcome");
|
|
643
|
+
if (!Array.isArray(body?.results)) {
|
|
644
|
+
throw new SsoError(`invitations returned no "results" array \u2014 the invitation outcome is unknown.`);
|
|
645
|
+
}
|
|
646
|
+
for (const r of body.results) {
|
|
647
|
+
if (typeof r?.outcome !== "string" || !INVITATION_OUTCOMES.has(r.outcome)) {
|
|
648
|
+
throw new SsoError(`invitations returned outcome ${JSON.stringify(r?.outcome)} for ${String(r?.email)} \u2014 not one this client knows.`);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return body.results;
|
|
652
|
+
},
|
|
653
|
+
async migrationStatus(appKey, emails) {
|
|
654
|
+
const body = await appPost("/api/app/migration-status", appKey, { emails }, "the migration state");
|
|
655
|
+
if (!Array.isArray(body?.users) || typeof body.complete !== "boolean") {
|
|
656
|
+
throw new SsoError(`migration-status returned no "users" array or no "complete" flag \u2014 the migration state is unknown.`);
|
|
657
|
+
}
|
|
658
|
+
for (const u of body.users) {
|
|
659
|
+
if (typeof u?.state !== "string" || !MIGRATION_STATES.has(u.state)) {
|
|
660
|
+
throw new SsoError(`migration-status returned state ${JSON.stringify(u?.state)} for ${String(u?.email)} \u2014 never read as "ready".`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return body;
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/session.ts
|
|
669
|
+
var enc = new TextEncoder();
|
|
670
|
+
var b64url2 = (bytes) => {
|
|
671
|
+
let s = "";
|
|
672
|
+
for (const b of bytes) s += String.fromCharCode(b);
|
|
673
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
674
|
+
};
|
|
675
|
+
var fromB64url = (s) => {
|
|
676
|
+
const pad = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
677
|
+
const bin = atob(pad + "=".repeat((4 - pad.length % 4) % 4));
|
|
678
|
+
return Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
679
|
+
};
|
|
680
|
+
async function hmacKey(secret) {
|
|
681
|
+
return crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
|
|
682
|
+
"sign",
|
|
683
|
+
"verify"
|
|
684
|
+
]);
|
|
685
|
+
}
|
|
686
|
+
async function signValue(value, secret, options = {}) {
|
|
687
|
+
const payload = b64url2(enc.encode(value));
|
|
688
|
+
const body = options.maxAgeSeconds === void 0 ? payload : `t${Math.floor((options.now ?? Date.now)() / 1e3)}~${payload}`;
|
|
689
|
+
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", await hmacKey(secret), enc.encode(body)));
|
|
690
|
+
return `${body}.${b64url2(sig)}`;
|
|
691
|
+
}
|
|
692
|
+
var STAMPED = /^t(\d+)~(.*)$/s;
|
|
693
|
+
async function verifyValue(token, secret, options = {}) {
|
|
694
|
+
if (!token) return null;
|
|
695
|
+
const dot = token.lastIndexOf(".");
|
|
696
|
+
if (dot <= 0) return null;
|
|
697
|
+
const body = token.slice(0, dot);
|
|
698
|
+
try {
|
|
699
|
+
const ok = await crypto.subtle.verify(
|
|
700
|
+
"HMAC",
|
|
701
|
+
await hmacKey(secret),
|
|
702
|
+
fromB64url(token.slice(dot + 1)),
|
|
703
|
+
enc.encode(body)
|
|
704
|
+
);
|
|
705
|
+
if (!ok) return null;
|
|
706
|
+
const stamped = STAMPED.exec(body);
|
|
707
|
+
if (options.maxAgeSeconds !== void 0) {
|
|
708
|
+
if (!stamped) return null;
|
|
709
|
+
const issuedAt = Number(stamped[1]);
|
|
710
|
+
if ((options.now ?? Date.now)() / 1e3 - issuedAt > options.maxAgeSeconds) return null;
|
|
711
|
+
}
|
|
712
|
+
return new TextDecoder().decode(fromB64url(stamped?.[2] ?? body));
|
|
713
|
+
} catch {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
async function signSession(payload, secret) {
|
|
718
|
+
return signValue(JSON.stringify(payload), secret);
|
|
719
|
+
}
|
|
720
|
+
async function verifySession(token, secret, now = Date.now) {
|
|
721
|
+
const body = await verifyValue(token, secret);
|
|
722
|
+
if (body === null) return null;
|
|
723
|
+
try {
|
|
724
|
+
const payload = JSON.parse(body);
|
|
725
|
+
if (typeof payload.sub !== "string" || payload.sub === "") return null;
|
|
726
|
+
if (typeof payload.exp !== "number" || payload.exp * 1e3 <= now()) return null;
|
|
727
|
+
return payload;
|
|
728
|
+
} catch {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function cookieHeader(name, value, opts) {
|
|
733
|
+
const parts = [
|
|
734
|
+
`${name}=${value}`,
|
|
735
|
+
`Path=${opts.path ?? "/"}`,
|
|
736
|
+
`Max-Age=${opts.maxAge}`,
|
|
737
|
+
"HttpOnly",
|
|
738
|
+
// Lax, NOT Strict, and this is load-bearing: the callback from Broberg ID
|
|
739
|
+
// is a top-level GET navigation from another site. Strict withholds the
|
|
740
|
+
// cookie on exactly that navigation, so the login transaction cookie would
|
|
741
|
+
// be missing when it is needed and every sign-in would fail with "state
|
|
742
|
+
// does not match" — a message that sends you looking in the wrong place.
|
|
743
|
+
`SameSite=${opts.sameSite ?? "Lax"}`
|
|
744
|
+
];
|
|
745
|
+
if (opts.secure) parts.push("Secure");
|
|
746
|
+
return parts.join("; ");
|
|
747
|
+
}
|
|
748
|
+
function readCookie(header, name) {
|
|
749
|
+
if (!header) return void 0;
|
|
750
|
+
for (const part of header.split(";")) {
|
|
751
|
+
const eq = part.indexOf("=");
|
|
752
|
+
if (eq === -1) continue;
|
|
753
|
+
if (part.slice(0, eq).trim() === name) return part.slice(eq + 1).trim();
|
|
754
|
+
}
|
|
755
|
+
return void 0;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/tokens.ts
|
|
759
|
+
var warned = false;
|
|
760
|
+
function memoryTokenStore(options = {}) {
|
|
761
|
+
if (!options.quiet && !warned) {
|
|
762
|
+
warned = true;
|
|
763
|
+
console.warn(
|
|
764
|
+
"@broberg/sso: memoryTokenStore() keeps tokens in this process only \u2014 they are lost on restart and not shared between instances. Give ssoRoutes a TokenStore backed by your database in production."
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
const rows = /* @__PURE__ */ new Map();
|
|
768
|
+
return {
|
|
769
|
+
get size() {
|
|
770
|
+
return rows.size;
|
|
771
|
+
},
|
|
772
|
+
async get(sid) {
|
|
773
|
+
return rows.get(sid);
|
|
774
|
+
},
|
|
775
|
+
async set(sid, tokens) {
|
|
776
|
+
rows.set(sid, { ...tokens });
|
|
777
|
+
},
|
|
778
|
+
async delete(sid) {
|
|
779
|
+
rows.delete(sid);
|
|
780
|
+
},
|
|
781
|
+
async deleteSub(sub) {
|
|
782
|
+
for (const [sid, t] of rows) if (t.sub === sub) rows.delete(sid);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function expiresAtFrom(expiresIn, accessToken, now) {
|
|
787
|
+
if (typeof expiresIn === "number" && expiresIn > 0) return now + Math.floor(expiresIn);
|
|
788
|
+
const parts = accessToken.split(".");
|
|
789
|
+
if (parts.length === 3) {
|
|
790
|
+
try {
|
|
791
|
+
const json = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
792
|
+
if (typeof json.exp === "number" && json.exp > now) return json.exp;
|
|
793
|
+
} catch {
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return now + 300;
|
|
797
|
+
}
|
|
798
|
+
function newSid() {
|
|
799
|
+
const b = crypto.getRandomValues(new Uint8Array(16));
|
|
800
|
+
let s = "";
|
|
801
|
+
for (const x of b) s += String.fromCharCode(x);
|
|
802
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
exports.ALLOWED_ALGS = ALLOWED_ALGS;
|
|
806
|
+
exports.AVATAR_TYPES = AVATAR_TYPES;
|
|
807
|
+
exports.DEFAULT_SESSION_MAX_AGE = DEFAULT_SESSION_MAX_AGE;
|
|
808
|
+
exports.JwksError = JwksError;
|
|
809
|
+
exports.JwksUnavailableError = JwksUnavailableError;
|
|
810
|
+
exports.JwksUnknownKeyError = JwksUnknownKeyError;
|
|
811
|
+
exports.MAX_AVATAR_BYTES = MAX_AVATAR_BYTES;
|
|
812
|
+
exports.MAX_INVITATIONS = MAX_INVITATIONS;
|
|
813
|
+
exports.SsoAppApiError = SsoAppApiError;
|
|
814
|
+
exports.SsoAvatarRejectedError = SsoAvatarRejectedError;
|
|
815
|
+
exports.SsoConfigError = SsoConfigError;
|
|
816
|
+
exports.SsoError = SsoError;
|
|
817
|
+
exports.SsoInsufficientScopeError = SsoInsufficientScopeError;
|
|
818
|
+
exports.SsoReauthError = SsoReauthError;
|
|
819
|
+
exports.cookieHeader = cookieHeader;
|
|
820
|
+
exports.createJwksCache = createJwksCache;
|
|
821
|
+
exports.createSsoClient = createSsoClient;
|
|
822
|
+
exports.expiresAtFrom = expiresAtFrom;
|
|
823
|
+
exports.loadSsoConfig = loadSsoConfig;
|
|
824
|
+
exports.mediaType = mediaType;
|
|
825
|
+
exports.memoryTokenStore = memoryTokenStore;
|
|
826
|
+
exports.newSid = newSid;
|
|
827
|
+
exports.readCookie = readCookie;
|
|
828
|
+
exports.signSession = signSession;
|
|
829
|
+
exports.signValue = signValue;
|
|
830
|
+
exports.verifySession = verifySession;
|
|
831
|
+
exports.verifyValue = verifyValue;
|
|
832
|
+
//# sourceMappingURL=chunk-JGIO7XPR.cjs.map
|
|
833
|
+
//# sourceMappingURL=chunk-JGIO7XPR.cjs.map
|