@eventuras/fides-auth-next 0.1.5 → 0.1.11

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 (35) hide show
  1. package/LICENSE +674 -0
  2. package/dist/cookies.js +192 -53
  3. package/dist/cookies.js.map +1 -0
  4. package/dist/index.js +18 -17
  5. package/dist/oidc-callback.js +52 -22
  6. package/dist/oidc-callback.js.map +1 -0
  7. package/dist/oidc-login.js +41 -15
  8. package/dist/oidc-login.js.map +1 -0
  9. package/dist/request.js +27 -17
  10. package/dist/request.js.map +1 -0
  11. package/dist/session.js +184 -44
  12. package/dist/session.js.map +1 -0
  13. package/dist/store/configure-logger.js +21 -6
  14. package/dist/store/configure-logger.js.map +1 -0
  15. package/dist/store/hooks.js +61 -19
  16. package/dist/store/hooks.js.map +1 -0
  17. package/dist/store/index.js +6 -6
  18. package/dist/store/session-monitor.js +80 -37
  19. package/dist/store/session-monitor.js.map +1 -0
  20. package/dist/store/store.js +174 -90
  21. package/dist/store/store.js.map +1 -0
  22. package/dist/store/use-session-monitor.js +35 -8
  23. package/dist/store/use-session-monitor.js.map +1 -0
  24. package/package.json +22 -13
  25. package/dist/fides-auth/dist/build-CNL3v39v.js +0 -977
  26. package/dist/fides-auth/dist/decode_jwt-1J26fl4I.js +0 -25
  27. package/dist/fides-auth/dist/decrypt-Cahlu_6Y.js +0 -88
  28. package/dist/fides-auth/dist/deflate-koSuX7FB.js +0 -969
  29. package/dist/fides-auth/dist/logger.js +0 -46
  30. package/dist/fides-auth/dist/oauth.js +0 -165
  31. package/dist/fides-auth/dist/rate-limit.js +0 -26
  32. package/dist/fides-auth/dist/session-refresh.js +0 -27
  33. package/dist/fides-auth/dist/session-validation-BxObT3wC.js +0 -64
  34. package/dist/fides-auth/dist/silent-login.js +0 -50
  35. package/dist/fides-auth/dist/utils-ByMRF7b2.js +0 -379
