@zitadel/sdk-nuxt 0.1.0-alpha.10 → 0.1.0-alpha.12
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-E7GMYXBM.js → chunk-AQZKZRKQ.js} +14 -39
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/module.js +27 -1
- package/dist/runtime/plugin.js +1 -6
- package/dist/runtime/server/handler.js +1 -1
- package/dist/runtime/server/middleware.d.ts +2 -2
- package/dist/runtime/server/middleware.js +1 -1
- package/dist/runtime/types.d.ts +2 -2
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/runtime/server/middleware.ts
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
3
|
import {
|
|
3
4
|
HOP_BY_HOP,
|
|
4
5
|
INTERNAL_HEADERS,
|
|
@@ -17,12 +18,7 @@ import {
|
|
|
17
18
|
} from "h3";
|
|
18
19
|
|
|
19
20
|
// src/runtime/lib/jwt.ts
|
|
20
|
-
import {
|
|
21
|
-
JWKS_TTL_MS,
|
|
22
|
-
base64UrlDecode,
|
|
23
|
-
decodeJwt,
|
|
24
|
-
verifyJwt
|
|
25
|
-
} from "@zitadel/sdk-core/jwt";
|
|
21
|
+
import { JWKS_TTL_MS, base64UrlDecode, decodeJwt, verifyJwt } from "@zitadel/sdk-core/jwt";
|
|
26
22
|
|
|
27
23
|
// src/runtime/server/middleware.ts
|
|
28
24
|
function buildUpstreamHeaders(event) {
|
|
@@ -38,10 +34,7 @@ function buildUpstreamHeaders(event) {
|
|
|
38
34
|
const socketIp = event.node.req.socket?.remoteAddress;
|
|
39
35
|
if (socketIp) {
|
|
40
36
|
const existingXff = headers.get("x-forwarded-for");
|
|
41
|
-
headers.set(
|
|
42
|
-
"x-forwarded-for",
|
|
43
|
-
existingXff ? `${existingXff}, ${socketIp}` : socketIp
|
|
44
|
-
);
|
|
37
|
+
headers.set("x-forwarded-for", existingXff ? `${existingXff}, ${socketIp}` : socketIp);
|
|
45
38
|
}
|
|
46
39
|
if (!headers.has("x-forwarded-host")) {
|
|
47
40
|
headers.set("x-forwarded-host", url.host);
|
|
@@ -64,8 +57,7 @@ function createNextgenMiddleware(options = {}) {
|
|
|
64
57
|
allowedTokenTypes = ["JWT", "at+JWT"],
|
|
65
58
|
jwksTimeoutMs,
|
|
66
59
|
proxyTimeoutMs = 5e3,
|
|
67
|
-
opaqueTokenTimeoutMs = 5e3
|
|
68
|
-
onExchangeResponse
|
|
60
|
+
opaqueTokenTimeoutMs = 5e3
|
|
69
61
|
} = options;
|
|
70
62
|
if (!loginPath.startsWith("/") || loginPath.startsWith("//")) {
|
|
71
63
|
throw new Error(
|
|
@@ -80,14 +72,7 @@ function createNextgenMiddleware(options = {}) {
|
|
|
80
72
|
return;
|
|
81
73
|
}
|
|
82
74
|
if (pathname === proxyPath || pathname.startsWith(`${proxyPath}/`)) {
|
|
83
|
-
return proxyRequest(
|
|
84
|
-
event,
|
|
85
|
-
url,
|
|
86
|
-
proxyPath,
|
|
87
|
-
urlObj,
|
|
88
|
-
proxyTimeoutMs,
|
|
89
|
-
onExchangeResponse
|
|
90
|
-
);
|
|
75
|
+
return proxyRequest(event, url, proxyPath, urlObj, proxyTimeoutMs);
|
|
91
76
|
}
|
|
92
77
|
return handleAuth(event, {
|
|
93
78
|
url,
|
|
@@ -103,7 +88,7 @@ function createNextgenMiddleware(options = {}) {
|
|
|
103
88
|
});
|
|
104
89
|
});
|
|
105
90
|
}
|
|
106
|
-
async function proxyRequest(event, authUrl, proxyPath, url, proxyTimeoutMs
|
|
91
|
+
async function proxyRequest(event, authUrl, proxyPath, url, proxyTimeoutMs) {
|
|
107
92
|
const suffix = url.pathname.slice(proxyPath.length);
|
|
108
93
|
const target = `${authUrl}${suffix}${url.search}`;
|
|
109
94
|
const method = event.node.req.method ?? "GET";
|
|
@@ -111,11 +96,11 @@ async function proxyRequest(event, authUrl, proxyPath, url, proxyTimeoutMs, onEx
|
|
|
111
96
|
const rawBody = hasBody ? await readRawBody(event, false) : void 0;
|
|
112
97
|
const body = rawBody != null ? new Uint8Array(rawBody) : void 0;
|
|
113
98
|
const upstreamHeaders = buildUpstreamHeaders(event);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
upstreamHeaders.set("authorization", `Bearer
|
|
99
|
+
if (!upstreamHeaders.has("authorization")) {
|
|
100
|
+
const config = useRuntimeConfig();
|
|
101
|
+
const projectSecret = config.nextgen?.projectSecret;
|
|
102
|
+
if (projectSecret) {
|
|
103
|
+
upstreamHeaders.set("authorization", `Bearer ${projectSecret}`);
|
|
119
104
|
}
|
|
120
105
|
}
|
|
121
106
|
const upstream = await fetch(target, {
|
|
@@ -130,14 +115,10 @@ async function proxyRequest(event, authUrl, proxyPath, url, proxyTimeoutMs, onEx
|
|
|
130
115
|
for (const cookie of setCookieHeaders) {
|
|
131
116
|
responseHeaders.append("set-cookie", cookie);
|
|
132
117
|
}
|
|
133
|
-
|
|
118
|
+
const response = new Response(upstream.body, {
|
|
134
119
|
status: upstream.status,
|
|
135
120
|
headers: responseHeaders
|
|
136
121
|
});
|
|
137
|
-
const isExchange = method === "POST" && suffix.startsWith("/sessions/exchange");
|
|
138
|
-
if (isExchange && onExchangeResponse) {
|
|
139
|
-
response = await onExchangeResponse(response);
|
|
140
|
-
}
|
|
141
122
|
event.node.res.statusCode = response.status;
|
|
142
123
|
for (const [key, value] of response.headers.entries()) {
|
|
143
124
|
if (key.toLowerCase() === "set-cookie") continue;
|
|
@@ -154,9 +135,7 @@ function isJwtShaped(token) {
|
|
|
154
135
|
const parts = token.split(".");
|
|
155
136
|
if (parts.length < 3 || !parts[0]) return false;
|
|
156
137
|
try {
|
|
157
|
-
const header = JSON.parse(
|
|
158
|
-
DECODER.decode(base64UrlDecode(parts[0]))
|
|
159
|
-
);
|
|
138
|
+
const header = JSON.parse(DECODER.decode(base64UrlDecode(parts[0])));
|
|
160
139
|
return typeof header?.alg === "string" && !("enc" in header);
|
|
161
140
|
} catch {
|
|
162
141
|
return false;
|
|
@@ -215,11 +194,7 @@ async function handleAuth(event, opts) {
|
|
|
215
194
|
return;
|
|
216
195
|
}
|
|
217
196
|
if (!payload && cookieToken && !isJwtShaped(cookieToken)) {
|
|
218
|
-
const opaqueResult = await validateOpaqueSessionToken(
|
|
219
|
-
cookieToken,
|
|
220
|
-
url,
|
|
221
|
-
opaqueTokenTimeoutMs
|
|
222
|
-
);
|
|
197
|
+
const opaqueResult = await validateOpaqueSessionToken(cookieToken, url, opaqueTokenTimeoutMs);
|
|
223
198
|
if (opaqueResult) {
|
|
224
199
|
event.context.nextgenAuth = {
|
|
225
200
|
isAuthenticated: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { ZitadelLogin, ZitadelLogout } from '@zitadel/components';
|
|
|
2
2
|
export { createNextgenMiddleware, getAuth } from './runtime/server/middleware.js';
|
|
3
3
|
import { ZitadelProject } from '@zitadel/api/config';
|
|
4
4
|
export { ClientAuthResult } from './runtime/types.js';
|
|
5
|
-
export { AuthResult, NextgenMiddlewareOptions } from '@zitadel/sdk-core/
|
|
5
|
+
export { AuthResult, NextgenMiddlewareOptions } from '@zitadel/sdk-core/middleware';
|
|
6
6
|
import 'h3';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/index.js
CHANGED
package/dist/module.js
CHANGED
|
@@ -6,6 +6,27 @@ import {
|
|
|
6
6
|
addImportsDir,
|
|
7
7
|
createResolver
|
|
8
8
|
} from "@nuxt/kit";
|
|
9
|
+
import { existsSync, readFileSync } from "fs";
|
|
10
|
+
import { resolve as resolvePath } from "path";
|
|
11
|
+
function loadProjectSecret(rootDir) {
|
|
12
|
+
if (process.env.ZITADEL_PROJECT_SECRET) {
|
|
13
|
+
return process.env.ZITADEL_PROJECT_SECRET;
|
|
14
|
+
}
|
|
15
|
+
const path = resolvePath(rootDir, ".env.local");
|
|
16
|
+
if (!existsSync(path)) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
for (const line of readFileSync(path, "utf8").split(/\r?\n/)) {
|
|
20
|
+
const match = line.match(/^\s*(?:export\s+)?ZITADEL_PROJECT_SECRET\s*=\s*(.*)$/);
|
|
21
|
+
if (match && match[1] !== void 0) {
|
|
22
|
+
const raw = match[1].trim();
|
|
23
|
+
const quoted = raw.match(/^(['"])(.*)\1\s*(?:#.*)?$/);
|
|
24
|
+
const value = quoted ? quoted[2] : raw.replace(/\s+#.*$/, "").trim();
|
|
25
|
+
return value === "" ? void 0 : value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
9
30
|
var module_default = defineNuxtModule({
|
|
10
31
|
meta: {
|
|
11
32
|
name: "@zitadel/sdk-nuxt",
|
|
@@ -23,7 +44,12 @@ var module_default = defineNuxtModule({
|
|
|
23
44
|
url: options.url ?? "http://localhost:4000",
|
|
24
45
|
loginPath: options.loginPath ?? "/login",
|
|
25
46
|
protectedRoutes: options.protectedRoutes ?? [],
|
|
26
|
-
jwtKey: options.jwtKey
|
|
47
|
+
jwtKey: options.jwtKey,
|
|
48
|
+
// Server-only — never exposed to the client. Override at deploy time via
|
|
49
|
+
// `NUXT_NEXTGEN_PROJECT_SECRET`. Left undefined when the env var (and
|
|
50
|
+
// `.env.local`) provide no value, so the middleware surfaces a missing
|
|
51
|
+
// bearer instead of silently sending an empty one.
|
|
52
|
+
projectSecret: loadProjectSecret(nuxt.options.rootDir)
|
|
27
53
|
};
|
|
28
54
|
nuxt.options.runtimeConfig.public.zitadelProxyPath = options.proxyPath ?? "/__nextgen";
|
|
29
55
|
nuxt.options.runtimeConfig.public.nextgenProxyPath = options.proxyPath ?? "/__nextgen";
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// src/runtime/plugin.ts
|
|
2
|
-
import {
|
|
3
|
-
defineNuxtPlugin,
|
|
4
|
-
useRequestEvent,
|
|
5
|
-
useRuntimeConfig,
|
|
6
|
-
useState
|
|
7
|
-
} from "#imports";
|
|
2
|
+
import { defineNuxtPlugin, useRequestEvent, useRuntimeConfig, useState } from "#imports";
|
|
8
3
|
import { configureZitadel } from "@zitadel/api/config";
|
|
9
4
|
var plugin_default = defineNuxtPlugin(() => {
|
|
10
5
|
const event = useRequestEvent();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AuthResult, NextgenMiddlewareOptions } from '@zitadel/sdk-core/
|
|
1
|
+
import { AuthResult, NextgenMiddlewareOptions } from '@zitadel/sdk-core/middleware';
|
|
2
2
|
import { EventHandler, H3Event } from 'h3';
|
|
3
3
|
|
|
4
|
-
declare module
|
|
4
|
+
declare module "h3" {
|
|
5
5
|
interface H3EventContext {
|
|
6
6
|
nextgenAuth: AuthResult;
|
|
7
7
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UnauthState } from '@zitadel/sdk-core/
|
|
2
|
-
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/
|
|
1
|
+
import { UnauthState } from '@zitadel/sdk-core/middleware';
|
|
2
|
+
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/middleware';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Re-exports shared SDK types from `@zitadel/sdk-core`.
|
package/dist/server.d.ts
CHANGED
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zitadel/sdk-nuxt",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.12",
|
|
4
4
|
"description": "Nuxt proxy middleware and helpers for Nextgen Auth",
|
|
5
5
|
"homepage": "https://github.com/zitadel/nextgen/tree/main/packages/sdk-nuxt#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@zitadel/api": "0.1.0-alpha.
|
|
37
|
-
"@zitadel/
|
|
38
|
-
"@zitadel/
|
|
36
|
+
"@zitadel/api": "0.1.0-alpha.12",
|
|
37
|
+
"@zitadel/sdk-core": "0.1.0-alpha.12",
|
|
38
|
+
"@zitadel/components": "0.1.0-alpha.12"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"h3": ">=1",
|