zitejs 0.10.0-start.27 → 0.10.0-start.28
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/esm/signin/index.d.ts +1 -1
- package/dist/esm/signin/index.js +1 -1
- package/dist/esm/signin/keys.d.ts +22 -12
- package/dist/esm/signin/keys.js +118 -31
- package/dist/esm/signin/verify.d.ts +3 -2
- package/dist/esm/signin/verify.js +5 -3
- package/dist/esm/start/localSignIn.d.ts +2 -4
- package/dist/esm/start/localSignIn.js +4 -5
- package/dist/esm/start/server.js +1 -1
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM, type Resolution, type SignIn, type SignInConfig } from "./signin.js";
|
|
2
2
|
export { createIdentityVerifier, DEFAULT_MAX_LIFETIME_S, IDENTITY_TOKEN_TYPE, type IdentityClaims, type IdentityMode, type IdentityVerifier, type Refusal, type RefusalReport, type Verdict, type VerifyExpectations, } from "./verify.js";
|
|
3
|
-
export { identityKeys, remoteIdentityKeys, staticIdentityKeys, type IdentityKeys, type IdentityKeySource, } from "./keys.js";
|
|
3
|
+
export { discoveredIdentityKeys, identityKeys, remoteIdentityKeys, staticIdentityKeys, type IdentityKeys, type IdentityKeySource, } from "./keys.js";
|
|
4
4
|
export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES, type CookieContext, type ModuleCookie } from "./cookies.js";
|
|
5
5
|
export { aesGcmSealer, type Sealer } from "./seal.js";
|
|
6
6
|
export { httpTransport, type ClientAuth, type HttpTransportOptions } from "./http.js";
|
package/dist/esm/signin/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// bundle, in an app's Worker and on Node alike.
|
|
3
3
|
export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM } from "./signin.js";
|
|
4
4
|
export { createIdentityVerifier, DEFAULT_MAX_LIFETIME_S, IDENTITY_TOKEN_TYPE, } from "./verify.js";
|
|
5
|
-
export { identityKeys, remoteIdentityKeys, staticIdentityKeys, } from "./keys.js";
|
|
5
|
+
export { discoveredIdentityKeys, identityKeys, remoteIdentityKeys, staticIdentityKeys, } from "./keys.js";
|
|
6
6
|
export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES } from "./cookies.js";
|
|
7
7
|
export { aesGcmSealer } from "./seal.js";
|
|
8
8
|
export { httpTransport } from "./http.js";
|
|
@@ -5,26 +5,36 @@
|
|
|
5
5
|
export type IdentityKeys = Readonly<Record<string, string>>;
|
|
6
6
|
/** Where a verifier finds keys: what it holds now, and a refetch for a `kid` it doesn't know. */
|
|
7
7
|
export type IdentityKeySource = {
|
|
8
|
-
|
|
8
|
+
/** The keys to verify with; a source that fetches them fetches again first once what it holds is stale. */
|
|
9
|
+
current(): IdentityKeys | Promise<IdentityKeys>;
|
|
9
10
|
/** The keys after a refetch, or undefined when none happened (none configured, or one ran under a minute ago). */
|
|
10
11
|
refresh(): Promise<IdentityKeys | undefined>;
|
|
11
12
|
};
|
|
13
|
+
/** An Ed25519 key's JWS `alg`: RFC 9864's `Ed25519`, or the older `EdDSA`, which the identity server signs with. */
|
|
14
|
+
export declare const ED25519_ALGS: ReadonlySet<unknown>;
|
|
12
15
|
/**
|
|
13
|
-
* Parses the identity issuer's JWK Set
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Parses the identity issuer's JWK Set by the rule every verifier of it follows, restly's included. A key of a kind
|
|
17
|
+
* zitejs doesn't use (another `kty`, `crv` or `alg`, an RS256 key for other clients, say) is skipped and logged, as
|
|
18
|
+
* RFC 7517 §5 has it, so a key type the issuer adds later doesn't break an older zitejs. Anything else throws, so a bad
|
|
19
|
+
* deploy fails at once: a document that isn't a set, an Ed25519 key with a bad `x`, `kid` or `use`, a private member in
|
|
20
|
+
* any key, a `kid` two keys share, or no Ed25519 key at all.
|
|
16
21
|
*/
|
|
17
22
|
export declare const identityKeys: (json: string) => IdentityKeys;
|
|
18
23
|
/** Keys that never change: the dispatcher's configured set. */
|
|
19
24
|
export declare const staticIdentityKeys: (keys: IdentityKeys) => IdentityKeySource;
|
|
20
|
-
/**
|
|
25
|
+
/** How long a response may be held, in seconds, by its `Cache-Control` (RFC 9111 §5.2.2): its `max-age`, or none. */
|
|
26
|
+
export declare const maxAgeOf: (response: Response) => number;
|
|
27
|
+
type Fetch = (request: Request) => Promise<Response>;
|
|
28
|
+
type FetchOptions = {
|
|
29
|
+
fetch?: Fetch;
|
|
30
|
+
now?: () => number;
|
|
31
|
+
};
|
|
32
|
+
/** For tests: forget every fetched key set and discovery document. */
|
|
21
33
|
export declare const resetFetchedIdentityKeys: () => void;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
* Make one per request; concurrent refreshes on it share one fetch.
|
|
25
|
-
*/
|
|
26
|
-
export declare const remoteIdentityKeys: (url: string, options?: {
|
|
34
|
+
/** Keys from the JWK Set at `url`, as {@link fetchedIdentityKeys} holds them. */
|
|
35
|
+
export declare const remoteIdentityKeys: (url: string, options?: FetchOptions & {
|
|
27
36
|
initial?: IdentityKeys;
|
|
28
|
-
fetch?: (request: Request) => Promise<Response>;
|
|
29
|
-
now?: () => number;
|
|
30
37
|
}) => IdentityKeySource;
|
|
38
|
+
/** Keys from the JWK Set `issuer`'s discovery document names, as {@link remoteIdentityKeys} holds them. */
|
|
39
|
+
export declare const discoveredIdentityKeys: (issuer: string, options?: FetchOptions) => IdentityKeySource;
|
|
40
|
+
export {};
|
package/dist/esm/signin/keys.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import { fromBase64Url, isRecord } from "./encoding.js";
|
|
2
2
|
const KEY_SET_NAME = "the identity JWK Set";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
/** An Ed25519 key's JWS `alg`: RFC 9864's `Ed25519`, or the older `EdDSA`, which the identity server signs with. */
|
|
4
|
+
export const ED25519_ALGS = new Set(["EdDSA", "Ed25519"]);
|
|
5
|
+
// RFC 7518 §6's private members, of every key type.
|
|
6
|
+
const PRIVATE_MEMBERS = ["d", "p", "q", "dp", "dq", "qi", "oth", "k"];
|
|
7
|
+
// The kind of key the identity server signs with; a set may hold others, for other clients.
|
|
8
|
+
const isEd25519Kind = (jwk) => jwk.kty === "OKP" && jwk.crv === "Ed25519" && (jwk.alg === undefined || ED25519_ALGS.has(jwk.alg));
|
|
9
|
+
/** An Ed25519 key's `kid` and `x`, or what's wrong with it: an operator's typo, which fails at once, never skipped. */
|
|
10
|
+
const ed25519KeyOf = (jwk) => {
|
|
11
|
+
if (jwk.use !== undefined && jwk.use !== "sig")
|
|
12
|
+
return { problem: "use must be sig" };
|
|
13
|
+
if (typeof jwk.x !== "string" || fromBase64Url(jwk.x)?.length !== 32)
|
|
14
|
+
return { problem: "x must be a 32-byte key" };
|
|
15
|
+
if (typeof jwk.kid !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(jwk.kid))
|
|
16
|
+
return { problem: "kid must be 1 to 64 letters, digits, - or _" };
|
|
17
|
+
return { kid: jwk.kid, x: jwk.x };
|
|
18
|
+
};
|
|
19
|
+
// Each skipped key is logged once per process, and only so many: a fetched set is read again on every refetch.
|
|
20
|
+
const MAX_REPORTED_SKIPS = 32;
|
|
21
|
+
const reportedSkips = new Set();
|
|
22
|
+
const reportSkipped = (jwk) => {
|
|
23
|
+
const key = JSON.stringify({ kid: jwk.kid, kty: jwk.kty, crv: jwk.crv, alg: jwk.alg });
|
|
24
|
+
if (reportedSkips.has(key) || reportedSkips.size >= MAX_REPORTED_SKIPS)
|
|
25
|
+
return;
|
|
26
|
+
reportedSkips.add(key);
|
|
27
|
+
console.warn(`[zite] skipped a key of another kind in ${KEY_SET_NAME}: ${key.slice(0, 256)}`);
|
|
28
|
+
};
|
|
14
29
|
/**
|
|
15
|
-
* Parses the identity issuer's JWK Set
|
|
16
|
-
*
|
|
17
|
-
*
|
|
30
|
+
* Parses the identity issuer's JWK Set by the rule every verifier of it follows, restly's included. A key of a kind
|
|
31
|
+
* zitejs doesn't use (another `kty`, `crv` or `alg`, an RS256 key for other clients, say) is skipped and logged, as
|
|
32
|
+
* RFC 7517 §5 has it, so a key type the issuer adds later doesn't break an older zitejs. Anything else throws, so a bad
|
|
33
|
+
* deploy fails at once: a document that isn't a set, an Ed25519 key with a bad `x`, `kid` or `use`, a private member in
|
|
34
|
+
* any key, a `kid` two keys share, or no Ed25519 key at all.
|
|
18
35
|
*/
|
|
19
36
|
export const identityKeys = (json) => {
|
|
20
37
|
let parsed;
|
|
@@ -28,14 +45,26 @@ export const identityKeys = (json) => {
|
|
|
28
45
|
throw new Error(`${KEY_SET_NAME} must be a JSON object with a keys array`);
|
|
29
46
|
// No prototype, so a `kid` of `__proto__` is a key like any other.
|
|
30
47
|
const keys = Object.create(null);
|
|
31
|
-
for (const jwk of parsed.keys) {
|
|
32
|
-
const
|
|
33
|
-
|
|
48
|
+
for (const [index, jwk] of parsed.keys.entries()) {
|
|
49
|
+
const name = isRecord(jwk) && typeof jwk.kid === "string" ? jwk.kid.slice(0, 64) : `#${index}`;
|
|
50
|
+
const fail = (problem) => new Error(`${KEY_SET_NAME}: key ${name}: ${problem}`);
|
|
51
|
+
if (!isRecord(jwk))
|
|
52
|
+
throw fail("must be a JSON object");
|
|
53
|
+
if (PRIVATE_MEMBERS.some((member) => Object.hasOwn(jwk, member)))
|
|
54
|
+
throw fail("holds a private key");
|
|
55
|
+
if (!isEd25519Kind(jwk)) {
|
|
56
|
+
reportSkipped(jwk);
|
|
34
57
|
continue;
|
|
58
|
+
}
|
|
59
|
+
const key = ed25519KeyOf(jwk);
|
|
60
|
+
if ("problem" in key)
|
|
61
|
+
throw fail(key.problem);
|
|
35
62
|
if (Object.hasOwn(keys, key.kid))
|
|
36
63
|
throw new Error(`${KEY_SET_NAME}: key ${key.kid} is in it twice`);
|
|
37
64
|
keys[key.kid] = key.x;
|
|
38
65
|
}
|
|
66
|
+
if (Object.keys(keys).length === 0)
|
|
67
|
+
throw new Error(`${KEY_SET_NAME} holds no Ed25519 key`);
|
|
39
68
|
return keys;
|
|
40
69
|
};
|
|
41
70
|
/** Keys that never change: the dispatcher's configured set. */
|
|
@@ -45,31 +74,53 @@ export const staticIdentityKeys = (keys) => ({
|
|
|
45
74
|
});
|
|
46
75
|
const REFETCH_EVERY_MS = 60_000;
|
|
47
76
|
const FETCH_TIMEOUT_MS = 5_000;
|
|
48
|
-
//
|
|
49
|
-
|
|
77
|
+
// What the backend sends, and how long a set is held when its response names no max-age.
|
|
78
|
+
const DEFAULT_MAX_AGE_S = 300;
|
|
79
|
+
/** How long a response may be held, in seconds, by its `Cache-Control` (RFC 9111 §5.2.2): its `max-age`, or none. */
|
|
80
|
+
export const maxAgeOf = (response) => {
|
|
81
|
+
const directives = (response.headers.get("cache-control") ?? "")
|
|
82
|
+
.toLowerCase()
|
|
83
|
+
.split(",")
|
|
84
|
+
.map((directive) => directive.trim());
|
|
85
|
+
if (directives.includes("no-store") || directives.includes("no-cache"))
|
|
86
|
+
return 0;
|
|
87
|
+
const maxAge = directives.map((directive) => /^max-age=(\d+)$/.exec(directive)?.[1]).find((value) => value !== undefined);
|
|
88
|
+
return maxAge === undefined ? DEFAULT_MAX_AGE_S : Number(maxAge);
|
|
89
|
+
};
|
|
90
|
+
const getJson = (url, fetch = globalThis.fetch) => fetch(new Request(url, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) }));
|
|
91
|
+
// Per process, only fetched keys, when they were fetched and for how long they hold, and when a fetch last started:
|
|
92
|
+
// Workers ties a fetch to the request that made it, so a pending one is never shared across requests. Another request
|
|
93
|
+
// inside the minute keeps the keys it has.
|
|
50
94
|
const fetched = new Map();
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
// Per process, each issuer's `jwks_uri`, once its discovery document named it.
|
|
96
|
+
const discovered = new Map();
|
|
97
|
+
/** For tests: forget every fetched key set and discovery document. */
|
|
98
|
+
export const resetFetchedIdentityKeys = () => {
|
|
99
|
+
fetched.clear();
|
|
100
|
+
discovered.clear();
|
|
101
|
+
};
|
|
53
102
|
/**
|
|
54
|
-
* Keys from
|
|
55
|
-
*
|
|
103
|
+
* Keys from the JWK Set at `jwksUri()`, held per process under `id`. They're fetched when none are held, once the set
|
|
104
|
+
* is older than its response's `max-age` (five minutes without one), and on an unknown `kid`, at most once a minute
|
|
105
|
+
* in all. A failed fetch keeps the keys held. Make one per request; concurrent fetches on it share one.
|
|
56
106
|
*/
|
|
57
|
-
|
|
107
|
+
const fetchedIdentityKeys = (id, jwksUri, options) => {
|
|
58
108
|
const now = options.now ?? Date.now;
|
|
59
109
|
let refreshing;
|
|
60
110
|
const load = async () => {
|
|
61
|
-
const held = fetched.get(
|
|
111
|
+
const held = fetched.get(id);
|
|
62
112
|
const startedAt = now();
|
|
63
113
|
if (held && startedAt - held.startedAt < REFETCH_EVERY_MS)
|
|
64
114
|
return undefined;
|
|
65
|
-
fetched.set(
|
|
115
|
+
fetched.set(id, { ...held, startedAt });
|
|
116
|
+
let url = id;
|
|
66
117
|
try {
|
|
67
|
-
|
|
68
|
-
const response = await (options.fetch
|
|
118
|
+
url = await jwksUri();
|
|
119
|
+
const response = await getJson(url, options.fetch);
|
|
69
120
|
if (!response.ok)
|
|
70
121
|
throw new Error(`${response.status}`);
|
|
71
122
|
const keys = identityKeys(await response.text());
|
|
72
|
-
fetched.set(
|
|
123
|
+
fetched.set(id, { keys, fetchedAt: now(), maxAgeMs: maxAgeOf(response) * 1000, startedAt });
|
|
73
124
|
return keys;
|
|
74
125
|
}
|
|
75
126
|
catch (error) {
|
|
@@ -77,8 +128,44 @@ export const remoteIdentityKeys = (url, options = {}) => {
|
|
|
77
128
|
return undefined;
|
|
78
129
|
}
|
|
79
130
|
};
|
|
131
|
+
const refresh = () => (refreshing ??= load());
|
|
132
|
+
const held = () => fetched.get(id)?.keys ?? options.initial ?? {};
|
|
80
133
|
return {
|
|
81
|
-
current: () =>
|
|
82
|
-
|
|
134
|
+
current: () => {
|
|
135
|
+
const entry = fetched.get(id);
|
|
136
|
+
const fresh = entry?.keys !== undefined && entry.fetchedAt !== undefined && now() - entry.fetchedAt < (entry.maxAgeMs ?? 0);
|
|
137
|
+
return fresh ? held() : refresh().then((keys) => keys ?? held());
|
|
138
|
+
},
|
|
139
|
+
refresh,
|
|
83
140
|
};
|
|
84
141
|
};
|
|
142
|
+
/** Keys from the JWK Set at `url`, as {@link fetchedIdentityKeys} holds them. */
|
|
143
|
+
export const remoteIdentityKeys = (url, options = {}) => fetchedIdentityKeys(url, async () => url, options);
|
|
144
|
+
const isHttpUrl = (value) => {
|
|
145
|
+
try {
|
|
146
|
+
return typeof value === "string" && /^https?:$/.test(new URL(value).protocol);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* The `jwks_uri` of `issuer`'s discovery document (OpenID Connect Discovery 1.0 §4), fetched once per process. It must
|
|
154
|
+
* name this issuer (§4.3), and an http(s) URL.
|
|
155
|
+
*/
|
|
156
|
+
const jwksUriOf = async (issuer, fetch) => {
|
|
157
|
+
const held = discovered.get(issuer);
|
|
158
|
+
if (held)
|
|
159
|
+
return held;
|
|
160
|
+
const response = await getJson(`${issuer.replace(/\/$/, "")}/.well-known/openid-configuration`, fetch);
|
|
161
|
+
if (!response.ok)
|
|
162
|
+
throw new Error(`discovery answered ${response.status}`);
|
|
163
|
+
const metadata = await response.json();
|
|
164
|
+
const jwksUri = isRecord(metadata) && metadata.issuer === issuer ? metadata.jwks_uri : undefined;
|
|
165
|
+
if (!isHttpUrl(jwksUri))
|
|
166
|
+
throw new Error(`${issuer}'s discovery document names no jwks_uri for it`);
|
|
167
|
+
discovered.set(issuer, jwksUri);
|
|
168
|
+
return jwksUri;
|
|
169
|
+
};
|
|
170
|
+
/** Keys from the JWK Set `issuer`'s discovery document names, as {@link remoteIdentityKeys} holds them. */
|
|
171
|
+
export const discoveredIdentityKeys = (issuer, options = {}) => fetchedIdentityKeys(`${issuer}/.well-known/openid-configuration`, () => jwksUriOf(issuer, options.fetch), options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IdentityKeySource } from "./keys.js";
|
|
2
2
|
export type IdentityMode = "live" | "preview" | "demo" | "dev";
|
|
3
3
|
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
4
4
|
export declare const IDENTITY_TOKEN_TYPE = "zite-id+jwt";
|
|
@@ -68,7 +68,8 @@ export type RefusalReport = {
|
|
|
68
68
|
kid?: string;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
|
-
* Verifies identity tokens against `keys`, in §6.1's order
|
|
71
|
+
* Verifies identity tokens against `keys`, in §6.1's order, the header's `alg` `EdDSA` or RFC 9864's `Ed25519`. A
|
|
72
|
+
* `kid` the keys don't know triggers one refetch. Each
|
|
72
73
|
* refusal is reported to `onRefusal`, by default logged once per reason and key id.
|
|
73
74
|
*/
|
|
74
75
|
export declare const createIdentityVerifier: (keys: IdentityKeySource, options?: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The identity token's verifier (T5 design §6.1), the same rules as restly's `identityToken.ts` on the front and the
|
|
2
2
|
// dispatcher. Web Crypto only.
|
|
3
3
|
import { fromBase64Url, isRecord, jsonOf, utf8 } from "./encoding.js";
|
|
4
|
+
import { ED25519_ALGS } from "./keys.js";
|
|
4
5
|
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
5
6
|
export const IDENTITY_TOKEN_TYPE = "zite-id+jwt";
|
|
6
7
|
export const DEFAULT_MAX_LIFETIME_S = 300;
|
|
@@ -85,7 +86,8 @@ const reportOnce = (report) => {
|
|
|
85
86
|
console.warn(`[zite] refused an identity token: ${report.reason}${report.kid ? ` (kid ${report.kid})` : ""}`);
|
|
86
87
|
};
|
|
87
88
|
/**
|
|
88
|
-
* Verifies identity tokens against `keys`, in §6.1's order
|
|
89
|
+
* Verifies identity tokens against `keys`, in §6.1's order, the header's `alg` `EdDSA` or RFC 9864's `Ed25519`. A
|
|
90
|
+
* `kid` the keys don't know triggers one refetch. Each
|
|
89
91
|
* refusal is reported to `onRefusal`, by default logged once per reason and key id.
|
|
90
92
|
*/
|
|
91
93
|
export const createIdentityVerifier = (keys, options = {}) => async (token, expect) => {
|
|
@@ -103,7 +105,7 @@ export const createIdentityVerifier = (keys, options = {}) => async (token, expe
|
|
|
103
105
|
const signature = fromBase64Url(signaturePart);
|
|
104
106
|
if (!isRecord(header) || !isRecord(payload) || !signature)
|
|
105
107
|
return refuse("malformed");
|
|
106
|
-
if (header.alg
|
|
108
|
+
if (!ED25519_ALGS.has(header.alg))
|
|
107
109
|
return refuse("alg");
|
|
108
110
|
if (header.typ !== IDENTITY_TOKEN_TYPE)
|
|
109
111
|
return refuse("typ");
|
|
@@ -111,7 +113,7 @@ export const createIdentityVerifier = (keys, options = {}) => async (token, expe
|
|
|
111
113
|
if (kid === undefined)
|
|
112
114
|
return refuse("kid");
|
|
113
115
|
const own = (map) => (map && Object.hasOwn(map, kid) ? map[kid] : undefined);
|
|
114
|
-
const raw = own(keys.current()) ?? own(await keys.refresh());
|
|
116
|
+
const raw = own(await keys.current()) ?? own(await keys.refresh());
|
|
115
117
|
if (!raw)
|
|
116
118
|
return refuse("kid", kid);
|
|
117
119
|
const key = await publicKey(raw);
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import type { IdentityClaims, SignIn } from "../signin/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { User } from "./types.js";
|
|
3
3
|
/** What the module reads, from env or from the `.zite/dev.env` that `zitejs dev` writes. */
|
|
4
4
|
export declare const LOCAL_SIGNIN_ENV: {
|
|
5
5
|
readonly config: "ZITE_SIGNIN";
|
|
6
6
|
readonly secret: "ZITE_AUTH_SECRET";
|
|
7
7
|
};
|
|
8
8
|
type Env = Record<string, string | undefined>;
|
|
9
|
-
/** Where the backend serves the identity issuer's JWK Set, for an unknown `kid`. */
|
|
10
|
-
export declare const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
11
9
|
/**
|
|
12
10
|
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
13
11
|
* set: the stand-in wins, with no network, as agent sandboxes need.
|
|
14
12
|
*/
|
|
15
|
-
export declare const localSignIn: (env: Env,
|
|
13
|
+
export declare const localSignIn: (env: Env, request: Request) => Promise<SignIn | undefined>;
|
|
16
14
|
/** The identity as app code reads it. Off Zite no role names are known, so each role is named by its id. */
|
|
17
15
|
export declare const userOfIdentity: (claims: IdentityClaims | null) => User | null;
|
|
18
16
|
export {};
|
|
@@ -20,14 +20,12 @@ const configOf = (raw) => {
|
|
|
20
20
|
}
|
|
21
21
|
return config;
|
|
22
22
|
};
|
|
23
|
-
/** Where the backend serves the identity issuer's JWK Set, for an unknown `kid`. */
|
|
24
|
-
export const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
25
23
|
const send = (request) => platformFetch(request);
|
|
26
24
|
/**
|
|
27
25
|
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
28
26
|
* set: the stand-in wins, with no network, as agent sandboxes need.
|
|
29
27
|
*/
|
|
30
|
-
export const localSignIn = async (env,
|
|
28
|
+
export const localSignIn = async (env, request) => {
|
|
31
29
|
if (env[LOCAL_ENV.user])
|
|
32
30
|
return undefined;
|
|
33
31
|
const raw = env[LOCAL_SIGNIN_ENV.config] ?? devSignIn?.[LOCAL_SIGNIN_ENV.config];
|
|
@@ -41,7 +39,7 @@ export const localSignIn = async (env, urls, request) => {
|
|
|
41
39
|
// Only the developer's client for now; a self-hosted one comes with private key JWT.
|
|
42
40
|
if (mode !== "dev")
|
|
43
41
|
throw new Error(`${LOCAL_SIGNIN_ENV.config} names ${config.clientId}; off Zite the client is <app>:dev`);
|
|
44
|
-
const { aesGcmSealer, createSignIn, httpTransport, remoteIdentityKeys } = await import("../signin/index.js");
|
|
42
|
+
const { aesGcmSealer, createSignIn, discoveredIdentityKeys, httpTransport, remoteIdentityKeys } = await import("../signin/index.js");
|
|
45
43
|
const sealer = aesGcmSealer(secret);
|
|
46
44
|
return createSignIn({
|
|
47
45
|
issuer: config.issuer,
|
|
@@ -50,7 +48,8 @@ export const localSignIn = async (env, urls, request) => {
|
|
|
50
48
|
mode,
|
|
51
49
|
ver: "any",
|
|
52
50
|
redirectUri: config.redirectUri,
|
|
53
|
-
|
|
51
|
+
// The issuer's discovery document names its JWK Set (OpenID Connect Discovery 1.0); `keysUrl` overrides it.
|
|
52
|
+
keys: config.keysUrl ? remoteIdentityKeys(config.keysUrl, { fetch: send }) : discoveredIdentityKeys(config.issuer, { fetch: send }),
|
|
54
53
|
cookies: { secure: new URL(request.url).protocol === "https:", framed: false },
|
|
55
54
|
transport: httpTransport({
|
|
56
55
|
issuer: config.issuer,
|
package/dist/esm/start/server.js
CHANGED
|
@@ -510,7 +510,7 @@ const signInLocally = async (request, local) => {
|
|
|
510
510
|
if (!local.urls || invokeOf(request.headers, UNHOSTED_INVOKE_KINDS) || pathname === ANALYTICS_PATH || pathname === UPLOAD_SESSION_PATH) {
|
|
511
511
|
return undefined;
|
|
512
512
|
}
|
|
513
|
-
const signIn = await localSignIn(globalThis.process?.env ?? {},
|
|
513
|
+
const signIn = await localSignIn(globalThis.process?.env ?? {}, request);
|
|
514
514
|
if (!signIn)
|
|
515
515
|
return undefined;
|
|
516
516
|
const answered = await signIn.handle(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.0-start.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.0-start.28";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = "0.10.0-start.
|
|
2
|
+
export const ZITEJS_VERSION = "0.10.0-start.28";
|