@authaz/next 1.0.6 → 1.0.7

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 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.
@@ -95,6 +96,7 @@ const createAuthazHandler = (config) => {
95
96
  const afterLoginUrl = config.afterLoginUrl || "/";
96
97
  const afterLogoutUrl = config.afterLogoutUrl || "/";
97
98
  const authazDomain = config.authazDomain || "https://api.authaz.io";
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 action = pathParts[pathParts.length - 1];
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,9 +240,6 @@ 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("authazDomain", authazDomain);
236
- logError("accessToken", accessToken);
237
- logError("apiKey", apiKey);
238
243
  const userinfo = await fetchUserinfo(authazDomain, accessToken, apiKey);
239
244
  if (!userinfo) {
240
245
  logError("Failed to fetch userinfo");
@@ -246,6 +251,23 @@ const createAuthazHandler = (config) => {
246
251
  user
247
252
  });
248
253
  };
254
+ const handleUserinfo = async () => {
255
+ log("Getting userinfo (OAuth2 userinfo endpoint)");
256
+ const accessToken = (await getCookieStore()).get(COOKIE_NAMES.ACCESS_TOKEN)?.value;
257
+ if (!accessToken) return NextResponse.json({ error: "Unauthorized" }, {
258
+ status: 401,
259
+ headers: { "WWW-Authenticate": "Bearer" }
260
+ });
261
+ const userinfo = await fetchUserinfo(authazIdentityDomain, accessToken, apiKey);
262
+ if (!userinfo) {
263
+ logError("Failed to fetch userinfo");
264
+ return NextResponse.json({ error: "Unauthorized" }, {
265
+ status: 401,
266
+ headers: { "WWW-Authenticate": "Bearer" }
267
+ });
268
+ }
269
+ return NextResponse.json(userinfo);
270
+ };
249
271
  const handleRefresh = async (request) => {
250
272
  log("Handling token refresh");
251
273
  const refreshToken = (await getCookieStore()).get(COOKIE_NAMES.REFRESH_TOKEN)?.value;
@@ -273,6 +295,7 @@ const createAuthazHandler = (config) => {
273
295
  switch (action) {
274
296
  case "login": return handleLogin(request);
275
297
  case "me": return handleMe();
298
+ case "oauth2/userinfo": return handleUserinfo();
276
299
  case "callback":
277
300
  case "logout":
278
301
  case "refresh": return NextResponse.json({ error: "Method not allowed. Use POST." }, { status: 405 });
@@ -286,7 +309,8 @@ const createAuthazHandler = (config) => {
286
309
  case "logout": return handleLogout(request);
287
310
  case "refresh": return handleRefresh(request);
288
311
  case "login":
289
- case "me": return NextResponse.json({ error: "Method not allowed. Use GET." }, { status: 405 });
312
+ case "me":
313
+ case "oauth2/userinfo": return NextResponse.json({ error: "Method not allowed. Use GET." }, { status: 405 });
290
314
  default: return NextResponse.json({ error: `Unknown action: ${action}` }, { status: 404 });
291
315
  }
292
316
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "@authaz",
3
3
  "name": "@authaz/next",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
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.4"
42
+ "@authaz/sdk": "^1.2.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@jest/globals": "30.2.0",