@softistx/alxia-react-router 0.86.4 → 0.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -5
- package/dist/chunks/{index-t2ph23wk.js → index-5hjhzztk.js} +6 -17
- package/dist/chunks/{index-t2ph23wk.js.map → index-5hjhzztk.js.map} +3 -4
- package/dist/chunks/{index-v2z5k640.js → index-6zx9dfvs.js} +3 -18
- package/dist/chunks/{index-v2z5k640.js.map → index-6zx9dfvs.js.map} +3 -4
- package/dist/chunks/{index-xd5aqy3g.js → index-c721mm5a.js} +26 -3
- package/dist/chunks/{index-xd5aqy3g.js.map → index-c721mm5a.js.map} +4 -3
- package/dist/chunks/index-njfh26ez.js +19 -0
- package/dist/chunks/index-njfh26ez.js.map +10 -0
- package/dist/chunks/index-t68hwhz1.js +37 -0
- package/dist/chunks/{index-0786n4qe.js.map → index-t68hwhz1.js.map} +5 -4
- package/dist/errors/index.js +7 -4
- package/dist/errors/index.js.map +2 -2
- package/dist/errors/use-json-fetcher.d.ts +10 -1
- package/dist/errors/use-json-fetcher.d.ts.map +1 -1
- package/dist/fetcher/index.js +3 -5
- package/dist/fetcher/index.js.map +2 -2
- package/dist/oidc/dpop-fetch.d.ts +39 -0
- package/dist/oidc/dpop-fetch.d.ts.map +1 -0
- package/dist/oidc/env.d.ts +52 -0
- package/dist/oidc/env.d.ts.map +1 -0
- package/dist/oidc/index.d.ts +3 -0
- package/dist/oidc/index.d.ts.map +1 -1
- package/dist/oidc/index.js +248 -24
- package/dist/oidc/index.js.map +8 -5
- package/dist/oidc/oidc.d.ts +18 -0
- package/dist/oidc/oidc.d.ts.map +1 -1
- package/dist/oidc/routes.d.ts +76 -0
- package/dist/oidc/routes.d.ts.map +1 -0
- package/dist/session/index.js +9 -7
- package/dist/session/index.js.map +2 -2
- package/dist/session/model/index.js +2 -2
- package/dist/session/react/index.js +4 -6
- package/dist/session/react/index.js.map +2 -2
- package/docs/README.md +1 -1
- package/docs/guide/errors.md +21 -2
- package/docs/guide/fetcher.md +28 -0
- package/docs/guide/oidc.md +172 -6
- package/docs/roadmap.md +13 -0
- package/docs/troubleshooting.md +109 -0
- package/package.json +7 -7
- package/dist/chunks/index-0786n4qe.js +0 -25
- package/dist/chunks/index-ajtvyq35.js +0 -16
- package/dist/chunks/index-ajtvyq35.js.map +0 -10
package/dist/fetcher/index.js
CHANGED
|
@@ -4,11 +4,9 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
FetcherPromiseAborted2,
|
|
6
6
|
FetcherPromiseNoAnswer2,
|
|
7
|
-
useFetcherPromise2
|
|
8
|
-
} from "../chunks/index-xd5aqy3g.js";
|
|
9
|
-
import {
|
|
7
|
+
useFetcherPromise2,
|
|
10
8
|
useJsonFetcher2
|
|
11
|
-
} from "../chunks/index-
|
|
9
|
+
} from "../chunks/index-c721mm5a.js";
|
|
12
10
|
|
|
13
11
|
// src/fetcher/auth-refusal.ts
|
|
14
12
|
function authRefusal(answer, fields) {
|
|
@@ -388,5 +386,5 @@ export {
|
|
|
388
386
|
useVisibleRevalidation
|
|
389
387
|
};
|
|
390
388
|
|
|
391
|
-
//# debugId=
|
|
389
|
+
//# debugId=50AA4C0BEA2518B564756E2164756E21
|
|
392
390
|
//# sourceMappingURL=index.js.map
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"import { useEffect, useRef } from 'react';\n\nexport interface VisibleIntervalOptions {\n\t/** `false` stops the timer. Default `true`. */\n\treadonly enabled?: boolean;\n\t/**\n\t * Run the callback as soon as a hidden page becomes visible again, when at\n\t * least the interval has passed since its last run. Default `true`.\n\t */\n\treadonly runOnVisible?: boolean;\n}\n\n/**\n * Runs `callback` every `ms` **only while the page is visible**\n * (`document.visibilityState`), for a screen that has no real-time channel\n * (a revalidation, a fetcher's `load`). A tick that fires while the page is\n * hidden is skipped; when the page becomes visible again after at least `ms`\n * since the last run, the callback runs at once (`runOnVisible`); a page that\n * comes back sooner waits for the next tick. The timer and the listener are\n * cleared on unmount and while `enabled` is false. `ms` must be positive.\n *\n * The callback is read from a ref: a new function each render never restarts\n * the timer, and the latest one runs. Skipping a read already in flight is the\n * callback's to decide. On the server nothing starts (effects do not run).\n */\nexport function useVisibleInterval(\n\tcallback: () => void,\n\tms: number,\n\toptions: VisibleIntervalOptions = {},\n): void {\n\tconst { enabled = true, runOnVisible = true } = options;\n\tconst latest = useRef(callback);\n\tlatest.current = callback;\n\n\tuseEffect(() => {\n\t\tif (!enabled || ms <= 0) return;\n\t\tlet last = Date.now();\n\t\tconst run = () => {\n\t\t\tif (document.visibilityState !== 'visible') return;\n\t\t\tlast = Date.now();\n\t\t\tlatest.current();\n\t\t};\n\t\tconst timer = setInterval(run, ms);\n\t\tconst back = () => {\n\t\t\tif (runOnVisible && Date.now() - last >= ms) run();\n\t\t};\n\t\tdocument.addEventListener('visibilitychange', back);\n\t\treturn () => {\n\t\t\tclearInterval(timer);\n\t\t\tdocument.removeEventListener('visibilitychange', back);\n\t\t};\n\t}, [ms, enabled, runOnVisible]);\n}\n",
|
|
16
16
|
"import { useRevalidator } from 'react-router';\nimport {\n\tuseVisibleInterval,\n\ttype VisibleIntervalOptions,\n} from './use-visible-interval';\n\n/**\n * Runs the current route's loaders again every `ms`, **only while the page is\n * visible**, and at once when a hidden page comes back after more than `ms`\n * (`useVisibleInterval` over React Router's `useRevalidator`). A revalidation\n * already in flight is not doubled. `enabled: false` stops it (a menu is open,\n * a change is in flight).\n */\nexport function useVisibleRevalidation(\n\tms: number,\n\toptions?: Pick<VisibleIntervalOptions, 'enabled'>,\n): void {\n\tconst revalidator = useRevalidator();\n\tuseVisibleInterval(\n\t\t() => {\n\t\t\tif (revalidator.state === 'idle') void revalidator.revalidate();\n\t\t},\n\t\tms,\n\t\toptions,\n\t);\n}\n"
|
|
17
17
|
],
|
|
18
|
-
"mappings": "
|
|
19
|
-
"debugId": "
|
|
18
|
+
"mappings": ";;;;;;;;;;;AA2BO,SAAS,WAAmC,CAClD,QACA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|
19
|
+
"debugId": "50AA4C0BEA2518B564756E2164756E21",
|
|
20
20
|
"names": []
|
|
21
21
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OidcClient, OidcUser } from './oidc';
|
|
2
|
+
/** A `fetch` that calls a resource as one signed-in user. */
|
|
3
|
+
export type DpopFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
/** The part of the relying party `dpopFetch` needs. */
|
|
5
|
+
export type DpopRefresher = Pick<OidcClient, 'refresh'>;
|
|
6
|
+
/** Options of {@link dpopFetch}. */
|
|
7
|
+
export interface DpopFetchOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Called with the new user each time the access token or its expiry changes
|
|
10
|
+
* (parallel calls sharing one refresh report it once). Its `headers` hold the
|
|
11
|
+
* `Set-Cookie` to pass with the route's answer (the last one wins: each refresh
|
|
12
|
+
* starts from the previous user, so the cookie it sets replaces the older one).
|
|
13
|
+
*/
|
|
14
|
+
readonly onUser?: ((user: OidcUser) => void) | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `fetch` for the calls a loader or an action makes to an API as the signed-in
|
|
18
|
+
* user. On a DPoP-bound session (`oidcClient`'s `dpop` option) each call carries
|
|
19
|
+
* `Authorization: DPoP <token>` and a fresh proof (`htm`, `htu` without its
|
|
20
|
+
* query, `ath`, `jti`), and a `401` with `WWW-Authenticate: DPoP
|
|
21
|
+
* error="use_dpop_nonce"` is signed again with the `DPoP-Nonce` sent and
|
|
22
|
+
* retried once; the nonce is remembered per server. On a bearer session it
|
|
23
|
+
* sends `Authorization: Bearer <token>` through the client's own `fetch`.
|
|
24
|
+
*
|
|
25
|
+
* It keeps the last user it got. Before each call it asks `oidc.refresh` for a
|
|
26
|
+
* fresh one, which refreshes from that user's own tokens (never the request's
|
|
27
|
+
* cookie, whose refresh token a rotation spends) only when the access token
|
|
28
|
+
* ends within `refreshSkewSeconds`. A body must be a string or bytes, since a
|
|
29
|
+
* stream cannot be sent twice.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const user = await oidc.requireOidcUser(request);
|
|
33
|
+
* let latest = user;
|
|
34
|
+
* const api = dpopFetch(oidc, user, { onUser: (next) => (latest = next) });
|
|
35
|
+
* const orders = await (await api('https://api.example.com/orders?page=2')).json();
|
|
36
|
+
* return data({ orders }, { headers: latest.headers });
|
|
37
|
+
*/
|
|
38
|
+
export declare function dpopFetch(oidc: DpopRefresher, user: OidcUser, options?: DpopFetchOptions): DpopFetch;
|
|
39
|
+
//# sourceMappingURL=dpop-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dpop-fetch.d.ts","sourceRoot":"","sources":["../../src/oidc/dpop-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEnD,6DAA6D;AAC7D,MAAM,MAAM,SAAS,GAAG,CACvB,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,IAAI,CAAC,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,uDAAuD;AACvD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAExD,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACzD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,aAAa,EACnB,IAAI,EAAE,QAAQ,EACd,OAAO,GAAE,gBAAqB,GAC5B,SAAS,CAgBX"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OidcOptions } from './oidc';
|
|
2
|
+
/** Every start-up problem of the environment, in one error. */
|
|
3
|
+
export declare class OidcEnvError extends Error {
|
|
4
|
+
readonly problems: readonly string[];
|
|
5
|
+
readonly name = "OidcEnvError";
|
|
6
|
+
constructor(problems: readonly string[]);
|
|
7
|
+
}
|
|
8
|
+
/** What {@link oidcFromEnv} reads. */
|
|
9
|
+
export interface OidcEnvSource {
|
|
10
|
+
/** The variables' prefix. `'OIDC'` by default (`OIDC_ISSUER`, …). */
|
|
11
|
+
readonly prefix?: string | undefined;
|
|
12
|
+
/** The environment; `process.env` by default. */
|
|
13
|
+
readonly env?: Readonly<Record<string, string | undefined>> | undefined;
|
|
14
|
+
/** Reads a secret file; `Bun.file(path).text()` by default. */
|
|
15
|
+
readonly readFile?: ((path: string) => Promise<string>) | undefined;
|
|
16
|
+
/** Gives a secret file's `mode`, to refuse one that group or others can read; `Bun.file(path).stat()` by default. */
|
|
17
|
+
readonly statFile?: ((path: string) => Promise<{
|
|
18
|
+
readonly mode: number;
|
|
19
|
+
}>) | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** What {@link oidcFromEnv} gives: spread it into `oidcClient`, with `secure`. */
|
|
22
|
+
export type OidcEnvOptions = Pick<OidcOptions, 'issuer' | 'clientId' | 'clientSecret' | 'redirectUri' | 'secret' | 'name' | 'postLogoutRedirectUri'>;
|
|
23
|
+
/**
|
|
24
|
+
* The relying party's settings from the environment, checked once at start-up:
|
|
25
|
+
* every missing or malformed variable is listed in one `OidcEnvError`, never a
|
|
26
|
+
* secret's value. `secure` is not read from the environment: give it to
|
|
27
|
+
* `oidcClient` yourself (`secure: !import.meta.env.DEV`).
|
|
28
|
+
*
|
|
29
|
+
* | variable (prefix `OIDC`) | |
|
|
30
|
+
* | --- | --- |
|
|
31
|
+
* | `OIDC_ISSUER` | required, an `https:` URL (`http:` on loopback) |
|
|
32
|
+
* | `OIDC_CLIENT_ID` | required |
|
|
33
|
+
* | `OIDC_CLIENT_SECRET_FILE` or `OIDC_CLIENT_SECRET` | the secret of a confidential client; none for a public one |
|
|
34
|
+
* | `OIDC_REDIRECT_URI` | required, an `https:` URL (`http:` on loopback) |
|
|
35
|
+
* | `OIDC_SESSION_SECRET_FILE` or `OIDC_SESSION_SECRET` | required, 32 characters or more |
|
|
36
|
+
* | `OIDC_COOKIE_NAME` | `'oidc'` by default |
|
|
37
|
+
* | `OIDC_POST_LOGOUT_REDIRECT_URI` | optional, an `https:` URL (`http:` on loopback) |
|
|
38
|
+
*
|
|
39
|
+
* A `_FILE` variable names a file whose trimmed content is the value, and
|
|
40
|
+
* that only its owner can read (no group or other permission bit), with no
|
|
41
|
+
* whitespace inside; a message never prints the path. Prefer it to the plain
|
|
42
|
+
* variable for a secret.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* export const oidc = oidcClient({
|
|
46
|
+
* ...(await oidcFromEnv()),
|
|
47
|
+
* secure: !import.meta.env.DEV,
|
|
48
|
+
* scopes: ['profile', 'email', 'offline_access'],
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
export declare function oidcFromEnv(source?: OidcEnvSource): Promise<OidcEnvOptions>;
|
|
52
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/oidc/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,+DAA+D;AAC/D,qBAAa,YAAa,SAAQ,KAAK;IAE1B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;IADhD,SAAkB,IAAI,kBAAkB;gBACnB,QAAQ,EAAE,SAAS,MAAM,EAAE;CAKhD;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC7B,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,iDAAiD;IACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IACxE,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IACpE,qHAAqH;IACrH,QAAQ,CAAC,QAAQ,CAAC,EACf,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,GACtD,SAAS,CAAC;CACb;AAED,kFAAkF;AAClF,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,WAAW,EACT,QAAQ,GACR,UAAU,GACV,cAAc,GACd,aAAa,GACb,QAAQ,GACR,MAAM,GACN,uBAAuB,CACzB,CAAC;AAiHF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,WAAW,CAChC,MAAM,GAAE,aAAkB,GACxB,OAAO,CAAC,cAAc,CAAC,CAqCzB"}
|
package/dist/oidc/index.d.ts
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* nothing else.
|
|
7
7
|
*/
|
|
8
8
|
export { type DpopAlgorithm, type DpopBinding, type DpopKey, type DpopProofInput, generateDpopKey, signDpopProof, } from './dpop';
|
|
9
|
+
export { type DpopFetch, type DpopFetchOptions, type DpopRefresher, dpopFetch, } from './dpop-fetch';
|
|
10
|
+
export { OidcEnvError, type OidcEnvOptions, type OidcEnvSource, oidcFromEnv, } from './env';
|
|
9
11
|
export { OidcError, type OidcErrorCode } from './errors';
|
|
10
12
|
export { type OidcClient, type OidcOptions, type OidcUser, oidcClient, } from './oidc';
|
|
13
|
+
export { type CallbackRouteOptions, callbackRoute, type SignInRouteOptions, type SignOutRouteOptions, signInRoute, signOutRoute, } from './routes';
|
|
11
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/oidc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,eAAe,EACf,aAAa,GACb,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EACN,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,UAAU,GACV,MAAM,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,eAAe,EACf,aAAa,GACb,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,WAAW,GACX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EACN,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,UAAU,GACV,MAAM,QAAQ,CAAC;AAChB,OAAO,EACN,KAAK,oBAAoB,EACzB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,WAAW,EACX,YAAY,GACZ,MAAM,UAAU,CAAC"}
|
package/dist/oidc/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
siteCheck
|
|
3
|
+
} from "../chunks/index-6zx9dfvs.js";
|
|
1
4
|
import {
|
|
2
5
|
sessionCookies2
|
|
3
6
|
} from "../chunks/index-1nw5yeek.js";
|
|
4
7
|
import {
|
|
5
|
-
safeNext2
|
|
6
|
-
|
|
8
|
+
safeNext2,
|
|
9
|
+
sitePath
|
|
10
|
+
} from "../chunks/index-t68hwhz1.js";
|
|
7
11
|
|
|
8
12
|
// src/oidc/dpop.ts
|
|
9
13
|
import {
|
|
@@ -161,6 +165,135 @@ function dpopBinding(config) {
|
|
|
161
165
|
}
|
|
162
166
|
};
|
|
163
167
|
}
|
|
168
|
+
// src/oidc/dpop-fetch.ts
|
|
169
|
+
function dpopFetch(oidc, user, options = {}) {
|
|
170
|
+
let last = user;
|
|
171
|
+
return async (input, init) => {
|
|
172
|
+
const next = await oidc.refresh(last);
|
|
173
|
+
if (next.accessToken !== last.accessToken || next.expiresAt !== last.expiresAt) {
|
|
174
|
+
last = next;
|
|
175
|
+
options.onUser?.(next);
|
|
176
|
+
}
|
|
177
|
+
if (last.dpop)
|
|
178
|
+
return last.dpop.fetch(input, init);
|
|
179
|
+
const headers = new Headers(init?.headers);
|
|
180
|
+
headers.set("authorization", `Bearer ${last.accessToken}`);
|
|
181
|
+
return last.fetch(String(input), { ...init, headers });
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// src/oidc/env.ts
|
|
185
|
+
class OidcEnvError extends Error {
|
|
186
|
+
problems;
|
|
187
|
+
name = "OidcEnvError";
|
|
188
|
+
constructor(problems) {
|
|
189
|
+
super(`The OIDC environment is not usable:
|
|
190
|
+
${problems.map((p) => `- ${p}`).join(`
|
|
191
|
+
`)}`);
|
|
192
|
+
this.problems = problems;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
var LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
196
|
+
var named = (context, suffix) => `${context.prefix}_${suffix}`;
|
|
197
|
+
function plain(context, suffix) {
|
|
198
|
+
const value = context.env[named(context, suffix)]?.trim();
|
|
199
|
+
return value ? value : undefined;
|
|
200
|
+
}
|
|
201
|
+
function required(context, suffix) {
|
|
202
|
+
const value = plain(context, suffix);
|
|
203
|
+
if (value === undefined) {
|
|
204
|
+
context.problems.push(`${named(context, suffix)} is not set.`);
|
|
205
|
+
}
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
function url(context, suffix, mandatory) {
|
|
209
|
+
const value = mandatory ? required(context, suffix) : plain(context, suffix);
|
|
210
|
+
if (value === undefined)
|
|
211
|
+
return;
|
|
212
|
+
const variable = named(context, suffix);
|
|
213
|
+
let parsed;
|
|
214
|
+
try {
|
|
215
|
+
parsed = new URL(value);
|
|
216
|
+
} catch {
|
|
217
|
+
context.problems.push(`${variable} is not an absolute URL.`);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && LOOPBACK.has(parsed.hostname))) {
|
|
221
|
+
context.problems.push(`${variable} must be an https: URL.`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
async function secret(context, suffix, mandatory) {
|
|
227
|
+
const direct = plain(context, suffix);
|
|
228
|
+
const fileSuffix = `${suffix}_FILE`;
|
|
229
|
+
const path = plain(context, fileSuffix);
|
|
230
|
+
if (direct !== undefined && path !== undefined) {
|
|
231
|
+
context.problems.push(`Set ${named(context, suffix)} or ${named(context, fileSuffix)}, not both.`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (path === undefined) {
|
|
235
|
+
if (direct !== undefined) {
|
|
236
|
+
return { value: direct, variable: named(context, suffix) };
|
|
237
|
+
}
|
|
238
|
+
if (mandatory) {
|
|
239
|
+
context.problems.push(`${named(context, fileSuffix)} (or ${named(context, suffix)}) is not set.`);
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const variable = named(context, fileSuffix);
|
|
244
|
+
let text;
|
|
245
|
+
try {
|
|
246
|
+
const { mode } = await context.statFile(path);
|
|
247
|
+
if ((mode & 63) !== 0) {
|
|
248
|
+
context.problems.push(`${variable} names a file readable by group or others (mode ${(mode & 511).toString(8)}); restrict it to its owner, such as chmod 600.`);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
text = await context.readFile(path);
|
|
252
|
+
} catch {
|
|
253
|
+
context.problems.push(`${variable} names a file that cannot be read: check the path and its permissions.`);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const value = text.trim();
|
|
257
|
+
if (value === "") {
|
|
258
|
+
context.problems.push(`${variable} names an empty file.`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (/\s/.test(value)) {
|
|
262
|
+
context.problems.push(`${variable} names a file with whitespace inside: it must hold one value.`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
return { value, variable };
|
|
266
|
+
}
|
|
267
|
+
async function oidcFromEnv(source = {}) {
|
|
268
|
+
const context = {
|
|
269
|
+
env: source.env ?? process.env,
|
|
270
|
+
prefix: source.prefix ?? "OIDC",
|
|
271
|
+
problems: [],
|
|
272
|
+
readFile: source.readFile ?? ((path) => Bun.file(path).text()),
|
|
273
|
+
statFile: source.statFile ?? ((path) => Bun.file(path).stat())
|
|
274
|
+
};
|
|
275
|
+
const issuer = url(context, "ISSUER", true);
|
|
276
|
+
const clientId = required(context, "CLIENT_ID");
|
|
277
|
+
const clientSecret = await secret(context, "CLIENT_SECRET", false);
|
|
278
|
+
const redirectUri = url(context, "REDIRECT_URI", true);
|
|
279
|
+
const postLogoutRedirectUri = url(context, "POST_LOGOUT_REDIRECT_URI", false);
|
|
280
|
+
const session = await secret(context, "SESSION_SECRET", true);
|
|
281
|
+
if (session !== undefined && session.value.length < 32) {
|
|
282
|
+
context.problems.push(`The session secret must be 32 characters or more (${session.variable}).`);
|
|
283
|
+
}
|
|
284
|
+
if (context.problems.length > 0 || issuer === undefined || clientId === undefined || redirectUri === undefined || session === undefined) {
|
|
285
|
+
throw new OidcEnvError(context.problems);
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
issuer,
|
|
289
|
+
clientId,
|
|
290
|
+
clientSecret: clientSecret?.value,
|
|
291
|
+
redirectUri,
|
|
292
|
+
secret: session.value,
|
|
293
|
+
name: plain(context, "COOKIE_NAME") ?? "oidc",
|
|
294
|
+
postLogoutRedirectUri
|
|
295
|
+
};
|
|
296
|
+
}
|
|
164
297
|
// src/oidc/errors.ts
|
|
165
298
|
class OidcError extends Error {
|
|
166
299
|
code;
|
|
@@ -397,7 +530,7 @@ async function revokeTokens(input) {
|
|
|
397
530
|
// src/oidc/oidc.ts
|
|
398
531
|
var DEFAULT_ALGORITHMS = ["RS256", "PS256", "ES256", "EdDSA"];
|
|
399
532
|
var CHALLENGE_SECONDS = 600;
|
|
400
|
-
var
|
|
533
|
+
var MAX_TIMER_MS = 2147483647;
|
|
401
534
|
var isFlow = (value) => typeof value === "object" && value !== null && ["state", "nonce", "verifier", "next"].every((key) => typeof value[key] === "string") && typeof value["exp"] === "number" && (value["dpop"] === undefined || isKey(value["dpop"]));
|
|
402
535
|
var isKey = (value) => typeof value === "object" && value !== null && ["ES256", "EdDSA"].includes(value["alg"]) && typeof value["jwk"] === "object";
|
|
403
536
|
var isStored = (value) => typeof value === "object" && value !== null && typeof value["idToken"] === "string" && typeof value["accessToken"] === "string" && typeof value["expiresAt"] === "number" && (value["dpop"] === undefined || isKey(value["dpop"]));
|
|
@@ -411,6 +544,7 @@ function oidcClient(options) {
|
|
|
411
544
|
signInPath = "/sign-in",
|
|
412
545
|
sessionSeconds = 30 * 24 * 3600,
|
|
413
546
|
refreshSkewSeconds = 60,
|
|
547
|
+
refreshFlightMs = 1e4,
|
|
414
548
|
clockToleranceSeconds = 30
|
|
415
549
|
} = options;
|
|
416
550
|
for (const [label, value] of [
|
|
@@ -464,6 +598,9 @@ function oidcClient(options) {
|
|
|
464
598
|
if (options.revokeTimeoutMs !== undefined && !(Number.isFinite(options.revokeTimeoutMs) && options.revokeTimeoutMs > 0)) {
|
|
465
599
|
throw new TypeError("oidcClient(): revokeTimeoutMs must be a positive finite number of milliseconds.");
|
|
466
600
|
}
|
|
601
|
+
if (!(Number.isFinite(refreshFlightMs) && refreshFlightMs >= 0 && refreshFlightMs <= MAX_TIMER_MS)) {
|
|
602
|
+
throw new TypeError("oidcClient(): refreshFlightMs must be a finite number of milliseconds, from 0 to 2147483647.");
|
|
603
|
+
}
|
|
467
604
|
const nonces = nonceMemory();
|
|
468
605
|
const signing = (key) => key ? { key, nonces, now } : undefined;
|
|
469
606
|
const flights = new Map;
|
|
@@ -518,8 +655,7 @@ function oidcClient(options) {
|
|
|
518
655
|
target.searchParams.set("next", next);
|
|
519
656
|
throw redirect(`${target.pathname}${target.search}`, { headers });
|
|
520
657
|
};
|
|
521
|
-
function refreshing(stored) {
|
|
522
|
-
const key = stored.refreshToken;
|
|
658
|
+
function refreshing(stored, key) {
|
|
523
659
|
const flying = flights.get(key);
|
|
524
660
|
if (flying)
|
|
525
661
|
return flying;
|
|
@@ -534,10 +670,58 @@ function oidcClient(options) {
|
|
|
534
670
|
return (await toStored(answer, undefined, stored, stored.dpop)).stored;
|
|
535
671
|
})();
|
|
536
672
|
flights.set(key, flight);
|
|
537
|
-
const forget = () =>
|
|
673
|
+
const forget = () => {
|
|
674
|
+
const timer = setTimeout(() => flights.delete(key), refreshFlightMs);
|
|
675
|
+
if (typeof timer === "object")
|
|
676
|
+
timer.unref();
|
|
677
|
+
};
|
|
538
678
|
flight.then(forget, () => flights.delete(key));
|
|
539
679
|
return flight;
|
|
540
680
|
}
|
|
681
|
+
const stores = new WeakMap;
|
|
682
|
+
async function toUser(stored, headers) {
|
|
683
|
+
const user = {
|
|
684
|
+
claims: decodeJwt(stored.idToken),
|
|
685
|
+
accessToken: stored.accessToken,
|
|
686
|
+
idToken: stored.idToken,
|
|
687
|
+
expiresAt: stored.expiresAt,
|
|
688
|
+
headers,
|
|
689
|
+
dpop: stored.dpop ? dpopBinding({
|
|
690
|
+
key: stored.dpop,
|
|
691
|
+
thumbprint: await dpopThumbprint(stored.dpop),
|
|
692
|
+
accessToken: stored.accessToken,
|
|
693
|
+
nonces,
|
|
694
|
+
fetch: fetcher,
|
|
695
|
+
now
|
|
696
|
+
}) : null,
|
|
697
|
+
fetch: fetcher
|
|
698
|
+
};
|
|
699
|
+
stores.set(user, stored);
|
|
700
|
+
return user;
|
|
701
|
+
}
|
|
702
|
+
async function refresh(user, refreshOptions = {}) {
|
|
703
|
+
const stored = stores.get(user);
|
|
704
|
+
if (!stored) {
|
|
705
|
+
throw new TypeError("oidc.refresh(): the user was not returned by this client.");
|
|
706
|
+
}
|
|
707
|
+
if (!refreshOptions.force && stored.expiresAt - refreshSkewSeconds * 1000 > now()) {
|
|
708
|
+
return user;
|
|
709
|
+
}
|
|
710
|
+
const headers = new Headers;
|
|
711
|
+
try {
|
|
712
|
+
if (!stored.refreshToken)
|
|
713
|
+
throw new Error("no refresh token");
|
|
714
|
+
const next = await refreshing(stored, stored.refreshToken);
|
|
715
|
+
await commit(headers, next);
|
|
716
|
+
return toUser(next, headers);
|
|
717
|
+
} catch (cause) {
|
|
718
|
+
if (stored.expiresAt > now())
|
|
719
|
+
return user;
|
|
720
|
+
throw cause instanceof OidcError ? cause : new OidcError("refresh-failed", "The refresh failed.", undefined, {
|
|
721
|
+
cause
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
541
725
|
async function oidcUser(request) {
|
|
542
726
|
const headers = new Headers;
|
|
543
727
|
const sealed = cookies.token(request);
|
|
@@ -553,32 +737,19 @@ function oidcClient(options) {
|
|
|
553
737
|
try {
|
|
554
738
|
if (!stored.refreshToken)
|
|
555
739
|
throw new Error("no refresh token");
|
|
556
|
-
stored = await refreshing(stored);
|
|
740
|
+
stored = await refreshing(stored, stored.refreshToken);
|
|
557
741
|
await commit(headers, stored);
|
|
558
742
|
} catch {
|
|
559
743
|
if (stored.expiresAt <= now())
|
|
560
744
|
return null;
|
|
561
745
|
}
|
|
562
746
|
}
|
|
563
|
-
return
|
|
564
|
-
claims: decodeJwt(stored.idToken),
|
|
565
|
-
accessToken: stored.accessToken,
|
|
566
|
-
idToken: stored.idToken,
|
|
567
|
-
expiresAt: stored.expiresAt,
|
|
568
|
-
headers,
|
|
569
|
-
dpop: stored.dpop ? dpopBinding({
|
|
570
|
-
key: stored.dpop,
|
|
571
|
-
thumbprint: await dpopThumbprint(stored.dpop),
|
|
572
|
-
accessToken: stored.accessToken,
|
|
573
|
-
nonces,
|
|
574
|
-
fetch: fetcher,
|
|
575
|
-
now
|
|
576
|
-
}) : null
|
|
577
|
-
};
|
|
747
|
+
return toUser(stored, headers);
|
|
578
748
|
}
|
|
579
749
|
return {
|
|
580
750
|
names: cookies.names,
|
|
581
751
|
oidcUser,
|
|
752
|
+
refresh,
|
|
582
753
|
async requireOidcUser(request) {
|
|
583
754
|
const user = await oidcUser(request);
|
|
584
755
|
if (user)
|
|
@@ -731,12 +902,65 @@ function oidcClient(options) {
|
|
|
731
902
|
}
|
|
732
903
|
};
|
|
733
904
|
}
|
|
905
|
+
// src/oidc/routes.ts
|
|
906
|
+
import { redirect as redirect2 } from "react-router";
|
|
907
|
+
function signInRoute(oidc, options = {}) {
|
|
908
|
+
return {
|
|
909
|
+
async loader({ request }) {
|
|
910
|
+
await options.guard?.(request);
|
|
911
|
+
return oidc.signIn(request);
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function callbackRoute(oidc, options = {}) {
|
|
916
|
+
const errorPath = sitePath(options.errorPath ?? "/", {
|
|
917
|
+
label: "callbackRoute(): errorPath"
|
|
918
|
+
});
|
|
919
|
+
return {
|
|
920
|
+
async loader({ request }) {
|
|
921
|
+
await options.guard?.(request);
|
|
922
|
+
try {
|
|
923
|
+
return await oidc.callback(request);
|
|
924
|
+
} catch (error) {
|
|
925
|
+
if (!(error instanceof OidcError))
|
|
926
|
+
throw error;
|
|
927
|
+
if (options.onError)
|
|
928
|
+
return options.onError(error);
|
|
929
|
+
return redirect2(`${errorPath}?${new URLSearchParams({ "sign-in-error": error.code })}`, { headers: error.headers });
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function signOutRoute(oidc, options = {}) {
|
|
935
|
+
const sameSite = siteCheck(options.origin);
|
|
936
|
+
const redirectTo = sitePath(options.redirectTo ?? "/", {
|
|
937
|
+
label: "signOutRoute(): redirectTo",
|
|
938
|
+
query: true
|
|
939
|
+
});
|
|
940
|
+
return {
|
|
941
|
+
async action({ request }) {
|
|
942
|
+
await options.guard?.(request);
|
|
943
|
+
sameSite(request);
|
|
944
|
+
return oidc.logout(request);
|
|
945
|
+
},
|
|
946
|
+
async loader({ request }) {
|
|
947
|
+
await options.guard?.(request);
|
|
948
|
+
return redirect2(redirectTo);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
}
|
|
734
952
|
export {
|
|
953
|
+
OidcEnvError,
|
|
735
954
|
OidcError,
|
|
955
|
+
callbackRoute,
|
|
956
|
+
dpopFetch,
|
|
736
957
|
generateDpopKey,
|
|
737
958
|
oidcClient,
|
|
738
|
-
|
|
959
|
+
oidcFromEnv,
|
|
960
|
+
signDpopProof,
|
|
961
|
+
signInRoute,
|
|
962
|
+
signOutRoute
|
|
739
963
|
};
|
|
740
964
|
|
|
741
|
-
//# debugId=
|
|
965
|
+
//# debugId=B7DF2BEADD6B2F6B64756E2164756E21
|
|
742
966
|
//# sourceMappingURL=index.js.map
|