@authaz/next 1.0.6 → 1.0.8
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/index.d.ts +7 -0
- package/dist/index.js +34 -8
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ type AuthazNextConfig = AuthazConfig & {
|
|
|
28
28
|
* Falls back to clientSecret if not provided.
|
|
29
29
|
*/
|
|
30
30
|
apiKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Domain for Universal Login (OAuth authorize, token, logout).
|
|
33
|
+
* Default: "https://identity.authaz.io".
|
|
34
|
+
* When set, the handler uses this for the login redirect; the core client uses it for OAuth flows.
|
|
35
|
+
*/
|
|
36
|
+
authazIdentityDomain?: string;
|
|
31
37
|
/**
|
|
32
38
|
* Enable debug logging
|
|
33
39
|
*/
|
|
@@ -45,6 +51,7 @@ type AuthHandler = {
|
|
|
45
51
|
* - POST /api/auth/callback - Handles OAuth callback (receives code via form POST)
|
|
46
52
|
* - POST /api/auth/logout - Clears session and redirects to logout (POST-only for CSRF protection)
|
|
47
53
|
* - GET /api/auth/me - Returns current user info (requires valid session)
|
|
54
|
+
* - GET /api/auth/oauth2/userinfo - Returns OIDC userinfo payload (same as backend /oauth2/userinfo)
|
|
48
55
|
* - POST /api/auth/refresh - Refreshes the access token
|
|
49
56
|
*
|
|
50
57
|
* IMPORTANT: The OAuth callback from the identity provider arrives as GET.
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const toNextCookieOptions = (options) => {
|
|
|
31
31
|
* - POST /api/auth/callback - Handles OAuth callback (receives code via form POST)
|
|
32
32
|
* - POST /api/auth/logout - Clears session and redirects to logout (POST-only for CSRF protection)
|
|
33
33
|
* - GET /api/auth/me - Returns current user info (requires valid session)
|
|
34
|
+
* - GET /api/auth/oauth2/userinfo - Returns OIDC userinfo payload (same as backend /oauth2/userinfo)
|
|
34
35
|
* - POST /api/auth/refresh - Refreshes the access token
|
|
35
36
|
*
|
|
36
37
|
* IMPORTANT: The OAuth callback from the identity provider arrives as GET.
|
|
@@ -94,7 +95,8 @@ const createAuthazHandler = (config) => {
|
|
|
94
95
|
};
|
|
95
96
|
const afterLoginUrl = config.afterLoginUrl || "/";
|
|
96
97
|
const afterLogoutUrl = config.afterLogoutUrl || "/";
|
|
97
|
-
|
|
98
|
+
config.authazDomain;
|
|
99
|
+
const authazIdentityDomain = config.authazIdentityDomain || "https://identity.authaz.io";
|
|
98
100
|
const fixedRedirectUri = config.redirectUri;
|
|
99
101
|
const isDebug = config.debug || false;
|
|
100
102
|
const apiKey = config.apiKey || config.clientSecret;
|
|
@@ -106,8 +108,14 @@ const createAuthazHandler = (config) => {
|
|
|
106
108
|
};
|
|
107
109
|
const getAction = (request) => {
|
|
108
110
|
const url = new URL(request.url);
|
|
109
|
-
const pathParts = url.pathname.split("/");
|
|
110
|
-
const
|
|
111
|
+
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
112
|
+
const last = pathParts[pathParts.length - 1];
|
|
113
|
+
const prev = pathParts[pathParts.length - 2];
|
|
114
|
+
if (last === "userinfo" && prev === "oauth2") {
|
|
115
|
+
log(`getAction: pathname=${url.pathname}, action=oauth2/userinfo`);
|
|
116
|
+
return "oauth2/userinfo";
|
|
117
|
+
}
|
|
118
|
+
const action = last ?? "";
|
|
111
119
|
log(`getAction: pathname=${url.pathname}, action=${action}`);
|
|
112
120
|
return action;
|
|
113
121
|
};
|
|
@@ -232,10 +240,8 @@ const createAuthazHandler = (config) => {
|
|
|
232
240
|
log("Getting current user");
|
|
233
241
|
const accessToken = (await getCookieStore()).get(COOKIE_NAMES.ACCESS_TOKEN)?.value;
|
|
234
242
|
if (!accessToken) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
235
|
-
logError("
|
|
236
|
-
|
|
237
|
-
logError("apiKey", apiKey);
|
|
238
|
-
const userinfo = await fetchUserinfo(authazDomain, accessToken, apiKey);
|
|
243
|
+
logError("1 -- authazIdentityDomain", authazIdentityDomain);
|
|
244
|
+
const userinfo = await fetchUserinfo(authazIdentityDomain, accessToken, apiKey);
|
|
239
245
|
if (!userinfo) {
|
|
240
246
|
logError("Failed to fetch userinfo");
|
|
241
247
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
@@ -246,6 +252,24 @@ const createAuthazHandler = (config) => {
|
|
|
246
252
|
user
|
|
247
253
|
});
|
|
248
254
|
};
|
|
255
|
+
const handleUserinfo = async () => {
|
|
256
|
+
log("Getting userinfo (OAuth2 userinfo endpoint)");
|
|
257
|
+
const accessToken = (await getCookieStore()).get(COOKIE_NAMES.ACCESS_TOKEN)?.value;
|
|
258
|
+
if (!accessToken) return NextResponse.json({ error: "Unauthorized" }, {
|
|
259
|
+
status: 401,
|
|
260
|
+
headers: { "WWW-Authenticate": "Bearer" }
|
|
261
|
+
});
|
|
262
|
+
logError("2 -- authazIdentityDomain", authazIdentityDomain);
|
|
263
|
+
const userinfo = await fetchUserinfo(authazIdentityDomain, accessToken, apiKey);
|
|
264
|
+
if (!userinfo) {
|
|
265
|
+
logError("Failed to fetch userinfo");
|
|
266
|
+
return NextResponse.json({ error: "Unauthorized" }, {
|
|
267
|
+
status: 401,
|
|
268
|
+
headers: { "WWW-Authenticate": "Bearer" }
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return NextResponse.json(userinfo);
|
|
272
|
+
};
|
|
249
273
|
const handleRefresh = async (request) => {
|
|
250
274
|
log("Handling token refresh");
|
|
251
275
|
const refreshToken = (await getCookieStore()).get(COOKIE_NAMES.REFRESH_TOKEN)?.value;
|
|
@@ -273,6 +297,7 @@ const createAuthazHandler = (config) => {
|
|
|
273
297
|
switch (action) {
|
|
274
298
|
case "login": return handleLogin(request);
|
|
275
299
|
case "me": return handleMe();
|
|
300
|
+
case "oauth2/userinfo": return handleUserinfo();
|
|
276
301
|
case "callback":
|
|
277
302
|
case "logout":
|
|
278
303
|
case "refresh": return NextResponse.json({ error: "Method not allowed. Use POST." }, { status: 405 });
|
|
@@ -286,7 +311,8 @@ const createAuthazHandler = (config) => {
|
|
|
286
311
|
case "logout": return handleLogout(request);
|
|
287
312
|
case "refresh": return handleRefresh(request);
|
|
288
313
|
case "login":
|
|
289
|
-
case "me":
|
|
314
|
+
case "me":
|
|
315
|
+
case "oauth2/userinfo": return NextResponse.json({ error: "Method not allowed. Use GET." }, { status: 405 });
|
|
290
316
|
default: return NextResponse.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
291
317
|
}
|
|
292
318
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "@authaz",
|
|
3
3
|
"name": "@authaz/next",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "NextJS authaz SDK",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"next": ">=15",
|
|
41
41
|
"react": ">=17",
|
|
42
|
-
"@authaz/sdk": "^1.2.
|
|
42
|
+
"@authaz/sdk": "^1.2.6"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@jest/globals": "30.2.0",
|