@asgardeo/nuxt 0.0.0 → 0.1.0

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 (119) hide show
  1. package/README.md +482 -6
  2. package/dist/module.d.mts +17 -24
  3. package/dist/module.json +2 -2
  4. package/dist/module.mjs +174 -48
  5. package/dist/runtime/components/AsgardeoRoot.d.ts +52 -0
  6. package/dist/runtime/components/AsgardeoRoot.js +160 -0
  7. package/dist/runtime/components/actions/SignInButton.d.ts +37 -0
  8. package/dist/runtime/components/actions/SignInButton.js +51 -0
  9. package/dist/runtime/components/actions/SignOutButton.d.ts +34 -0
  10. package/dist/runtime/components/actions/SignOutButton.js +43 -0
  11. package/dist/runtime/components/actions/SignUpButton.d.ts +33 -0
  12. package/dist/runtime/components/actions/SignUpButton.js +48 -0
  13. package/dist/runtime/components/auth/Callback.d.ts +43 -0
  14. package/dist/runtime/components/auth/Callback.js +93 -0
  15. package/dist/runtime/components/auth/SignIn.d.ts +38 -0
  16. package/dist/runtime/components/auth/SignIn.js +60 -0
  17. package/dist/runtime/components/auth/SignUp.d.ts +40 -0
  18. package/dist/runtime/components/auth/SignUp.js +79 -0
  19. package/dist/runtime/components/control/Loading.d.ts +36 -0
  20. package/dist/runtime/components/control/Loading.js +17 -0
  21. package/dist/runtime/components/control/SignedIn.d.ts +38 -0
  22. package/dist/runtime/components/control/SignedIn.js +17 -0
  23. package/dist/runtime/components/control/SignedOut.d.ts +37 -0
  24. package/dist/runtime/components/control/SignedOut.js +17 -0
  25. package/dist/runtime/components/organization/CreateOrganization.d.ts +32 -0
  26. package/dist/runtime/components/organization/CreateOrganization.js +29 -0
  27. package/dist/runtime/components/organization/Organization.d.ts +39 -0
  28. package/dist/runtime/components/organization/Organization.js +17 -0
  29. package/dist/runtime/components/organization/OrganizationList.d.ts +34 -0
  30. package/dist/runtime/components/organization/OrganizationList.js +30 -0
  31. package/dist/runtime/components/organization/OrganizationProfile.d.ts +32 -0
  32. package/dist/runtime/components/organization/OrganizationProfile.js +32 -0
  33. package/dist/runtime/components/organization/OrganizationSwitcher.d.ts +36 -0
  34. package/dist/runtime/components/organization/OrganizationSwitcher.js +26 -0
  35. package/dist/runtime/components/user/User.d.ts +38 -0
  36. package/dist/runtime/components/user/User.js +17 -0
  37. package/dist/runtime/components/user/UserDropdown.d.ts +38 -0
  38. package/dist/runtime/components/user/UserDropdown.js +45 -0
  39. package/dist/runtime/components/user/UserProfile.d.ts +35 -0
  40. package/dist/runtime/components/user/UserProfile.js +35 -0
  41. package/dist/runtime/composables/useAsgardeo.d.ts +38 -0
  42. package/dist/runtime/composables/useAsgardeo.js +73 -0
  43. package/dist/runtime/errors/asgardeo-error.d.ts +47 -0
  44. package/dist/runtime/errors/asgardeo-error.js +15 -0
  45. package/dist/runtime/errors/error-codes.d.ts +40 -0
  46. package/dist/runtime/errors/error-codes.js +19 -0
  47. package/dist/runtime/{composables/asgardeo/useAuth.d.ts → errors/index.d.ts} +2 -2
  48. package/dist/runtime/errors/index.js +2 -0
  49. package/dist/runtime/middleware/auth.d.ts +35 -0
  50. package/dist/runtime/middleware/auth.js +2 -0
  51. package/dist/runtime/middleware/defineAsgardeoMiddleware.d.ts +53 -0
  52. package/dist/runtime/middleware/defineAsgardeoMiddleware.js +24 -0
  53. package/dist/runtime/plugins/asgardeo.d.ts +40 -0
  54. package/dist/runtime/plugins/asgardeo.js +129 -0
  55. package/dist/runtime/server/AsgardeoNuxtClient.d.ts +182 -0
  56. package/dist/runtime/server/AsgardeoNuxtClient.js +366 -0
  57. package/dist/runtime/server/index.d.ts +33 -0
  58. package/dist/runtime/server/index.js +3 -0
  59. package/dist/runtime/server/plugins/asgardeo-ssr.d.ts +41 -0
  60. package/dist/runtime/server/plugins/asgardeo-ssr.js +134 -0
  61. package/dist/runtime/server/routes/auth/branding/branding.get.d.ts +31 -0
  62. package/dist/runtime/server/routes/auth/branding/branding.get.js +40 -0
  63. package/dist/runtime/server/routes/auth/organizations/current.get.d.ts +29 -0
  64. package/dist/runtime/server/routes/auth/organizations/current.get.js +24 -0
  65. package/dist/runtime/server/routes/auth/organizations/id.get.d.ts +28 -0
  66. package/dist/runtime/server/routes/auth/organizations/id.get.js +28 -0
  67. package/dist/runtime/server/routes/auth/organizations/index.get.d.ts +28 -0
  68. package/dist/runtime/server/routes/auth/organizations/index.get.js +24 -0
  69. package/dist/runtime/server/routes/auth/organizations/index.post.d.ts +30 -0
  70. package/dist/runtime/server/routes/auth/organizations/index.post.js +30 -0
  71. package/dist/runtime/server/routes/auth/organizations/me.get.d.ts +28 -0
  72. package/dist/runtime/server/routes/auth/organizations/me.get.js +24 -0
  73. package/dist/runtime/server/routes/auth/organizations/switch.post.d.ts +32 -0
  74. package/dist/runtime/server/routes/auth/organizations/switch.post.js +49 -0
  75. package/dist/runtime/server/routes/auth/session/callback.get.d.ts +27 -0
  76. package/dist/runtime/server/routes/auth/session/callback.get.js +91 -0
  77. package/dist/runtime/server/routes/auth/session/callback.post.d.ts +48 -0
  78. package/dist/runtime/server/routes/auth/session/callback.post.js +53 -0
  79. package/dist/runtime/server/routes/auth/session/session.get.d.ts +26 -0
  80. package/dist/runtime/server/routes/auth/session/session.get.js +22 -0
  81. package/dist/runtime/server/routes/auth/session/signin.get.d.ts +29 -0
  82. package/dist/runtime/server/routes/auth/session/signin.get.js +37 -0
  83. package/dist/runtime/server/routes/auth/session/signin.post.d.ts +37 -0
  84. package/dist/runtime/server/routes/auth/session/signin.post.js +102 -0
  85. package/dist/runtime/server/routes/auth/session/signout.post.d.ts +31 -0
  86. package/dist/runtime/server/routes/auth/session/signout.post.js +38 -0
  87. package/dist/runtime/server/routes/auth/session/signup.post.d.ts +36 -0
  88. package/dist/runtime/server/routes/auth/session/signup.post.js +30 -0
  89. package/dist/runtime/server/routes/auth/session/token.get.d.ts +29 -0
  90. package/dist/runtime/server/routes/auth/session/token.get.js +6 -0
  91. package/dist/runtime/server/routes/auth/user/profile.get.d.ts +29 -0
  92. package/dist/runtime/server/routes/auth/user/profile.get.js +24 -0
  93. package/dist/runtime/server/{handler.d.ts → routes/auth/user/profile.patch.d.ts} +17 -13
  94. package/dist/runtime/server/routes/auth/user/profile.patch.js +33 -0
  95. package/dist/runtime/server/{services/asgardeo/index.d.ts → routes/auth/user/user.get.d.ts} +6 -4
  96. package/dist/runtime/server/routes/auth/user/user.get.js +21 -0
  97. package/dist/runtime/server/utils/event-context.d.ts +49 -0
  98. package/dist/runtime/server/utils/event-context.js +3 -0
  99. package/dist/runtime/server/utils/serverSession.d.ts +65 -0
  100. package/dist/runtime/server/utils/serverSession.js +44 -0
  101. package/dist/runtime/server/utils/session.d.ts +85 -0
  102. package/dist/runtime/server/utils/session.js +106 -0
  103. package/dist/runtime/server/utils/token-refresh.d.ts +42 -0
  104. package/dist/runtime/server/utils/token-refresh.js +65 -0
  105. package/dist/runtime/types/augments.d.ts +61 -0
  106. package/dist/runtime/types.d.ts +115 -38
  107. package/dist/runtime/utils/createRouteMatcher.d.ts +40 -0
  108. package/dist/runtime/utils/createRouteMatcher.js +7 -0
  109. package/dist/runtime/utils/index.d.ts +30 -0
  110. package/dist/runtime/utils/index.js +1 -0
  111. package/dist/runtime/utils/log.d.ts +44 -0
  112. package/dist/runtime/utils/log.js +25 -0
  113. package/dist/runtime/utils/url-validation.d.ts +49 -0
  114. package/dist/runtime/utils/url-validation.js +38 -0
  115. package/dist/types.d.mts +0 -2
  116. package/package.json +48 -23
  117. package/dist/runtime/composables/asgardeo/useAuth.js +0 -129
  118. package/dist/runtime/server/handler.js +0 -231
  119. package/dist/runtime/server/services/asgardeo/index.js +0 -18
