@asgardeo/nextjs 0.3.9 → 0.3.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 (53) hide show
  1. package/dist/cjs/middleware.js +45 -0
  2. package/dist/cjs/middleware.js.map +7 -0
  3. package/dist/cjs/server/index.js +2 -10
  4. package/dist/cjs/server/index.js.map +2 -2
  5. package/dist/esm/client/contexts/Asgardeo/AsgardeoContext.js +2 -0
  6. package/dist/esm/client/contexts/Asgardeo/AsgardeoContext.js.map +1 -1
  7. package/dist/esm/client/contexts/Asgardeo/AsgardeoProvider.js +3 -1
  8. package/dist/esm/client/contexts/Asgardeo/AsgardeoProvider.js.map +1 -1
  9. package/dist/esm/constants/sessionConstants.js +49 -0
  10. package/dist/esm/constants/sessionConstants.js.map +1 -0
  11. package/dist/esm/middleware.js +35 -0
  12. package/dist/esm/middleware.js.map +1 -0
  13. package/dist/esm/server/AsgardeoProvider.js +4 -2
  14. package/dist/esm/server/AsgardeoProvider.js.map +1 -1
  15. package/dist/esm/server/actions/clearSession.js +49 -0
  16. package/dist/esm/server/actions/clearSession.js.map +1 -0
  17. package/dist/esm/server/actions/getAccessToken.js.map +1 -1
  18. package/dist/esm/server/actions/getSessionId.js.map +1 -1
  19. package/dist/esm/server/actions/getSessionPayload.js.map +1 -1
  20. package/dist/esm/server/actions/handleOAuthCallbackAction.js +6 -3
  21. package/dist/esm/server/actions/handleOAuthCallbackAction.js.map +1 -1
  22. package/dist/esm/server/actions/isSignedIn.js +11 -15
  23. package/dist/esm/server/actions/isSignedIn.js.map +1 -1
  24. package/dist/esm/server/actions/refreshToken.js +86 -0
  25. package/dist/esm/server/actions/refreshToken.js.map +1 -0
  26. package/dist/esm/server/actions/signInAction.js +13 -5
  27. package/dist/esm/server/actions/signInAction.js.map +1 -1
  28. package/dist/esm/server/actions/signOutAction.js.map +1 -1
  29. package/dist/esm/server/actions/switchOrganization.js +8 -9
  30. package/dist/esm/server/actions/switchOrganization.js.map +1 -1
  31. package/dist/esm/server/index.js +0 -3
  32. package/dist/esm/server/index.js.map +1 -1
  33. package/dist/esm/server/middleware/asgardeoMiddleware.js +182 -85
  34. package/dist/esm/server/middleware/asgardeoMiddleware.js.map +1 -1
  35. package/dist/esm/utils/SessionManager.js +54 -7
  36. package/dist/esm/utils/SessionManager.js.map +1 -1
  37. package/dist/esm/utils/decorateConfigWithNextEnv.js +5 -1
  38. package/dist/esm/utils/decorateConfigWithNextEnv.js.map +1 -1
  39. package/dist/esm/utils/handleRefreshToken.js +82 -0
  40. package/dist/esm/utils/handleRefreshToken.js.map +1 -0
  41. package/dist/types/client/contexts/Asgardeo/AsgardeoContext.d.ts +5 -1
  42. package/dist/types/client/contexts/Asgardeo/AsgardeoProvider.d.ts +3 -0
  43. package/dist/types/constants/sessionConstants.d.ts +48 -0
  44. package/dist/types/middleware.d.ts +34 -0
  45. package/dist/types/server/AsgardeoProvider.d.ts +14 -0
  46. package/dist/types/server/actions/clearSession.d.ts +39 -0
  47. package/dist/types/server/actions/isSignedIn.d.ts +8 -3
  48. package/dist/types/server/actions/refreshToken.d.ts +44 -0
  49. package/dist/types/server/index.d.ts +0 -3
  50. package/dist/types/server/middleware/asgardeoMiddleware.d.ts +20 -28
  51. package/dist/types/utils/SessionManager.d.ts +26 -5
  52. package/dist/types/utils/handleRefreshToken.d.ts +46 -0
  53. package/package.json +9 -3
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.js","sourceRoot":"","sources":["../../../src/utils/SessionManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,oBAAoB,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAC,OAAO,EAAE,SAAS,EAAa,MAAM,MAAM,CAAC;AAoBpD;;GAEG;AACH,MAAM,cAAc;IACV,MAAM,CAAU,sBAAsB,GAAW,IAAI,CAAC;IAE9D;;;OAGG;IACK,MAAM,CAAC,SAAS;QACtB,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M,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACxC,CAAC;YAED,OAAO,EAAC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAW,EAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,oBAAoB,CAC5B,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAC9F,4BAA4B,EAC5B,QAAQ,EACR,6CAA6C,CAC9C,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,uBAAuB,CAAC,MAAc;QAO3C,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,MAAM;YACN,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAc;YACxB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY;SACjD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,2BAA2B;QAOhC,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,EAAE,GAAG,EAAE;YACf,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAc;YACxB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY;SACjD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB;QACzB,OAAO,YAAY,CAAC,mBAAmB,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,wBAAwB;QAC7B,OAAO,YAAY,CAAC,wBAAwB,CAAC;IAC/C,CAAC;CACF;AAED,eAAe,cAAc,CAAC"}
@@ -16,7 +16,7 @@
16
16
  * under the License.
