@fluixi/oauth2 1.0.0-alpha.108 → 1.0.0-alpha.109

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.
Files changed (59) hide show
  1. package/dist/api-guard.cjs +7 -2
  2. package/dist/api-guard.mjs +9 -135
  3. package/dist/backchannel.cjs +7 -2
  4. package/dist/backchannel.mjs +11 -299
  5. package/dist/browser.mjs +10 -707
  6. package/dist/callback.mjs +16 -23
  7. package/dist/{dpop-YPGCGL7S.mjs → chunk-27BGFJIY.mjs} +6 -6
  8. package/dist/chunk-2GLWT7XH.mjs +143 -0
  9. package/dist/chunk-3EICMAF7.mjs +22 -0
  10. package/dist/chunk-4OHJTTX7.mjs +398 -0
  11. package/dist/chunk-4QRYJ4TN.mjs +86 -0
  12. package/dist/chunk-5WX3EV2W.mjs +78 -0
  13. package/dist/chunk-7AMC336S.mjs +52 -0
  14. package/dist/chunk-AAN3YN4S.mjs +63 -0
  15. package/dist/chunk-AWVECOG7.mjs +404 -0
  16. package/dist/chunk-GN5SERAQ.mjs +189 -0
  17. package/dist/chunk-KIXTZEEW.mjs +80 -0
  18. package/dist/chunk-KVW2S6VY.mjs +36 -0
  19. package/dist/chunk-MHWZTXZZ.mjs +9 -0
  20. package/dist/chunk-QC2FFASM.mjs +67 -0
  21. package/dist/chunk-SJOBQPG6.mjs +77 -0
  22. package/dist/chunk-VCNXQCIH.mjs +26 -0
  23. package/dist/chunk-XQJTQV3C.mjs +91 -0
  24. package/dist/client-auth.mjs +6 -78
  25. package/dist/discovery.mjs +6 -64
  26. package/dist/dpop-store.mjs +6 -118
  27. package/dist/dpop.mjs +11 -95
  28. package/dist/env-config.mjs +5 -214
  29. package/dist/env-credentials.mjs +5 -47
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.mjs +48 -1010
  32. package/dist/module.mjs +5 -20
  33. package/dist/pkce.mjs +11 -56
  34. package/dist/presets.mjs +5 -214
  35. package/dist/return-to.mjs +4 -22
  36. package/dist/roles.mjs +4 -32
  37. package/dist/server-client.mjs +7 -107
  38. package/dist/server.cjs +61 -9
  39. package/dist/server.d.ts +8 -0
  40. package/dist/server.d.ts.map +1 -1
  41. package/dist/server.js +80 -5
  42. package/dist/server.mjs +94 -433
  43. package/dist/service-client.cjs +1 -1
  44. package/dist/service-client.mjs +16 -138
  45. package/dist/service.mjs +14 -978
  46. package/dist/session-monitor.mjs +4 -74
  47. package/dist/tokens.mjs +5 -4
  48. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  49. package/dist/types.mjs +4 -9
  50. package/dist/verify.cjs +8 -3
  51. package/dist/verify.mjs +17 -585
  52. package/package.json +21 -21
  53. package/dist/browser-XDRDM2J3.mjs +0 -3545
  54. package/dist/chunk-6ZLDEEM7.mjs +0 -15
  55. package/dist/chunk-D2N6T3DN.mjs +0 -10
  56. package/dist/chunk-KPBCIVN3.mjs +0 -108
  57. package/dist/dpop-KK5X2JTA.mjs +0 -100
  58. package/dist/dpop-SO6GDDZH.mjs +0 -22
  59. /package/dist/{chunk-OGSFNTKA.mjs → chunk-AXPSPTNP.mjs} +0 -0