@@ -0,0 +1,37 @@
1
+ import { generateSessionId } from "@asgardeo/node";
2
+ import { defineEventHandler, getQuery, sendRedirect, setCookie, createError } from "h3";
3
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
4
+ import { createTempSessionToken, getTempSessionCookieName, getTempSessionCookieOptions } from "../../../utils/session.js";
5
+ import { useRuntimeConfig } from "#imports";
6
+ export default defineEventHandler(async (event) => {
7
+ const client = AsgardeoNuxtClient.getInstance();
8
+ const config = useRuntimeConfig();
9
+ const sessionSecret = config.asgardeo?.sessionSecret;
10
+ const query = getQuery(event);
11
+ const returnTo = query["returnTo"];
12
+ const safeReturnTo = returnTo && returnTo.startsWith("/") && !returnTo.startsWith("//") ? returnTo : void 0;
13
+ const sessionId = generateSessionId();
14
+ const tempToken = await createTempSessionToken(sessionId, sessionSecret, safeReturnTo);
15
+ setCookie(event, getTempSessionCookieName(), tempToken, getTempSessionCookieOptions());
16
+ let authorizationUrl = null;
17
+ await client.signIn(
18
+ (url) => {
19
+ authorizationUrl = url;
20
+ },
21
+ sessionId,
22
+ void 0,
23
+ // no authorization code (initial redirect)
24
+ void 0,
25
+ // no session_state
26
+ void 0,
27
+ // no state
28
+ {}
29
+ );
30
+ if (!authorizationUrl) {
31
+ throw createError({
32
+ statusCode: 500,
33
+ statusMessage: "Failed to generate authorization URL."
34
+ });
35
+ }
36
+ return sendRedirect(event, authorizationUrl, 302);
37
+ });
@@ -0,0 +1,37 @@
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
+ * POST /api/auth/signin
20
+ *
21
+ * Handles embedded (app-native) sign-in flow steps.
22
+ *
23
+ * Request body:
24
+ * - `payload` — the embedded flow step payload (`EmbeddedSignInFlowHandleRequestPayload`).
25
+ * When omitted or `{}`, the flow is initialised and the authorize URL is returned.
26
+ * - `request` — optional per-step config (e.g. `{ url }` override).
27
+ *
28
+ * Response shape:
29
+ * ```json
30
+ * { "data": { ... }, "success": true }
31
+ * ```
32
+ */
33
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
34
+ data: unknown;
35
+ success: boolean;
36
+ }>>;
37
+ export default _default;
@@ -0,0 +1,102 @@
1
+ import { EmbeddedSignInFlowStatus, generateSessionId, isEmpty } from "@asgardeo/node";
2
+ import { defineEventHandler, readBody, getCookie, setCookie, deleteCookie, createError } from "h3";
3
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
4
+ import { useServerSession } from "../../../utils/serverSession.js";
5
+ import {
6
+ issueSessionCookie,
7
+ createTempSessionToken,
8
+ verifyTempSessionToken,
9
+ getTempSessionCookieName,
10
+ getTempSessionCookieOptions
11
+ } from "../../../utils/session.js";
12
+ import { useRuntimeConfig } from "#imports";
13
+ function isTokenResponse(value) {
14
+ return typeof value === "object" && value !== null && ("accessToken" in value || "idToken" in value || "refreshToken" in value);
15
+ }
16
+ export default defineEventHandler(async (event) => {
17
+ const config = useRuntimeConfig();
18
+ const sessionSecret = config.asgardeo?.sessionSecret;
19
+ const afterSignInUrl = config.public.asgardeo?.afterSignInUrl || "/";
20
+ const client = AsgardeoNuxtClient.getInstance();
21
+ let sessionId;
22
+ const liveSession = await useServerSession(event);
23
+ if (liveSession?.sessionId) {
24
+ sessionId = liveSession.sessionId;
25
+ } else {
26
+ const tempCookie = getCookie(event, getTempSessionCookieName());
27
+ if (tempCookie) {
28
+ try {
29
+ const tempSession = await verifyTempSessionToken(
30
+ tempCookie,
31
+ sessionSecret
32
+ );
33
+ sessionId = tempSession.sessionId;
34
+ } catch {
35
+ sessionId = generateSessionId();
36
+ }
37
+ } else {
38
+ sessionId = generateSessionId();
39
+ }
40
+ const tempToken = await createTempSessionToken(sessionId, sessionSecret);
41
+ setCookie(event, getTempSessionCookieName(), tempToken, getTempSessionCookieOptions());
42
+ }
43
+ const body = await readBody(event);
44
+ const payload = body?.payload ?? {};
45
+ const request = body?.request ?? {};
46
+ if (isEmpty(payload) || !("flowId" in payload)) {
47
+ try {
48
+ const signInUrl = await client.getAuthorizeRequestUrl(
49
+ { client_secret: "{{clientSecret}}", response_mode: "direct" },
50
+ sessionId
51
+ );
52
+ return { data: { signInUrl }, success: true };
53
+ } catch (err) {
54
+ throw createError({
55
+ statusCode: 500,
56
+ statusMessage: `Failed to build authorize URL: ${err?.message ?? String(err)}`
57
+ });
58
+ }
59
+ }
60
+ let response;
61
+ try {
62
+ response = await client.signIn(payload, request, sessionId);
63
+ } catch (err) {
64
+ throw createError({
65
+ statusCode: 502,
66
+ statusMessage: `Embedded sign-in step failed: ${err?.message ?? String(err)}`
67
+ });
68
+ }
69
+ if (response?.flowStatus === EmbeddedSignInFlowStatus.SuccessCompleted) {
70
+ const authData = response?.authData ?? {};
71
+ const { code, state, session_state: sessionState } = authData;
72
+ if (!code) {
73
+ throw createError({ statusCode: 502, statusMessage: "Authorization code missing from completed flow response." });
74
+ }
75
+ let tokenResponse;
76
+ try {
77
+ tokenResponse = await client.signIn({ code, session_state: sessionState, state }, {}, sessionId);
78
+ } catch (err) {
79
+ throw createError({
80
+ statusCode: 502,
81
+ statusMessage: `Token exchange failed after embedded flow: ${err?.message ?? String(err)}`
82
+ });
83
+ }
84
+ if (!isTokenResponse(tokenResponse)) {
85
+ throw createError({
86
+ statusCode: 502,
87
+ statusMessage: "Token exchange failed: Invalid token response from Identity Provider."
88
+ });
89
+ }
90
+ try {
91
+ await issueSessionCookie(event, sessionId, tokenResponse, sessionSecret);
92
+ deleteCookie(event, getTempSessionCookieName(), getTempSessionCookieOptions());
93
+ } catch (err) {
94
+ throw createError({
95
+ statusCode: 500,
96
+ statusMessage: `Failed to establish session: ${err?.message ?? String(err)}`
97
+ });
98
+ }
99
+ return { data: { afterSignInUrl }, success: true };
100
+ }
101
+ return { data: response, success: true };
102
+ });
@@ -0,0 +1,31 @@
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
+ * POST /api/auth/signout
20
+ *
21
+ * Signs the user out by:
22
+ * 1. Getting the sign-out URL from Asgardeo (for RP-Initiated Logout)
23
+ * 2. Clearing all session cookies
24
+ * 3. Returning `{ redirectUrl }` for the client to navigate to
25
+ *
26
+ * Using POST instead of GET prevents CSRF-based forced sign-outs.
27
+ */
28
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
29
+ redirectUrl: string;
30
+ }>>;
31
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { defineEventHandler, deleteCookie } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
4
+ import {
5
+ getSessionCookieName,
6
+ getSessionCookieOptions,
7
+ getTempSessionCookieName,
8
+ getTempSessionCookieOptions
9
+ } from "../../../utils/session.js";
10
+ import { useRuntimeConfig } from "#imports";
11
+ export default defineEventHandler(async (event) => {
12
+ const config = useRuntimeConfig();
13
+ const sessionSecret = config.asgardeo?.sessionSecret;
14
+ const publicConfig = config.public.asgardeo;
15
+ const fallbackUrl = publicConfig.afterSignOutUrl || "/";
16
+ const clearCookies = () => {
17
+ deleteCookie(event, getSessionCookieName(), getSessionCookieOptions());
18
+ deleteCookie(event, getTempSessionCookieName(), getTempSessionCookieOptions());
19
+ };
20
+ const session = await verifyAndRehydrateSession(
21
+ event,
22
+ sessionSecret
23
+ );
24
+ if (!session) {
25
+ clearCookies();
26
+ return { redirectUrl: fallbackUrl };
27
+ }
28
+ try {
29
+ const client = AsgardeoNuxtClient.getInstance();
30
+ const signOutUrl = await client.signOut(session.sessionId);
31
+ clearCookies();
32
+ return { redirectUrl: signOutUrl || fallbackUrl };
33
+ } catch (err) {
34
+ console.error("[asgardeo] Sign-out error:", err?.message || err);
35
+ clearCookies();
36
+ return { redirectUrl: fallbackUrl };
37
+ }
38
+ });
@@ -0,0 +1,36 @@
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
+ * POST /api/auth/signup
20
+ *
21
+ * Handles embedded (app-native) sign-up flow steps.
22
+ *
23
+ * Request body:
24
+ * - `payload` — the embedded sign-up flow step payload (`EmbeddedFlowExecuteRequestPayload`).
25
+ * When omitted, returns an empty `signUpUrl` (caller should redirect to the sign-up page).
26
+ *
27
+ * Response shape:
28
+ * ```json
29
+ * { "data": { ... }, "success": true }
30
+ * ```
31
+ */
32
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
33
+ data: unknown;
34
+ success: boolean;
35
+ }>>;
36
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { EmbeddedFlowStatus } from "@asgardeo/node";
2
+ import { defineEventHandler, readBody, createError } from "h3";
3
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
4
+ import { useRuntimeConfig } from "#imports";
5
+ function hasFlowStatus(value) {
6
+ return typeof value === "object" && value !== null && "flowStatus" in value;
7
+ }
8
+ export default defineEventHandler(async (event) => {
9
+ const config = useRuntimeConfig();
10
+ const afterSignUpUrl = config.public.asgardeo?.afterSignInUrl || "/";
11
+ const body = await readBody(event);
12
+ const payload = body?.payload;
13
+ if (!payload) {
14
+ return { data: { signUpUrl: "" }, success: true };
15
+ }
16
+ const client = AsgardeoNuxtClient.getInstance();
17
+ let response;
18
+ try {
19
+ response = await client.signUp(payload);
20
+ } catch (err) {
21
+ throw createError({
22
+ statusCode: 502,
23
+ statusMessage: `Embedded sign-up step failed: ${err?.message ?? String(err)}`
24
+ });
25
+ }
26
+ if (hasFlowStatus(response) && response.flowStatus === EmbeddedFlowStatus.Complete) {
27
+ return { data: { afterSignUpUrl }, success: true };
28
+ }
29
+ return { data: response, success: true };
30
+ });
@@ -0,0 +1,29 @@
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
+ * GET /api/auth/token
20
+ *
21
+ * Returns a valid access token for the current session.
22
+ * Proactively refreshes the token if it is within 60 seconds of expiry
23
+ * (requires a refresh token stored in the session JWT).
24
+ * Returns 401 if there is no active session or the token cannot be refreshed.
25
+ */
26
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
27
+ accessToken: string;
28
+ }>>;
29
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { getValidAccessToken } from "../../../utils/token-refresh.js";
3
+ export default defineEventHandler(async (event) => {
4
+ const accessToken = await getValidAccessToken(event);
5
+ return { accessToken };
6
+ });
@@ -0,0 +1,29 @@
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 { UserProfile } from '@asgardeo/node';
19
+ /**
20
+ * GET /api/auth/user/profile
21
+ *
22
+ * Returns the full SCIM2 {@link UserProfile} (with `flattenedProfile` and
23
+ * `schemas`) for the authenticated user. Used by `AsgardeoRoot.revalidateProfile`
24
+ * to refresh client-side state after a profile update.
25
+ *
26
+ * Mirrors `getUserProfileAction` in the Next.js SDK.
27
+ */
28
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<UserProfile>>;
29
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { defineEventHandler, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
4
+ import { useRuntimeConfig } from "#imports";
5
+ export default defineEventHandler(async (event) => {
6
+ const config = useRuntimeConfig();
7
+ const sessionSecret = config.asgardeo?.sessionSecret;
8
+ const session = await verifyAndRehydrateSession(
9
+ event,
10
+ sessionSecret
11
+ );
12
+ if (!session) {
13
+ throw createError({ statusCode: 401, statusMessage: "Unauthorized: Invalid or expired session." });
14
+ }
15
+ try {
16
+ const client = AsgardeoNuxtClient.getInstance();
17
+ return await client.getUserProfile(session.sessionId);
18
+ } catch (err) {
19
+ throw createError({
20
+ statusCode: 500,
21
+ statusMessage: `Failed to retrieve user profile: ${err instanceof Error ? err.message : String(err)}`
22
+ });
23
+ }
24
+ });
@@ -15,17 +15,21 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { type AuthClientConfig } from '@asgardeo/auth-node';
19
- import type { CookieSerializeOptions } from 'cookie-es';
20
- export interface AsgardeoAuthHandlerOptions {
21
- basePath?: string;
22
- cookies?: {
23
- defaultOptions?: CookieSerializeOptions;
24
- sessionId?: string;
25
- sessionIdOptions?: CookieSerializeOptions;
26
- state?: string;
27
- stateOptions?: CookieSerializeOptions;
18
+ import type { User } from '@asgardeo/node';
19
+ /**
20
+ * PATCH /api/auth/user/profile
21
+ *
22
+ * Updates the SCIM2 /Me profile for the authenticated user.
23
+ * Mirrors the `updateUserProfileAction` Next.js server action.
24
+ *
25
+ * Request body: {@link UpdateMeProfileConfig} (the SCIM patch payload).
26
+ * Response: `{ data: { user: User }; success: boolean; error: string }`
27
+ */
28
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
29
+ data: {
30
+ user: User;
28
31
  };
29
- defaultCallbackUrl?: string;
30
- }
31
- export declare const AsgardeoAuthHandler: (config: AuthClientConfig, options?: AsgardeoAuthHandlerOptions) => any;
32
+ error: string;
33
+ success: boolean;
34
+ }>>;
35
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { defineEventHandler, readBody, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
4
+ import { useRuntimeConfig } from "#imports";
5
+ export default defineEventHandler(
6
+ async (event) => {
7
+ const config = useRuntimeConfig();
8
+ const sessionSecret = config.asgardeo?.sessionSecret;
9
+ const session = await verifyAndRehydrateSession(
10
+ event,
11
+ sessionSecret
12
+ );
13
+ if (!session) {
14
+ throw createError({ statusCode: 401, statusMessage: "Unauthorized: Invalid or expired session." });
15
+ }
16
+ let payload;
17
+ try {
18
+ payload = await readBody(event);
19
+ } catch {
20
+ throw createError({ statusCode: 400, statusMessage: "Invalid request body." });
21
+ }
22
+ try {
23
+ const client = AsgardeoNuxtClient.getInstance();
24
+ const user = await client.updateUserProfile(payload, session.sessionId);
25
+ return { data: { user }, error: "", success: true };
26
+ } catch (err) {
27
+ throw createError({
28
+ statusCode: 500,
29
+ statusMessage: `Failed to update user profile: ${err instanceof Error ? err.message : String(err)}`
30
+ });
31
+ }
32
+ }
33
+ );
@@ -15,9 +15,11 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AsgardeoNodeClient, type AuthClientConfig } from '@asgardeo/auth-node';
19
18
  /**
20
- * Returns a singleton AsgardeoNodeClient instance.
21
- * Must be called with configuration on first call.
19
+ * GET /api/auth/user
20
+ *
21
+ * Returns user information for the current session.
22
+ * Requires a valid session.
22
23
  */
23
- export declare function getAsgardeoSdkInstance(config: AuthClientConfig): AsgardeoNodeClient<any>;
24
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("@asgardeo/javascript").User>>;
25
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineEventHandler, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
4
+ import { useRuntimeConfig } from "#imports";
5
+ export default defineEventHandler(async (event) => {
6
+ const config = useRuntimeConfig();
7
+ const sessionSecret = config.asgardeo?.sessionSecret;
8
+ const session = await verifyAndRehydrateSession(
9
+ event,
10
+ sessionSecret
11
+ );
12
+ if (!session) {
13
+ throw createError({ statusCode: 401, statusMessage: "Unauthorized: Invalid or expired session." });
14
+ }
15
+ try {
16
+ const client = AsgardeoNuxtClient.getInstance();
17
+ return await client.getUser(session.sessionId);
18
+ } catch {
19
+ throw createError({ statusCode: 500, statusMessage: "Failed to retrieve user information." });
20
+ }
21
+ });
@@ -0,0 +1,49 @@
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 { H3Event } from 'h3';
19
+ import type { AsgardeoSessionPayload, AsgardeoSSRData } from '../../types.js';
20
+ /**
21
+ * The typed shape of `event.context.asgardeo` set by the Asgardeo Nitro plugin
22
+ * on every SSR request.
23
+ */
24
+ export interface AsgardeoEventContext {
25
+ /** Convenience boolean derived from the session presence. */
26
+ isSignedIn: boolean;
27
+ /** The decoded session payload, or null when the user is not signed in. */
28
+ session: AsgardeoSessionPayload | null;
29
+ /** SSR-prefetched data (user profile, orgs, branding). Present only after the SSR plugin runs. */
30
+ ssr?: AsgardeoSSRData;
31
+ }
32
+ /**
33
+ * Typed accessor for `event.context.asgardeo`.
34
+ *
35
+ * Returns null when called before the Asgardeo SSR plugin has populated
36
+ * the context (e.g. in non-Nuxt Nitro routes that run before the plugin).
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { getAsgardeoContext } from '@asgardeo/nuxt/server';
41
+ *
42
+ * export default defineEventHandler((event) => {
43
+ * const ctx = getAsgardeoContext(event);
44
+ * if (!ctx?.isSignedIn) throw createError({ statusCode: 401 });
45
+ * return { userId: ctx.session!.sub };
46
+ * });
47
+ * ```
48
+ */
49
+ export declare function getAsgardeoContext(event: H3Event): AsgardeoEventContext | null;
@@ -0,0 +1,3 @@
1
+ export function getAsgardeoContext(event) {
2
+ return event.context.asgardeo ?? null;
3
+ }
@@ -0,0 +1,65 @@
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 { H3Event } from 'h3';
19
+ import type { AsgardeoSessionPayload } from '../../types.js';
20
+ /**
21
+ * Get the current session from the request cookie.
22
+ * Returns the session payload if valid, or null if no session exists.
23
+ *
24
+ * Use this in custom server API routes to access session data.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // server/api/me.get.ts
29
+ * export default defineEventHandler(async (event) => {
30
+ * const session = await useServerSession(event);
31
+ * if (!session) {
32
+ * throw createError({ statusCode: 401, statusMessage: 'Unauthorized' });
33
+ * }
34
+ * return { sessionId: session.sessionId, sub: session.sub };
35
+ * });
36
+ * ```
37
+ */
38
+ export declare function useServerSession(event: H3Event): Promise<AsgardeoSessionPayload | null>;
39
+ /**
40
+ * Get the current session or throw a 401 error.
41
+ * Use this when the route must be authenticated.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // server/api/protected-data.get.ts
46
+ * export default defineEventHandler(async (event) => {
47
+ * const session = await requireServerSession(event);
48
+ * // session is guaranteed to be non-null here
49
+ * return { userId: session.sub };
50
+ * });
51
+ * ```
52
+ */
53
+ export declare function requireServerSession(event: H3Event): Promise<AsgardeoSessionPayload>;
54
+ /**
55
+ * Verify the session cookie and rehydrate the legacy in-memory token store
56
+ * from its payload. Used internally by the SDK's SSR plugin and /api/auth/*
57
+ * routes so that subsequent calls which look up tokens by `sessionId`
58
+ * (`getAccessToken`, `getUser`, `getDecodedIdToken`, `signOut`) still succeed
59
+ * after a server restart, when the in-memory store is empty but the signed
60
+ * session cookie is still valid.
61
+ *
62
+ * Returns `null` for missing or invalid cookies — callers decide whether to
63
+ * 401 or silently treat the user as unauthenticated.
64
+ */
65
+ export declare function verifyAndRehydrateSession(event: H3Event, sessionSecret?: string): Promise<AsgardeoSessionPayload | null>;