17
17
  */
18
18
  const decorateConfigWithNextEnv = (config) => {
19
- const { organizationHandle, scopes, applicationId, baseUrl, clientId, clientSecret, signInUrl, signUpUrl, afterSignInUrl, afterSignOutUrl, ...rest } = config;
19
+ const { organizationHandle, scopes, applicationId, baseUrl, clientId, clientSecret, signInUrl, signUpUrl, afterSignInUrl, afterSignOutUrl, sessionCookieExpiryTime, ...rest } = config;
20
20
  return {
21
21
  ...rest,
22
22
  afterSignInUrl: afterSignInUrl || process.env['NEXT_PUBLIC_ASGARDEO_AFTER_SIGN_IN_URL'],
@@ -27,6 +27,10 @@ const decorateConfigWithNextEnv = (config) => {
27
27
  clientSecret: clientSecret || process.env['ASGARDEO_CLIENT_SECRET'],
28
28
  organizationHandle: organizationHandle || process.env['NEXT_PUBLIC_ASGARDEO_ORGANIZATION_HANDLE'],
29
29
  scopes: scopes || process.env['NEXT_PUBLIC_ASGARDEO_SCOPES'],
30
+ sessionCookieExpiryTime: sessionCookieExpiryTime ||
31
+ (process.env['ASGARDEO_SESSION_COOKIE_EXPIRY_TIME']
32
+ ? parseInt(process.env['ASGARDEO_SESSION_COOKIE_EXPIRY_TIME'], 10)
33
+ : undefined),
30
34
  signInUrl: signInUrl || process.env['NEXT_PUBLIC_ASGARDEO_SIGN_IN_URL'],
31
35
  signUpUrl: signUpUrl || process.env['NEXT_PUBLIC_ASGARDEO_SIGN_UP_URL'],
32
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"decorateConfigWithNextEnv.js","sourceRoot":"","sources":["../../../src/utils/decorateConfigWithNextEnv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,yBAAyB,GAAG,CAAC,MAA0B,EAAsB,EAAE;IACnF,MAAM,EACJ,kBAAkB,EAClB,MAAM,EACN,aAAa,EACb,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,EACf,GAAG,IAAI,EACR,GAAG,MAAM,CAAC;IAEX,OAAO;QACL,GAAG,IAAI;QACP,cAAc,EAAE,cAAc,IAAK,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAY;QACnG,eAAe,EAAE,eAAe,IAAK,OAAO,CAAC,GAAG,CAAC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QAC9F,OAAO,EAAE,OAAO,IAAK,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAY;QAC5E,QAAQ,EAAE,QAAQ,IAAK,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAY;QAC/E,YAAY,EAAE,YAAY,IAAK,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAY;QAC/E,kBAAkB,EAAE,kBAAkB,IAAK,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAY;QAC7G,MAAM,EAAE,MAAM,IAAK,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAY;QACxE,uBAAuB,EACrB,uBAAuB;YACvB,CAAC,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC;gBACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,EAAE,EAAE,CAAC;gBAClE,CAAC,CAAC,SAAS,CAAC;QAChB,SAAS,EAAE,SAAS,IAAK,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAY;QACnF,SAAS,EAAE,SAAS,IAAK,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAY;KACpF,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import SessionManager from './SessionManager';
19
+ /**
20
+ * Handles the OAuth refresh_token grant and builds a new session JWT string.
21
+ *
22
+ * Intentionally decoupled from cookie APIs so it can be called from both the Edge
23
+ * Runtime (Next.js middleware) and the Node.js Runtime (server actions).
24
+ * Cookie persistence is the caller's responsibility.
25
+ */
26
+ const handleRefreshToken = async (sessionPayload, config) => {
27
+ const { baseUrl, clientId, clientSecret, sessionCookieExpiryTime: configuredExpiry } = config;
28
+ const { refreshToken: storedRefreshToken, sessionId, sub, scopes, organizationId } = sessionPayload;
29
+ if (!storedRefreshToken) {
30
+ throw new Error('No refresh token found in session payload.');
31
+ }
32
+ const tokenEndpoint = `${baseUrl}/oauth2/token`;
33
+ const body = new URLSearchParams({
34
+ client_id: clientId ?? '',
35
+ client_secret: clientSecret ?? '',
36
+ grant_type: 'refresh_token',
37
+ refresh_token: storedRefreshToken,
38
+ });
39
+ let response;
40
+ try {
41
+ response = await fetch(tokenEndpoint, {
42
+ body: body.toString(),
43
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
44
+ method: 'POST',
45
+ });
46
+ }
47
+ catch (fetchError) {
48
+ throw new Error(`Token refresh network error: ${fetchError instanceof Error ? fetchError.message : String(fetchError)}`);
49
+ }
50
+ if (!response.ok) {
51
+ throw new Error(`Token endpoint rejected refresh (HTTP ${response.status}).`);
52
+ }
53
+ let tokenData;
54
+ try {
55
+ tokenData = (await response.json());
56
+ }
57
+ catch {
58
+ throw new Error('Failed to parse token endpoint response as JSON.');
59
+ }
60
+ const newAccessToken = tokenData['access_token'];
61
+ const expiresIn = tokenData['expires_in'];
62
+ // Use the rotated refresh token if the server provided one; otherwise keep the existing one.
63
+ const newRefreshToken = tokenData['refresh_token'] ?? storedRefreshToken;
64
+ const newScopes = tokenData['scope'] ?? (Array.isArray(scopes) ? scopes.join(' ') : scopes ?? '');
65
+ const resolvedSessionCookieExpiry = SessionManager.resolveSessionCookieExpiry(configuredExpiry);
66
+ const newSessionToken = await SessionManager.createSessionToken(newAccessToken, sub, sessionId, newScopes, expiresIn, newRefreshToken, organizationId);
67
+ return {
68
+ newSessionToken,
69
+ sessionCookieExpiryTime: resolvedSessionCookieExpiry,
70
+ tokenResponse: {
71
+ accessToken: newAccessToken,
72
+ createdAt: Math.floor(Date.now() / 1000),
73
+ expiresIn: String(expiresIn),
74
+ idToken: tokenData['id_token'] ?? '',
75
+ refreshToken: newRefreshToken,
76
+ scope: newScopes,
77
+ tokenType: tokenData['token_type'] ?? 'Bearer',
78
+ },
79
+ };
80
+ };
81
+ export default handleRefreshToken;
82
+ //# sourceMappingURL=handleRefreshToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleRefreshToken.js","sourceRoot":"","sources":["../../../src/utils/handleRefreshToken.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,cAAqC,MAAM,kBAAkB,CAAC;AAsBrE;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAC9B,cAAmC,EACnC,MAAgC,EACG,EAAE;IACrC,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAC,GAAG,MAAM,CAAC;IAC5F,MAAM,EAAC,YAAY,EAAE,kBAAkB,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAC,GAAG,cAAc,CAAC;IAElG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,aAAa,GAAW,GAAG,OAAO,eAAe,CAAC;IACxD,MAAM,IAAI,GAAoB,IAAI,eAAe,CAAC;QAChD,SAAS,EAAE,QAAQ,IAAI,EAAE;QACzB,aAAa,EAAE,YAAY,IAAI,EAAE;QACjC,UAAU,EAAE,eAAe;QAC3B,aAAa,EAAE,kBAAkB;KAClC,CAAC,CAAC;IAEH,IAAI,QAAkB,CAAC;IAEvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,aAAa,EAAE;YACpC,IAAI,EAAE,IAAI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ACT,eAAe,EACf,cAAc,CACf,CAAC;IAEF,OAAO;QACL,eAAe;QACf,uBAAuB,EAAE,2BAA2B;QACpD,aAAa,EAAE;YACb,WAAW,EAAE,cAAc;YAC3B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YACxC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;YAC5B,OAAO,EAAG,SAAS,CAAC,UAAU,CAAwB,IAAI,EAAE;YAC5D,YAAY,EAAE,eAAe;YAC7B,KAAK,EAAE,SAAS;YAChB,SAAS,EAAG,SAAS,CAAC,YAAY,CAAwB,IAAI,QAAQ;SACvE;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -17,10 +17,14 @@
17
17
  */
18
18
  import { AsgardeoContextProps as AsgardeoReactContextProps } from '@asgardeo/react';
19
19
  import { Context } from 'react';
20
+ import { RefreshResult } from '../../../server/actions/refreshToken';
20
21
  /**
21
22
  * Props interface of {@link AsgardeoContext}
22
23
  */
23
- export type AsgardeoContextProps = Partial<AsgardeoReactContextProps>;
24
+ export type AsgardeoContextProps = Partial<AsgardeoReactContextProps> & {
25
+ clearSession?: () => Promise<void>;
26
+ refreshToken?: () => Promise<RefreshResult>;
27
+ };
24
28
  /**
25
29
  * Context object for managing the Authentication flow builder core context.
26
30
  */
@@ -19,12 +19,14 @@ import { AllOrganizationsApiResponse, Organization, UpdateMeProfileConfig, User,
19
19
  import { AsgardeoProviderProps } from '@asgardeo/react';
20
20
  import { FC, PropsWithChildren } from 'react';
21
21
  import { AsgardeoContextProps } from './AsgardeoContext';
22
+ import { RefreshResult } from '../../../server/actions/refreshToken';
22
23
  /**
23
24
  * Props interface of {@link AsgardeoClientProvider}
24
25
  */
25
26
  export type AsgardeoClientProviderProps = Partial<Omit<AsgardeoProviderProps, 'baseUrl' | 'clientId'>> & Pick<AsgardeoProviderProps, 'baseUrl' | 'clientId'> & {
26
27
  applicationId: AsgardeoContextProps['applicationId'];
27
28
  brandingPreference?: BrandingPreference | null;
29
+ clearSession: () => Promise<void>;
28
30
  createOrganization: (payload: CreateOrganizationPayload, sessionId: string) => Promise<Organization>;
29
31
  currentOrganization: Organization;
30
32
  getAllOrganizations: (options?: any, sessionId?: string) => Promise<AllOrganizationsApiResponse>;
@@ -36,6 +38,7 @@ export type AsgardeoClientProviderProps = Partial<Omit<AsgardeoProviderProps, 'b
36
38
  isSignedIn: boolean;
37
39
  myOrganizations: Organization[];
38
40
  organizationHandle: AsgardeoContextProps['organizationHandle'];
41
+ refreshToken: () => Promise<RefreshResult>;
39
42
  revalidateMyOrganizations?: (sessionId?: string) => Promise<Organization[]>;
40
43
  signIn: AsgardeoContextProps['signIn'];
41
44
  signOut: AsgardeoContextProps['signOut'];
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Number of seconds before access token expiry at which the SDK proactively
20
+ * refreshes the token. A 25-second buffer prevents races where the token is
21
+ * valid when a request starts but expires mid-flight.
22
+ */
23
+ export declare const REFRESH_BUFFER_SECONDS: number;
24
+ /**
25
+ * Default session cookie lifetime in seconds (24 hours).
26
+ *
27
+ * Used when no explicit session cookie expiry is configured. The session cookie
28
+ * lifetime can be overridden in two ways (evaluated in this order):
29
+ *
30
+ * 1. `sessionCookieExpiryTime` in `AsgardeoNodeConfig` — set programmatically
31
+ * when initialising the SDK.
32
+ * 2. `ASGARDEO_SESSION_COOKIE_EXPIRY_TIME` environment variable — set in `.env`
33
+ * (e.g. `ASGARDEO_SESSION_COOKIE_EXPIRY_TIME=86400`).
34
+ * 3. This constant — applied when neither of the above is present.
35
+ *
36
+ * Two independent expiry bounds apply to the session and they are generally
37
+ * NOT the same value:
38
+ *
39
+ * - JWT `exp` claim — set by `SessionManager.createSessionToken(...)` from
40
+ * the `accessTokenTtlSeconds` argument (i.e. the access token's `expires_in`
41
+ * returned by the auth server, typically ~1 hour). This controls when
42
+ * `verifySessionToken` rejects the token and is the trigger for a refresh.
43
+ * - Browser cookie `maxAge` — set by the caller (sign-in / refresh / org-switch
44
+ * actions) from `SessionManager.resolveSessionCookieExpiry(...)`, which returns
45
+ * this constant by default (24 hours). This controls how long the browser
46
+ * holds the cookie before discarding it.
47
+ */
48
+ export declare const DEFAULT_SESSION_COOKIE_EXPIRY_TIME: number;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Edge Runtime entry point — safe for use in Next.js middleware.ts.
20
+ *
21
+ * This file must only import modules whose full transitive dependency graph
22
+ * contains zero Node.js-only APIs (process.versions, fs, crypto, etc.).
23
+ * Permitted dependencies: jose, fetch, next/server, and local utilities
24
+ * that themselves satisfy the same constraint.
25
+ *
26
+ * Do NOT import from:
27
+ * - AsgardeoNextClient (depends on @asgardeo/node → @asgardeo/javascript)
28
+ * - server/AsgardeoProvider (depends on @asgardeo/node)
29
+ * - server/actions/* (depend on @asgardeo/node)
30
+ * - client/* (depend on @asgardeo/javascript via @asgardeo/react)
31
+ */
32
+ export { default as asgardeoMiddleware } from './server/middleware/asgardeoMiddleware';
33
+ export * from './server/middleware/asgardeoMiddleware';
34
+ export { default as createRouteMatcher } from './server/middleware/createRouteMatcher';
@@ -22,6 +22,20 @@ import { FC, PropsWithChildren } from 'react';
22
22
  */
23
23
  export type AsgardeoServerProviderProps = Partial<AsgardeoProviderProps> & {
24
24
  clientSecret?: string;
25
+ /**
26
+ * Session cookie lifetime in seconds. Determines how long the session cookie
27
+ * remains valid in the browser after sign-in.
28
+ *
29
+ * Resolution order (first defined value wins):
30
+ * 1. This prop — set here when mounting the provider.
31
+ * 2. `ASGARDEO_SESSION_COOKIE_EXPIRY_TIME` environment variable.
32
+ * 3. Built-in default of 86400 seconds (24 hours).
33
+ *
34
+ * @example
35
+ * // 8-hour session cookie
36
+ * <AsgardeoServerProvider sessionCookieExpiryTime={28800} ... />
37
+ */
38
+ sessionCookieExpiryTime?: number;
25
39
  };
26
40
  /**
27
41
  * Server-side provider component for Asgardeo authentication.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Deletes all Asgardeo session cookies from the browser without contacting the
20
+ * identity server.
21
+ *
22
+ * Use this for error-recovery scenarios where the local session must be wiped
23
+ * immediately: refresh token failures, corrupt sessions, or forced local sign-out
24
+ * when the identity server is unreachable.
25
+ *
26
+ * For a complete sign-out that also revokes the server-side session and obtains the
27
+ * after-sign-out redirect URL, use `signOutAction` instead.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { clearSession } from '@asgardeo/nextjs/server';
32
+ *
33
+ * // Inside a Server Action or Route Handler:
34
+ * await clearSession();
35
+ * redirect('/sign-in');
36
+ * ```
37
+ */
38
+ declare const clearSession: () => Promise<void>;
39
+ export default clearSession;
@@ -17,10 +17,15 @@
17
17
  */
18
18
  /**
19
19
  * Check if the user is currently signed in.
20
- * First tries JWT session validation, then falls back to legacy session check.
21
20
  *
22
- * @param sessionId - Optional session ID to check (if not provided, gets from cookies)
23
- * @returns True if user is signed in, false otherwise
21
+ * For JWT-based sessions: the session JWT exp claim is now tied to the access
22
+ * token expiry. A successful jwtVerify (inside getSessionPayload) already proves
23
+ * exp > now, so no separate timestamp comparison is needed here.
24
+ *
25
+ * Falls back to the legacy SDK in-memory check when no JWT session cookie exists.
26
+ *
27
+ * @param sessionId - Optional session ID (used only for the legacy fallback path)
28
+ * @returns True if the user is signed in with a valid, non-expired token
24
29
  */
25
30
  declare const isSignedIn: (sessionId?: string) => Promise<boolean>;
26
31
  export default isSignedIn;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Client-safe result of a token refresh.
20
+ *
21
+ * Intentionally omits accessToken, refreshToken, idToken, and scopes — those stay
22
+ * server-side in the HttpOnly session cookie. Returning tokens from a Server Action
23
+ * serializes them into browser memory, defeating the HttpOnly boundary and exposing
24
+ * them to XSS, browser extensions, and error-tracking SDKs.
25
+ *
26
+ * `expiresAt` is epoch seconds for the new access token; the client uses it to
27
+ * schedule the next refresh.
28
+ */
29
+ export interface RefreshResult {
30
+ expiresAt: number;
31
+ }
32
+ /**
33
+ * Server action to refresh the access token using the stored refresh token.
34
+ * Exchanges the refresh token for a new token set and updates the session cookie.
35
+ *
36
+ * Delegates the HTTP exchange to handleRefreshToken so the same logic is shared
37
+ * with the middleware token refresh path.
38
+ *
39
+ * Called from the client side (e.g. AsgardeoClientProvider refreshOnMount) where
40
+ * Next.js allows cookie mutation. When invoked during SSR rendering the cookie
41
+ * write is silently skipped and a warning is logged.
42
+ */
43
+ declare const refreshToken: () => Promise<RefreshResult>;
44
+ export default refreshToken;
@@ -18,6 +18,3 @@
18
18
  export { default as asgardeo } from './asgardeo';
19
19
  export { default as AsgardeoProvider } from './AsgardeoProvider.js';
20
20
  export * from './AsgardeoProvider.js';
21
- export { default as asgardeoMiddleware } from './middleware/asgardeoMiddleware';
22
- export * from './middleware/asgardeoMiddleware';
23
- export { default as createRouteMatcher } from './middleware/createRouteMatcher';
@@ -33,7 +33,7 @@ export type AsgardeoMiddlewareContext = {
33
33
  * 2. resolvedOptions.signInUrl
34
34
  * 3. resolvedOptions.defaultRedirect
35
35
  * 4. referer (if from same origin)
36
- * If none are available, throws an error.
36
+ * If none are available, falls back to '/'.
37
37
  */
38
38
  protectRoute: (routeOptions?: {
39
39
  redirect?: string;
@@ -44,16 +44,34 @@ type AsgardeoMiddlewareHandler = (asgardeo: AsgardeoMiddlewareContext, req: Next
44
44
  * Asgardeo middleware that integrates authentication into your Next.js application.
45
45
  * Similar to Clerk's clerkMiddleware pattern.
46
46
  *
47
+ * Proactively refreshes the access token when it is within REFRESH_BUFFER_SECONDS of
48
+ * expiry so that Server Components always receive a fresh session. The refresh also
49
+ * recovers expired tokens as long as a refresh token is present.
50
+ *
51
+ * The updated session cookie is written to:
52
+ * - The response → browser stores the new cookie for subsequent requests.
53
+ * - The forwarded request headers → the same-request Server Component render sees
54
+ * the fresh token immediately without waiting for the next navigation.
55
+ *
56
+ * Token refresh requires baseUrl, clientId, and clientSecret. These are resolved from
57
+ * the options argument first, then from the standard Asgardeo environment variables
58
+ * (NEXT_PUBLIC_ASGARDEO_BASE_URL, NEXT_PUBLIC_ASGARDEO_CLIENT_ID,
59
+ * ASGARDEO_CLIENT_SECRET). If none are available the refresh step is skipped silently.
60
+ *
47
61
  * @param handler - Optional handler function to customize middleware behavior
48
62
  * @param options - Configuration options for the middleware
49
63
  * @returns Next.js middleware function
50
64
  *
51
65
  * @example
52
66
  * ```typescript
53
- * // middleware.ts - Basic usage
67
+ * // middleware.ts - Basic usage (config read from env vars automatically)
54
68
  * import { asgardeoMiddleware } from '@asgardeo/nextjs';
55
69
  *
56
70
  * export default asgardeoMiddleware();
71
+ *
72
+ * export const config = {
73
+ * matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
74
+ * };
57
75
  * ```
58
76
  *
59
77
  * @example
@@ -69,32 +87,6 @@ type AsgardeoMiddlewareHandler = (asgardeo: AsgardeoMiddlewareContext, req: Next
69
87
  * }
70
88
  * });
71
89
  * ```
72
- *
73
- * @example
74
- * ```typescript
75
- * // Advanced usage with custom logic
76
- * import { asgardeoMiddleware, createRouteMatcher } from '@asgardeo/nextjs';
77
- *
78
- * const isProtectedRoute = createRouteMatcher(['/dashboard(.*)']);
79
- * const isAuthRoute = createRouteMatcher(['/sign-in', '/sign-up']);
80
- *
81
- * export default asgardeoMiddleware(async (asgardeo, req) => {
82
- * // Skip protection for auth routes
83
- * if (isAuthRoute(req)) return;
84
- *
85
- * // Protect specified routes
86
- * if (isProtectedRoute(req)) {
87
- * await asgardeo.protectRoute({ redirect: '/sign-in' });
88
- * }
89
- *
90
- * // Check authentication status
91
- * if (asgardeo.isSignedIn()) {
92
- * console.log('User is authenticated with session:', asgardeo.getSessionId());
93
- * }
94
- * }, {
95
- * defaultRedirect: '/sign-in'
96
- * });
97
- * ```
98
90
  */
99
91
  declare const asgardeoMiddleware: (handler?: AsgardeoMiddlewareHandler, options?: AsgardeoMiddlewareOptions | ((req: NextRequest) => AsgardeoMiddlewareOptions)) => ((request: NextRequest) => Promise<NextResponse>);
100
92
  export default asgardeoMiddleware;
@@ -20,24 +20,27 @@ import { JWTPayload } from 'jose';
20
20
  * Session token payload interface
21
21
  */
22
22
  export interface SessionTokenPayload extends JWTPayload {
23
- /** Expiration timestamp */
23
+ /** Expiration timestamp — doubles as the access token expiry (JWT exp == access token exp) */
24
24
  exp: number;
25
25
  /** Issued at timestamp */
26
26
  iat: number;
27
27
  /** Organization ID if applicable */
28
28
  organizationId?: string;
29
+ /** The refresh token; empty string if not provided by the auth server */
30
+ refreshToken: string;
29
31
  /** OAuth scopes */
30
32
  scopes: string[];
31
33
  /** Session ID */
32
34
  sessionId: string;
33
35
  /** User ID */
34
36
  sub: string;
37
+ /** Token type discriminant — must be 'session' for access-session JWTs */
38
+ type: 'session';
35
39
  }
36
40
  /**
37
41
  * Session management utility class for JWT-based session cookies
38
42
  */
39
43
  declare class SessionManager {
40
- private static readonly DEFAULT_EXPIRY_SECONDS;
41
44
  /**
42
45
  * Get the signing secret from environment variable
43
46
  * Throws error in production if not set
@@ -48,13 +51,31 @@ declare class SessionManager {
48
51
  */
49
52
  static createTempSession(sessionId: string): Promise<string>;
50
53
  /**
51
- * Create a session cookie with user information
54
+ * Resolve the session cookie expiry time in seconds.
55
+ *
56
+ * Resolution order (first defined value wins):
57
+ * 1. `configuredExpiry` — value from `AsgardeoNodeConfig.sessionCookieExpiryTime`
58
+ * 2. `ASGARDEO_SESSION_COOKIE_EXPIRY_TIME` environment variable
59
+ * 3. `DEFAULT_SESSION_COOKIE_EXPIRY_TIME` (24 hours)
52
60
  */
53
- static createSessionToken(accessToken: string, userId: string, sessionId: string, scopes: string, organizationId?: string, expirySeconds?: number): Promise<string>;
61
+ static resolveSessionCookieExpiry(configuredExpiry?: number): number;
62
+ static createSessionToken(accessToken: string, userId: string, sessionId: string, scopes: string, accessTokenTtlSeconds: number, refreshToken: string, organizationId?: string): Promise<string>;
54
63
  /**
55
64
  * Verify and decode a session token
56
65
  */
57
66
  static verifySessionToken(token: string): Promise<SessionTokenPayload>;
67
+ /**
68
+ * Verify a session token for refresh. Validates the HMAC signature and the
69
+ * `type === 'session'` discriminant but intentionally skips the `exp` check
70
+ * so an expired access token can still be exchanged for a new one.
71
+ *
72
+ * Session lifetime is still bounded — the cookie's `maxAge` is set from
73
+ * `sessionCookieExpiryTime`, so the browser drops an over-age session regardless
74
+ * of the access-token exp embedded in the JWT.
75
+ *
76
+ * Never use the returned payload for authorization.
77
+ */
78
+ static verifySessionTokenForRefresh(token: string): Promise<SessionTokenPayload>;
58
79
  /**
59
80
  * Verify and decode a temporary session token
60
81
  */
@@ -64,7 +85,7 @@ declare class SessionManager {
64
85
  /**
65
86
  * Get session cookie options
66
87
  */
67
- static getSessionCookieOptions(): {
88
+ static getSessionCookieOptions(maxAge: number): {
68
89
  httpOnly: boolean;
69
90
  maxAge: number;
70
91
  path: string;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import type { TokenResponse } from '@asgardeo/node';
19
+ import { SessionTokenPayload } from './SessionManager';
20
+ /**
21
+ * Config required to call the token endpoint.
22
+ */
23
+ export interface HandleRefreshTokenConfig {
24
+ baseUrl: string;
25
+ clientId: string;
26
+ clientSecret: string;
27
+ sessionCookieExpiryTime?: number;
28
+ }
29
+ /**
30
+ * Result returned by handleRefreshToken.
31
+ * Callers are responsible for persisting newSessionToken in the appropriate cookie context.
32
+ */
33
+ export interface HandleRefreshTokenResult {
34
+ newSessionToken: string;
35
+ sessionCookieExpiryTime: number;
36
+ tokenResponse: TokenResponse;
37
+ }
38
+ /**
39
+ * Handles the OAuth refresh_token grant and builds a new session JWT string.
40
+ *
41
+ * Intentionally decoupled from cookie APIs so it can be called from both the Edge
42
+ * Runtime (Next.js middleware) and the Node.js Runtime (server actions).
43
+ * Cookie persistence is the caller's responsibility.
44
+ */
45
+ declare const handleRefreshToken: (sessionPayload: SessionTokenPayload, config: HandleRefreshTokenConfig) => Promise<HandleRefreshTokenResult>;
46
+ export default handleRefreshToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgardeo/nextjs",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Next.js implementation of Asgardeo JavaScript SDK.",
5
5
  "keywords": [
6
6
  "asgardeo",
@@ -28,6 +28,12 @@
28
28
  "types": "./dist/types/server/index.d.ts",
29
29
  "import": "./dist/esm/server/index.js",
30
30
  "require": "./dist/cjs/server/index.js"
31
+ },
32
+ "./middleware": {
33
+ "types": "./dist/types/middleware.d.ts",
34
+ "edge-light": "./dist/esm/middleware.js",
35
+ "import": "./dist/esm/middleware.js",
36
+ "require": "./dist/cjs/middleware.js"
31
37
  }
32
38
  },
33
39
  "files": [
@@ -45,8 +51,8 @@
45
51
  "@types/react": "19.2.14",
46
52
  "jose": "5.10.0",
47
53
  "tslib": "2.8.1",
48
- "@asgardeo/node": "0.0.73",
49
- "@asgardeo/react": "0.22.4"
54
+ "@asgardeo/node": "0.0.75",
55
+ "@asgardeo/react": "0.23.0"
50
56
  },
51
57
  "devDependencies": {
52
58
  "@types/node": "22.15.3",