@@ -1,141 +1,19 @@
1
- /*! @fluixi/oauth2 v1.0.0-alpha.108 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
- import "./chunk-D2N6T3DN.mjs";
3
-
4
- // src/types.ts
5
- var OAuthError = class extends Error {
6
- constructor(message, code, description) {
7
- super(message);
8
- this.code = code;
9
- this.description = description;
10
- this.name = "OAuthError";
11
- }
12
- };
13
-
14
- // src/client-auth.ts
15
- var CANONICAL = {
16
- basic: "client_secret_basic",
17
- body: "client_secret_post",
18
- client_secret_basic: "client_secret_basic",
19
- client_secret_post: "client_secret_post",
20
- private_key_jwt: "private_key_jwt",
21
- none: "none"
22
- };
23
- function resolveMethod(auth) {
24
- if (auth.method) return CANONICAL[auth.method] ?? "client_secret_basic";
25
- if (auth.privateKey) return "private_key_jwt";
26
- return auth.clientSecret ? "client_secret_basic" : "none";
27
- }
28
- function assertUsable(auth, who) {
29
- if (!auth.clientId) throw new Error(`[fluixi/oauth2] ${who} needs a clientId.`);
30
- const method = resolveMethod(auth);
31
- if (method === "private_key_jwt" && !auth.privateKey) {
32
- throw new Error(
33
- `[fluixi/oauth2] ${who}: private_key_jwt needs \`privateKey\`, the JWK whose public half the provider holds.`
34
- );
35
- }
36
- if ((method === "client_secret_basic" || method === "client_secret_post") && !auth.clientSecret) {
37
- throw new Error(
38
- `[fluixi/oauth2] ${who}: ${method} needs a \`clientSecret\`. A public client should use \`method: 'none'\`, which PKCE is what protects.`
39
- );
40
- }
41
- return method;
42
- }
43
- async function loadJose() {
44
- try {
45
- return await import("./browser-XDRDM2J3.mjs");
46
- } catch {
47
- throw new OAuthError(
48
- "private_key_jwt needs `jose`. Install it: npm i jose. It is an optional peer, so a client using a secret does not carry it.",
49
- "jose_missing"
50
- );
51
- }
52
- }
53
- async function signAssertion(auth, endpoint) {
54
- const jose = await loadJose();
55
- const alg = auth.assertionAlgorithm ?? "RS256";
56
- const key = await jose.importJWK(auth.privateKey, alg);
57
- const kid = auth.keyId ?? auth.privateKey.kid;
58
- return new jose.SignJWT({}).setProtectedHeader(kid ? { alg, kid } : { alg }).setIssuer(auth.clientId).setSubject(auth.clientId).setAudience(endpoint).setJti(crypto.randomUUID()).setIssuedAt().setExpirationTime("1m").sign(key);
59
- }
60
- async function applyClientAuth(auth, endpoint, headers, form) {
61
- switch (resolveMethod(auth)) {
62
- case "client_secret_basic": {
63
- const pair = `${encodeURIComponent(auth.clientId)}:${encodeURIComponent(auth.clientSecret)}`;
64
- headers.authorization = `Basic ${btoa(pair)}`;
65
- break;
66
- }
67
- case "client_secret_post":
68
- form.set("client_id", auth.clientId);
69
- form.set("client_secret", auth.clientSecret);
70
- break;
71
- case "private_key_jwt":
72
- form.set("client_id", auth.clientId);
73
- form.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
74
- form.set("client_assertion", await signAssertion(auth, endpoint));
75
- break;
76
- case "none":
77
- form.set("client_id", auth.clientId);
78
- break;
79
- }
80
- }
81
-
82
- // src/discovery.ts
83
- var cache = /* @__PURE__ */ new Map();
84
- function documentUrl(issuer) {
85
- return `${issuer.replace(/\/$/, "")}/.well-known/openid-configuration`;
86
- }
87
- async function discover(issuer, fetcher = fetch) {
88
- const cached = cache.get(issuer);
89
- if (cached) return cached;
90
- const pending = (async () => {
91
- let response;
92
- try {
93
- response = await fetcher(documentUrl(issuer));
94
- } catch (cause) {
95
- const why = cause instanceof Error ? cause.message : String(cause);
96
- throw new OAuthError(
97
- typeof window === "undefined" ? (
98
- // On a server nothing blocks the read: the provider is down, or the address is wrong.
99
- `Could not reach the provider at ${documentUrl(issuer)}: is it running, and is the issuer right? (${why})`
100
- ) : `Could not read the discovery document at ${documentUrl(issuer)}. In a browser this is usually the provider refusing a cross-origin read: give \`endpoints\` directly, or resolve them on a server. (${why})`,
101
- "discovery_unreachable"
102
- );
103
- }
104
- if (!response.ok) {
105
- throw new OAuthError(
106
- `Discovery failed for ${issuer}: ${response.status}`,
107
- "discovery_failed"
108
- );
109
- }
110
- const doc = await response.json();
111
- if (!doc.authorization_endpoint || !doc.token_endpoint) {
112
- throw new OAuthError(
113
- `${issuer} published a discovery document with no authorization or token endpoint.`,
114
- "discovery_incomplete"
115
- );
116
- }
117
- return {
118
- authorization: doc.authorization_endpoint,
119
- token: doc.token_endpoint,
120
- userinfo: doc.userinfo_endpoint,
121
- endSession: doc.end_session_endpoint,
122
- jwks: doc.jwks_uri,
123
- introspection: doc.introspection_endpoint,
124
- revocation: doc.revocation_endpoint,
125
- checkSession: doc.check_session_iframe,
126
- issuer: doc.issuer ?? issuer
127
- };
128
- })();
129
- cache.set(issuer, pending);
130
- pending.catch(() => cache.delete(issuer));
131
- return pending;
132
- }
133
-
134
- // src/pkce.ts
135
- function expiryFrom(expiresIn, now = Date.now()) {
136
- const seconds = typeof expiresIn === "number" ? expiresIn : Number(expiresIn);
137
- return Number.isFinite(seconds) && seconds > 0 ? now + seconds * 1e3 : void 0;
138
- }
1
+ /*! @fluixi/oauth2 v1.0.0-alpha.109 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+ import {
3
+ expiryFrom
4
+ } from "./chunk-QC2FFASM.mjs";
5
+ import {
6
+ applyClientAuth,
7
+ assertUsable,
8
+ resolveMethod
9
+ } from "./chunk-SJOBQPG6.mjs";
10
+ import {
11
+ discover
12
+ } from "./chunk-AAN3YN4S.mjs";
13
+ import {
14
+ OAuthError
15
+ } from "./chunk-AXPSPTNP.mjs";
16
+ import "./chunk-7P6ASYW6.mjs";
139
17
 
140
18
  // src/service-client.ts
141
19
  function createServiceClient(options) {