@@ -1,46 +0,0 @@
1
- //#region ../fides-auth/dist/logger.js
2
- var e = class {
3
- prefix;
4
- constructor(e, t) {
5
- this.prefix = `[${e}]${t && Object.keys(t).length > 0 ? ` ${JSON.stringify(t)}` : ""}`;
6
- }
7
- debug(e, t) {
8
- typeof e == "string" ? console.debug(this.prefix, e) : t ? console.debug(this.prefix, t, e) : e && console.debug(this.prefix, e);
9
- }
10
- info(e, t) {
11
- typeof e == "string" ? console.info(this.prefix, e) : t ? console.info(this.prefix, t, e) : e && console.info(this.prefix, e);
12
- }
13
- warn(e, t) {
14
- typeof e == "string" ? console.warn(this.prefix, e) : t ? console.warn(this.prefix, t, e) : e && console.warn(this.prefix, e);
15
- }
16
- error(e, t) {
17
- typeof e == "string" ? console.error(this.prefix, e) : t ? console.error(this.prefix, t, e) : e && console.error(this.prefix, e);
18
- }
19
- }, t = { create({ namespace: t, context: n }) {
20
- return new e(t, n);
21
- } }, n = 0;
22
- function r(e) {
23
- t = e, n++;
24
- }
25
- function i(e) {
26
- let r = null, i = -1;
27
- function a() {
28
- return (r === null || i !== n) && (r = t.create(e), i = n), r;
29
- }
30
- return {
31
- debug(e, t) {
32
- a().debug(e, t);
33
- },
34
- info(e, t) {
35
- a().info(e, t);
36
- },
37
- warn(e, t) {
38
- a().warn(e, t);
39
- },
40
- error(e, t) {
41
- a().error(e, t);
42
- }
43
- };
44
- }
45
- //#endregion
46
- export { i, r };
@@ -1,165 +0,0 @@
1
- import { i as e } from "./logger.js";
2
- import { i as t } from "./decode_jwt-1J26fl4I.js";
3
- import { Bt as n, Ct as r, Ot as i, Rt as a, Tt as o, bt as s, wt as c, zt as l } from "./build-CNL3v39v.js";
4
- //#region ../fides-auth/dist/oauth.js
5
- var u = e({ namespace: "fides-auth:oauth" }), d = "openid profile email offline_access";
6
- async function f(e, t) {
7
- u.debug({ issuer: e.issuer }, "Starting token refresh");
8
- try {
9
- let n = await l(await i(new URL(e.issuer), e.clientId, e.clientSecret, s(e.clientSecret)), t, { scope: e.scope });
10
- return u.info({
11
- hasAccessToken: !!n.access_token,
12
- hasRefreshToken: !!n.refresh_token,
13
- expiresIn: n.expires_in
14
- }, "Token refresh successful"), n;
15
- } catch (t) {
16
- let n = t;
17
- throw n?.code === "OAUTH_RESPONSE_BODY_ERROR" && n?.error === "invalid_grant" ? u.info({
18
- error: n.error,
19
- error_description: n.error_description,
20
- issuer: e.issuer
21
- }, "Token refresh failed - refresh token expired or invalid") : u.error({
22
- error: t,
23
- issuer: e.issuer
24
- }, "Token refresh failed"), t;
25
- }
26
- }
27
- async function p(e) {
28
- let t = c(), n = await r(t), i = o(), a = {
29
- redirect_uri: e.redirect_uri,
30
- scope: e.scope ?? "openid profile email offline_access",
31
- code_challenge: n,
32
- code_challenge_method: "S256",
33
- state: i
34
- };
35
- return u.info({
36
- redirectUri: e.redirect_uri,
37
- scope: a.scope
38
- }, "PKCE parameters generated"), {
39
- code_verifier: t,
40
- code_challenge: n,
41
- state: i,
42
- parameters: a
43
- };
44
- }
45
- async function m(e, t) {
46
- try {
47
- let r = n(e, t.parameters);
48
- return u.info({ authUrl: r.origin }, "Authorization URL built successfully"), r;
49
- } catch (e) {
50
- throw u.error({ error: e }, "Failed to build authorization URL"), e;
51
- }
52
- }
53
- async function h(e, t) {
54
- u.debug({ issuer: e.issuer }, "Discovering OpenID configuration");
55
- try {
56
- return m(await i(new URL(e.issuer), e.clientId, e.clientSecret, s(e.clientSecret)), t);
57
- } catch (t) {
58
- throw u.error({
59
- error: t,
60
- issuer: e.issuer
61
- }, "Failed to discover config or build URL"), t;
62
- }
63
- }
64
- async function g(e, t, n, r) {
65
- u.debug({
66
- issuer: e.issuer,
67
- clientId: e.clientId
68
- }, "Exchanging authorization code for tokens");
69
- let o = await a(await i(new URL(e.issuer), e.clientId, e.clientSecret, s(e.clientSecret)), t, {
70
- pkceCodeVerifier: n,
71
- expectedState: r
72
- }, { redirect_uri: e.redirect_uri });
73
- return u.info({
74
- hasAccessToken: !!o.access_token,
75
- hasRefreshToken: !!o.refresh_token,
76
- expiresIn: o.expires_in
77
- }, "Authorization code exchange successful"), o;
78
- }
79
- function _(e, n = "roles") {
80
- if (!e.id_token) throw Error("OIDC token response is missing id_token");
81
- let r = t(e.id_token), i = r[n], a = typeof i == "string" ? [i] : [], o = Array.isArray(i) ? i : a;
82
- return u.debug({
83
- sub: r.sub,
84
- rolesClaim: n,
85
- rolesCount: o.length
86
- }, "Extracted user from ID token"), {
87
- sub: r.sub ?? "",
88
- name: r.name,
89
- email: r.email,
90
- roles: o
91
- };
92
- }
93
- function v(e, t = "roles") {
94
- if (!e.access_token) throw Error("OIDC token response is missing access_token");
95
- let n = _(e, t);
96
- return {
97
- tokens: {
98
- accessToken: e.access_token,
99
- accessTokenExpiresAt: e.expires_in ? new Date(Date.now() + e.expires_in * 1e3) : void 0,
100
- refreshToken: e.refresh_token
101
- },
102
- user: {
103
- name: n.name,
104
- email: n.email,
105
- roles: n.roles
106
- }
107
- };
108
- }
109
- function y(e, t, n = "/", r) {
110
- let i = e ?? n, a;
111
- try {
112
- a = new URL(i, t);
113
- } catch {
114
- return u.warn({ returnTo: i }, "Invalid returnTo URL, using default"), new URL(n, t);
115
- }
116
- let o = new URL(t);
117
- return a.origin === o.origin ? r && !r(a.pathname) ? (u.warn({ pathname: a.pathname }, "returnTo failed custom validation, falling back to default"), new URL(n, t)) : a : (u.error({
118
- returnTo: i,
119
- redirectOrigin: a.origin,
120
- applicationOrigin: o.origin
121
- }, "Possible open redirect attack: returnTo points outside application origin"), new URL(n, t));
122
- }
123
- async function b(e, t) {
124
- try {
125
- let n = (await i(new URL(e.issuer), e.clientId, e.clientSecret, s(e.clientSecret))).serverMetadata().end_session_endpoint;
126
- if (!n) return u.info({ issuer: e.issuer }, "No end_session_endpoint found"), null;
127
- let r = new URL(n);
128
- return r.searchParams.set("client_id", e.clientId), r.searchParams.set("post_logout_redirect_uri", t), u.debug({ logoutUrl: r.toString() }, "Built OIDC logout URL"), r;
129
- } catch (t) {
130
- return u.warn({
131
- error: t,
132
- issuer: e.issuer
133
- }, "OIDC discovery failed for logout"), null;
134
- }
135
- }
136
- async function x(e) {
137
- try {
138
- let t = new URLSearchParams({
139
- grant_type: "client_credentials",
140
- client_id: e.clientId,
141
- client_secret: e.clientSecret
142
- });
143
- e.scope && t.set("scope", e.scope);
144
- let n = await fetch(e.tokenEndpoint, {
145
- method: "POST",
146
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
147
- body: t
148
- });
149
- if (!n.ok) {
150
- let e = await n.text();
151
- throw u.error({
152
- status: n.status,
153
- error: e
154
- }, "Client credentials grant failed"), Error(`Client credentials grant failed: ${n.status} - ${e}`);
155
- }
156
- return await n.json();
157
- } catch (t) {
158
- throw u.error({
159
- error: t,
160
- tokenEndpoint: e.tokenEndpoint
161
- }, "Client credentials grant error"), t;
162
- }
163
- }
164
- //#endregion
165
- export { _, b, d, f, g, h, m, p, v, x, y };
@@ -1,26 +0,0 @@
1
- //#region ../fides-auth/dist/rate-limit.js
2
- var e = class {
3
- max;
4
- refillIntervalSeconds;
5
- constructor(e, t) {
6
- this.max = e, this.refillIntervalSeconds = t;
7
- }
8
- storage = /* @__PURE__ */ new Map();
9
- check(e, t) {
10
- let n = this.storage.get(e) ?? null;
11
- if (n === null) return !0;
12
- let r = Math.floor((Date.now() - n.refilledAt) / (this.refillIntervalSeconds * 1e3));
13
- return r > 0 ? Math.min(n.count + r, this.max) >= t : n.count >= t;
14
- }
15
- consume(e, t) {
16
- let n = this.storage.get(e) ?? null, r = Date.now();
17
- if (n === null) return n = {
18
- count: this.max - t,
19
- refilledAt: r
20
- }, this.storage.set(e, n), !0;
21
- let i = Math.floor((r - n.refilledAt) / (this.refillIntervalSeconds * 1e3));
22
- return i > 0 && (n.count = Math.min(n.count + i, this.max), n.refilledAt = r), n.count < t ? (this.storage.set(e, n), !1) : (n.count -= t, this.storage.set(e, n), !0);
23
- }
24
- };
25
- //#endregion
26
- export { e };
@@ -1,27 +0,0 @@
1
- import { i as e } from "./logger.js";
2
- import { f as t } from "./oauth.js";
3
- //#region ../fides-auth/dist/session-refresh.js
4
- var n = e({ namespace: "fides-auth:session-refresh" }), r = async (e, r, i = {}) => {
5
- if (n.debug("Starting session refresh"), !e.tokens?.refreshToken) throw n.error("No refresh token available in session"), Error("No refresh token available");
6
- try {
7
- let i = await t(r, e.tokens.refreshToken), a = {
8
- ...e,
9
- tokens: {
10
- ...e.tokens,
11
- accessToken: i.access_token,
12
- accessTokenExpiresAt: i.expires_in ? new Date(Date.now() + i.expires_in * 1e3) : void 0,
13
- refreshToken: i.refresh_token ?? e.tokens?.refreshToken
14
- }
15
- };
16
- return n.info({
17
- hasNewAccessToken: !!a.tokens.accessToken,
18
- hasNewRefreshToken: !!i.refresh_token,
19
- expiresIn: i.expires_in
20
- }, "Session refreshed successfully"), a;
21
- } catch (e) {
22
- let t = e;
23
- throw t?.code === "OAUTH_RESPONSE_BODY_ERROR" && t?.error === "invalid_grant" ? n.info("Session refresh failed - refresh token expired or invalid") : n.error({ error: e }, "Session refresh failed"), e;
24
- }
25
- };
26
- //#endregion
27
- export { r };
@@ -1,64 +0,0 @@
1
- import { i as e } from "./logger.js";
2
- import { ne as t } from "./deflate-koSuX7FB.js";
3
- import { i as n } from "./decode_jwt-1J26fl4I.js";
4
- import { P as r, z as i } from "./utils-ByMRF7b2.js";
5
- import { y as a } from "./decrypt-Cahlu_6Y.js";
6
- //#region ../fides-auth/dist/session-validation-BxObT3wC.js
7
- async function o(e, n, i) {
8
- let o = await a(e, n, i), s = r(o.protectedHeader, o.plaintext, i), { protectedHeader: c } = o;
9
- if (c.iss !== void 0 && c.iss !== s.iss) throw new t("replicated \"iss\" claim header parameter mismatch", s, "iss", "mismatch");
10
- if (c.sub !== void 0 && c.sub !== s.sub) throw new t("replicated \"sub\" claim header parameter mismatch", s, "sub", "mismatch");
11
- if (c.aud !== void 0 && JSON.stringify(c.aud) !== JSON.stringify(s.aud)) throw new t("replicated \"aud\" claim header parameter mismatch", s, "aud", "mismatch");
12
- let l = {
13
- payload: s,
14
- protectedHeader: c
15
- };
16
- return typeof n == "function" ? {
17
- ...l,
18
- key: o.key
19
- } : l;
20
- }
21
- var s = e({ namespace: "fides-auth:session-validation" });
22
- async function c(e, t) {
23
- s.debug("Starting session JWT validation");
24
- let n = typeof t == "string" ? i(t) : t, r;
25
- try {
26
- ({payload: r} = await o(e, n));
27
- } catch (e) {
28
- let t = e instanceof Error ? e.message : "Failed decrypting JWT";
29
- return s.warn({ reason: t }, "Session JWT decryption failed"), {
30
- status: "INVALID",
31
- reason: `Decryption error: ${t}`
32
- };
33
- }
34
- if (!u(r)) return s.warn("JWT payload does not match Session structure"), {
35
- status: "INVALID",
36
- reason: "jwt does not seem to include a session"
37
- };
38
- s.debug("Session validated successfully");
39
- let a = l(r);
40
- return a !== void 0 && a <= 0 ? (s.info({ accessTokenExpiresIn: a }, "Session access token has expired"), {
41
- session: r,
42
- status: "EXPIRED",
43
- accessTokenExpiresIn: a,
44
- reason: "Access token has expired"
45
- }) : {
46
- session: r,
47
- status: "VALID",
48
- accessTokenExpiresIn: a
49
- };
50
- }
51
- function l(e) {
52
- let t = e.tokens?.accessToken;
53
- if (t) try {
54
- let { exp: e } = n(t);
55
- return typeof e == "number" ? Math.floor(e - Date.now() / 1e3) : void 0;
56
- } catch {
57
- return;
58
- }
59
- }
60
- function u(e) {
61
- return !(typeof e != "object" || !e || "tokens" in e && typeof e.tokens != "object" || "user" in e && typeof e.user != "object");
62
- }
63
- //#endregion
64
- export { c, u };
@@ -1,50 +0,0 @@
1
- import { i as e } from "./logger.js";
2
- import { Bt as t, Ot as n, bt as r } from "./build-CNL3v39v.js";
3
- //#region ../fides-auth/dist/silent-login.js
4
- var i = e({ namespace: "fides-auth:silent-login" });
5
- async function a(e, a = {}) {
6
- i.debug({ issuer: e.issuer }, "Building silent login URL");
7
- try {
8
- let o = await n(new URL(e.issuer), e.clientId, e.clientSecret, r(e.clientSecret)), s = {
9
- redirect_uri: e.redirect_uri,
10
- scope: e.scope,
11
- prompt: "none",
12
- response_type: "code",
13
- ...a.additionalParams
14
- };
15
- a.loginHint && (s.login_hint = a.loginHint), a.maxAge !== void 0 && (s.max_age = a.maxAge.toString());
16
- let c = t(o, s);
17
- return i.info("Silent login URL built successfully"), c;
18
- } catch (t) {
19
- throw i.error({
20
- error: t,
21
- issuer: e.issuer
22
- }, "Failed to build silent login URL"), t;
23
- }
24
- }
25
- function o(e) {
26
- let t = e.searchParams.get("error"), n = e.searchParams.get("error_description"), r = e.searchParams.get("code");
27
- return t ? (i.info({
28
- error: t,
29
- errorDescription: n
30
- }, "Silent login failed with error"), {
31
- success: !1,
32
- error: t,
33
- errorDescription: n ?? void 0
34
- }) : r ? (i.info("Silent login successful"), { success: !0 }) : (i.warn("Silent login callback missing both code and error"), {
35
- success: !1,
36
- error: "invalid_callback",
37
- errorDescription: "Callback URL missing both code and error parameters"
38
- });
39
- }
40
- var s = {
41
- LOGIN_REQUIRED: "login_required",
42
- INTERACTION_REQUIRED: "interaction_required",
43
- CONSENT_REQUIRED: "consent_required",
44
- ACCOUNT_SELECTION_REQUIRED: "account_selection_required"
45
- };
46
- function c(e) {
47
- return e ? Object.values(s).includes(e) : !1;
48
- }
49
- //#endregion
50
- export { a, c, o, s };