@zitadel/sdk-next 0.1.0-alpha.0 → 0.1.0-alpha.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.
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +2 -2
- package/dist/{chunk-4KENHIG4.js → chunk-7D5LORRL.js} +12 -33
- package/dist/chunk-KHTLEMQO.js +8 -0
- package/dist/{chunk-B7S6XMT3.js → chunk-WZU5OYIF.js} +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +2 -2
- package/dist/server.d.ts +1 -1
- package/dist/server.js +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/useAuth.d.ts +1 -1
- package/package.json +9 -9
- package/dist/chunk-OCZMYSFX.js +0 -13
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/auth.d.ts
CHANGED
package/dist/auth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
base64UrlDecode,
|
|
3
3
|
verifyJwt
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KHTLEMQO.js";
|
|
5
5
|
|
|
6
6
|
// src/middleware.ts
|
|
7
7
|
import {
|
|
@@ -35,8 +35,7 @@ async function nextgenMiddleware(req, options = {}) {
|
|
|
35
35
|
audience,
|
|
36
36
|
allowedTokenTypes = ["JWT", "at+JWT"],
|
|
37
37
|
jwksTimeoutMs,
|
|
38
|
-
proxyTimeoutMs = 5e3
|
|
39
|
-
onExchangeResponse
|
|
38
|
+
proxyTimeoutMs = 5e3
|
|
40
39
|
} = options;
|
|
41
40
|
if (!loginPath.startsWith("/") || loginPath.startsWith("//")) {
|
|
42
41
|
throw new Error(
|
|
@@ -49,13 +48,7 @@ async function nextgenMiddleware(req, options = {}) {
|
|
|
49
48
|
return NextResponse.next({ request: { headers } });
|
|
50
49
|
}
|
|
51
50
|
if (pathname === proxyPath || pathname.startsWith(`${proxyPath}/`)) {
|
|
52
|
-
return proxyRequest(
|
|
53
|
-
req,
|
|
54
|
-
url,
|
|
55
|
-
proxyPath,
|
|
56
|
-
proxyTimeoutMs,
|
|
57
|
-
onExchangeResponse
|
|
58
|
-
);
|
|
51
|
+
return proxyRequest(req, url, proxyPath, proxyTimeoutMs);
|
|
59
52
|
}
|
|
60
53
|
return handleAuth(req, {
|
|
61
54
|
url,
|
|
@@ -74,9 +67,7 @@ function isJwtShaped(token) {
|
|
|
74
67
|
const parts = token.split(".");
|
|
75
68
|
if (parts.length < 3 || !parts[0]) return false;
|
|
76
69
|
try {
|
|
77
|
-
const header = JSON.parse(
|
|
78
|
-
DECODER.decode(base64UrlDecode(parts[0]))
|
|
79
|
-
);
|
|
70
|
+
const header = JSON.parse(DECODER.decode(base64UrlDecode(parts[0])));
|
|
80
71
|
return typeof header?.alg === "string" && !("enc" in header);
|
|
81
72
|
} catch {
|
|
82
73
|
return false;
|
|
@@ -94,7 +85,7 @@ async function validateOpaqueSessionToken(token, issuerUrl, timeoutMs) {
|
|
|
94
85
|
return false;
|
|
95
86
|
}
|
|
96
87
|
}
|
|
97
|
-
async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs
|
|
88
|
+
async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs) {
|
|
98
89
|
const url = new URL(req.url);
|
|
99
90
|
const suffix = url.pathname.slice(proxyPath.length);
|
|
100
91
|
const target = `${authUrl}${suffix}${url.search}`;
|
|
@@ -108,10 +99,7 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
|
|
|
108
99
|
const directIp = req.ip ?? req.headers.get("x-real-ip");
|
|
109
100
|
if (directIp) {
|
|
110
101
|
const existingXff = upstreamHeaders.get("x-forwarded-for");
|
|
111
|
-
upstreamHeaders.set(
|
|
112
|
-
"x-forwarded-for",
|
|
113
|
-
existingXff ? `${existingXff}, ${directIp}` : directIp
|
|
114
|
-
);
|
|
102
|
+
upstreamHeaders.set("x-forwarded-for", existingXff ? `${existingXff}, ${directIp}` : directIp);
|
|
115
103
|
}
|
|
116
104
|
if (!upstreamHeaders.has("x-forwarded-host")) {
|
|
117
105
|
upstreamHeaders.set("x-forwarded-host", url.host);
|
|
@@ -120,11 +108,10 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
|
|
|
120
108
|
upstreamHeaders.set("x-forwarded-proto", url.protocol.replace(":", ""));
|
|
121
109
|
}
|
|
122
110
|
const hasBody = !["GET", "HEAD"].includes(req.method);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
upstreamHeaders.set("authorization", `Bearer sk_${projectId}`);
|
|
111
|
+
if (!upstreamHeaders.has("authorization")) {
|
|
112
|
+
const secret = process.env.ZITADEL_PROJECT_SECRET;
|
|
113
|
+
if (secret) {
|
|
114
|
+
upstreamHeaders.set("authorization", `Bearer ${secret}`);
|
|
128
115
|
}
|
|
129
116
|
}
|
|
130
117
|
const bodyBuffer = hasBody ? await req.arrayBuffer() : void 0;
|
|
@@ -140,14 +127,10 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
|
|
|
140
127
|
for (const cookie of setCookies) {
|
|
141
128
|
responseHeaders.append("set-cookie", cookie);
|
|
142
129
|
}
|
|
143
|
-
|
|
130
|
+
return new Response(upstream.body, {
|
|
144
131
|
status: upstream.status,
|
|
145
132
|
headers: responseHeaders
|
|
146
133
|
});
|
|
147
|
-
if (isExchangeRequest && onExchangeResponse) {
|
|
148
|
-
response = await onExchangeResponse(response);
|
|
149
|
-
}
|
|
150
|
-
return response;
|
|
151
134
|
}
|
|
152
135
|
async function handleAuth(req, opts) {
|
|
153
136
|
const {
|
|
@@ -178,11 +161,7 @@ async function handleAuth(req, opts) {
|
|
|
178
161
|
return NextResponse.next({ request: { headers: tunnelled2 } });
|
|
179
162
|
}
|
|
180
163
|
if (!payload && cookieToken && !isJwtShaped(cookieToken)) {
|
|
181
|
-
const isValid = await validateOpaqueSessionToken(
|
|
182
|
-
cookieToken,
|
|
183
|
-
url,
|
|
184
|
-
jwksTimeoutMs ?? 5e3
|
|
185
|
-
);
|
|
164
|
+
const isValid = await validateOpaqueSessionToken(cookieToken, url, jwksTimeoutMs ?? 5e3);
|
|
186
165
|
if (isValid) {
|
|
187
166
|
const tunnelled2 = tunnelHeaders(req, {
|
|
188
167
|
"x-nextgen-auth-token": cookieToken
|
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { AuthResult, NextgenSession } from '@zitadel/sdk-core/
|
|
3
|
+
import { AuthResult, NextgenSession } from '@zitadel/sdk-core/middleware';
|
|
4
4
|
|
|
5
5
|
declare function NextgenProvider({ session, children, }: {
|
|
6
6
|
session: AuthResult | NextgenSession | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/
|
|
1
|
+
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/middleware';
|
|
2
2
|
export { ProxyHandler, ProxyOptions, createProxy, nextgenMiddleware } from './middleware.js';
|
|
3
3
|
export { auth } from './auth.js';
|
|
4
4
|
export { NextgenProvider, useAuthContext } from './context.js';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProxy,
|
|
3
3
|
nextgenMiddleware
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7D5LORRL.js";
|
|
5
5
|
import {
|
|
6
6
|
auth
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-WZU5OYIF.js";
|
|
8
|
+
import "./chunk-KHTLEMQO.js";
|
|
9
9
|
import "./chunk-6F4PWJZI.js";
|
|
10
10
|
import {
|
|
11
11
|
useAuth
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZitadelProject } from '@zitadel/api/config';
|
|
2
|
-
import { NextgenMiddlewareOptions } from '@zitadel/sdk-core/
|
|
2
|
+
import { NextgenMiddlewareOptions } from '@zitadel/sdk-core/middleware';
|
|
3
3
|
import { NextRequest, NextResponse } from 'next/server';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -38,7 +38,7 @@ declare function nextgenMiddleware(req: NextRequest, options?: NextgenMiddleware
|
|
|
38
38
|
* `proxyPath` and `url` are omitted because they come from the
|
|
39
39
|
* {@link ZitadelConfig} passed as the first argument.
|
|
40
40
|
*/
|
|
41
|
-
type ProxyOptions = Omit<NextgenMiddlewareOptions,
|
|
41
|
+
type ProxyOptions = Omit<NextgenMiddlewareOptions, "proxyPath" | "url">;
|
|
42
42
|
/**
|
|
43
43
|
* A pre-configured middleware handler returned by {@link createProxy}.
|
|
44
44
|
*/
|
package/dist/middleware.js
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { auth } from './auth.js';
|
|
2
|
-
import '@zitadel/sdk-core/
|
|
2
|
+
import '@zitadel/sdk-core/middleware';
|
package/dist/server.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/
|
|
1
|
+
export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/middleware';
|
|
2
2
|
import '@zitadel/components';
|
|
3
3
|
import '@zitadel/api/config';
|
package/dist/useAuth.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zitadel/sdk-next",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"description": "Next.js helpers and mock auth UI for Zitadel",
|
|
5
5
|
"homepage": "https://github.com/zitadel/nextgen/tree/main/packages/sdk-next#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"server-only": "^0.0.1",
|
|
42
|
-
"@zitadel/
|
|
43
|
-
"@zitadel/
|
|
44
|
-
"@zitadel/
|
|
42
|
+
"@zitadel/components": "0.1.0-alpha.11",
|
|
43
|
+
"@zitadel/sdk-core": "0.1.0-alpha.11",
|
|
44
|
+
"@zitadel/api": "0.1.0-alpha.11"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"next": ">=14",
|
|
@@ -50,12 +50,10 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@eslint/js": "^9.0.0",
|
|
53
|
-
"tsup": "^8.3.5",
|
|
54
|
-
"typescript": "^5.7.3",
|
|
55
53
|
"@eslint/json": "^0.11.0",
|
|
56
54
|
"@eslint/markdown": "^6.0.0",
|
|
57
|
-
"@testing-library/react": "^16.
|
|
58
|
-
"@testing-library/user-event": "^14.
|
|
55
|
+
"@testing-library/react": "^16.3.2",
|
|
56
|
+
"@testing-library/user-event": "^14.6.1",
|
|
59
57
|
"@types/react": "^19.2.14",
|
|
60
58
|
"eslint": "^9.0.0",
|
|
61
59
|
"eslint-config-prettier": "^10.0.0",
|
|
@@ -67,9 +65,11 @@
|
|
|
67
65
|
"eslint-plugin-react": "^7.37.0",
|
|
68
66
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
69
67
|
"eslint-plugin-testing-library": "^7.0.0",
|
|
70
|
-
"jsdom": "^
|
|
68
|
+
"jsdom": "^29.0.2",
|
|
71
69
|
"next": "^16.2.4",
|
|
72
70
|
"prettier": "^3.0.0",
|
|
71
|
+
"tsup": "^8.3.5",
|
|
72
|
+
"typescript": "^5.7.3",
|
|
73
73
|
"typescript-eslint": "^8.0.0",
|
|
74
74
|
"vitest": "^3.0.0"
|
|
75
75
|
},
|
package/dist/chunk-OCZMYSFX.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"fileNames":[],"fileInfos":[],"root":[],"options":{"composite":true,"declarationMap":true,"emitDeclarationOnly":true,"importHelpers":true,"module":99,"noEmitOnError":true,"noFallthroughCasesInSwitch":true,"noImplicitOverride":true,"noImplicitReturns":true,"noUncheckedIndexedAccess":true,"noUnusedLocals":true,"skipLibCheck":true,"strict":true,"target":9,"tsBuildInfoFile":"./tsconfig.tsbuildinfo"},"version":"5.9.3"}
|