@asgardeo/nuxt 0.0.0 → 0.1.0-alpha.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,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.getCurrentOrganization(session.sessionId);
18
+ } catch (err) {
19
+ throw createError({
20
+ statusCode: 500,
21
+ statusMessage: `Failed to retrieve current organisation: ${err instanceof Error ? err.message : String(err)}`
22
+ });
23
+ }
24
+ });
@@ -0,0 +1,28 @@
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 { OrganizationDetails } from '@asgardeo/node';
19
+ /**
20
+ * GET /api/auth/organizations/:id
21
+ *
22
+ * Returns the details of a single organisation by its ID.
23
+ * Requires an active session.
24
+ *
25
+ * Mirrors `getOrganizationAction` in the Next.js SDK.
26
+ */
27
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<OrganizationDetails>>;
28
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { defineEventHandler, getRouterParam, 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
+ const organizationId = getRouterParam(event, "id");
16
+ if (!organizationId) {
17
+ throw createError({ statusCode: 400, statusMessage: "Organization ID is required." });
18
+ }
19
+ try {
20
+ const client = AsgardeoNuxtClient.getInstance();
21
+ return await client.getOrganization(organizationId, session.sessionId);
22
+ } catch (err) {
23
+ throw createError({
24
+ statusCode: 500,
25
+ statusMessage: `Failed to retrieve organisation: ${err instanceof Error ? err.message : String(err)}`
26
+ });
27
+ }
28
+ });
@@ -0,0 +1,28 @@
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 { AllOrganizationsApiResponse } from '@asgardeo/node';
19
+ /**
20
+ * GET /api/auth/organizations
21
+ *
22
+ * Returns all organisations accessible to the authenticated user (paginated).
23
+ * Used by `AsgardeoRoot.getAllOrganizations` callback.
24
+ *
25
+ * Mirrors `getAllOrganizations` server action in the Next.js SDK.
26
+ */
27
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<AllOrganizationsApiResponse>>;
28
+ 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.getAllOrganizations(void 0, session.sessionId);
18
+ } catch (err) {
19
+ throw createError({
20
+ statusCode: 500,
21
+ statusMessage: `Failed to retrieve all organisations: ${err instanceof Error ? err.message : String(err)}`
22
+ });
23
+ }
24
+ });
@@ -0,0 +1,30 @@
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 { Organization } from '@asgardeo/node';
19
+ /**
20
+ * POST /api/auth/organizations
21
+ *
22
+ * Creates a new sub-organisation under the authenticated user's root organisation.
23
+ *
24
+ * Request body: {@link CreateOrganizationPayload}
25
+ * Response: {@link Organization}
26
+ *
27
+ * Mirrors `createOrganization` server action in the Next.js SDK.
28
+ */
29
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Organization>>;
30
+ export default _default;
@@ -0,0 +1,30 @@
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(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
+ let payload;
16
+ try {
17
+ payload = await readBody(event);
18
+ } catch {
19
+ throw createError({ statusCode: 400, statusMessage: "Invalid request body." });
20
+ }
21
+ try {
22
+ const client = AsgardeoNuxtClient.getInstance();
23
+ return await client.createOrganization(payload, session.sessionId);
24
+ } catch (err) {
25
+ throw createError({
26
+ statusCode: 500,
27
+ statusMessage: `Failed to create organisation: ${err instanceof Error ? err.message : String(err)}`
28
+ });
29
+ }
30
+ });
@@ -0,0 +1,28 @@
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 { Organization } from '@asgardeo/node';
19
+ /**
20
+ * GET /api/auth/organizations/me
21
+ *
22
+ * Returns the list of organisations the authenticated user is a member of.
23
+ * Used by `AsgardeoRoot.revalidateMyOrganizations` to refresh client-side state.
24
+ *
25
+ * Mirrors `getMyOrganizations` server action in the Next.js SDK.
26
+ */
27
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Organization[]>>;
28
+ 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.getMyOrganizations(session.sessionId);
18
+ } catch (err) {
19
+ throw createError({
20
+ statusCode: 500,
21
+ statusMessage: `Failed to retrieve organisations: ${err instanceof Error ? err.message : String(err)}`
22
+ });
23
+ }
24
+ });
@@ -0,0 +1,32 @@
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/organizations/switch
20
+ *
21
+ * Performs an `organization_switch` token exchange for the given organisation,
22
+ * then re-issues the JWT session cookie so subsequent requests carry the new
23
+ * organisation context.
24
+ *
25
+ * Request body: `{ organization: Organization }`
26
+ *
27
+ * Mirrors `switchOrganization` server action in the Next.js SDK.
28
+ */
29
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
30
+ success: boolean;
31
+ }>>;
32
+ export default _default;
@@ -0,0 +1,49 @@
1
+ import { defineEventHandler, readBody, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import { verifyAndRehydrateSession } from "../../../utils/serverSession.js";
4
+ import { issueSessionCookie } from "../../../utils/session.js";
5
+ import { useRuntimeConfig } from "#imports";
6
+ export default defineEventHandler(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
+ const { sessionId } = session;
17
+ let organization;
18
+ try {
19
+ const body = await readBody(event);
20
+ organization = body.organization;
21
+ } catch {
22
+ throw createError({ statusCode: 400, statusMessage: "Invalid request body." });
23
+ }
24
+ if (!organization?.id) {
25
+ throw createError({ statusCode: 400, statusMessage: "organization.id is required." });
26
+ }
27
+ let tokenResponse;
28
+ try {
29
+ const client = AsgardeoNuxtClient.getInstance();
30
+ const response = await client.switchOrganization(organization, sessionId);
31
+ tokenResponse = response;
32
+ } catch (err) {
33
+ throw createError({
34
+ statusCode: 500,
35
+ statusMessage: `Organisation switch failed: ${err instanceof Error ? err.message : String(err)}`
36
+ });
37
+ }
38
+ try {
39
+ const runtimeConfig = useRuntimeConfig();
40
+ const runtimeSessionSecret = runtimeConfig.asgardeo?.sessionSecret;
41
+ await issueSessionCookie(event, sessionId, tokenResponse, runtimeSessionSecret);
42
+ } catch (err) {
43
+ throw createError({
44
+ statusCode: 500,
45
+ statusMessage: `Failed to establish new session after organisation switch: ${err instanceof Error ? err.message : String(err)}`
46
+ });
47
+ }
48
+ return { success: true };
49
+ });
@@ -0,0 +1,27 @@
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/callback
20
+ *
21
+ * Handles the OAuth2 callback from Asgardeo.
22
+ * Exchanges the authorization code for tokens,
23
+ * creates a signed session JWT cookie,
24
+ * and redirects to afterSignInUrl.
25
+ */
26
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
27
+ export default _default;
@@ -0,0 +1,91 @@
1
+ import { defineEventHandler, getQuery, getCookie, deleteCookie, sendRedirect, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import {
4
+ issueSessionCookie,
5
+ verifyTempSessionToken,
6
+ getTempSessionCookieName,
7
+ getTempSessionCookieOptions
8
+ } from "../../../utils/session.js";
9
+ import { useRuntimeConfig } from "#imports";
10
+ export default defineEventHandler(async (event) => {
11
+ const config = useRuntimeConfig();
12
+ const sessionSecret = config.asgardeo?.sessionSecret;
13
+ const publicConfig = config.public.asgardeo;
14
+ const query = getQuery(event);
15
+ const code = query["code"];
16
+ const state = query["state"];
17
+ const sessionState = query["session_state"];
18
+ const error = query["error"];
19
+ const errorDescription = query["error_description"];
20
+ if (error) {
21
+ throw createError({
22
+ statusCode: 400,
23
+ statusMessage: `Authentication failed: ${errorDescription || error}`
24
+ });
25
+ }
26
+ if (!code || !state) {
27
+ throw createError({
28
+ statusCode: 400,
29
+ statusMessage: "Missing required OAuth parameters: code and state are required."
30
+ });
31
+ }
32
+ const tempSessionCookie = getCookie(event, getTempSessionCookieName());
33
+ if (!tempSessionCookie) {
34
+ throw createError({
35
+ statusCode: 400,
36
+ statusMessage: "No temporary session found. Please start the sign-in flow again."
37
+ });
38
+ }
39
+ let sessionId;
40
+ let returnTo;
41
+ try {
42
+ const tempSession = await verifyTempSessionToken(
43
+ tempSessionCookie,
44
+ sessionSecret
45
+ );
46
+ sessionId = tempSession.sessionId;
47
+ returnTo = tempSession.returnTo;
48
+ } catch {
49
+ throw createError({
50
+ statusCode: 400,
51
+ statusMessage: "Invalid or expired temporary session. Please start the sign-in flow again."
52
+ });
53
+ }
54
+ const client = AsgardeoNuxtClient.getInstance();
55
+ let tokenResponse;
56
+ try {
57
+ tokenResponse = await client.signIn(
58
+ () => {
59
+ },
60
+ // no-op redirect callback (we're handling the code exchange)
61
+ sessionId,
62
+ code,
63
+ sessionState || "",
64
+ state
65
+ );
66
+ } catch (err) {
67
+ throw createError({
68
+ data: err?.message || "An unexpected error occurred during token exchange.",
69
+ statusCode: 500,
70
+ statusMessage: "Token exchange failed."
71
+ });
72
+ }
73
+ if (!tokenResponse?.accessToken && !tokenResponse?.idToken) {
74
+ throw createError({
75
+ statusCode: 500,
76
+ statusMessage: "Token exchange failed: Invalid response from Identity Provider."
77
+ });
78
+ }
79
+ try {
80
+ await issueSessionCookie(event, sessionId, tokenResponse, sessionSecret);
81
+ deleteCookie(event, getTempSessionCookieName(), getTempSessionCookieOptions());
82
+ } catch (err) {
83
+ console.error("[asgardeo] Failed to create JWT session:", err?.message || err);
84
+ throw createError({
85
+ statusCode: 500,
86
+ statusMessage: "Failed to establish session after authentication."
87
+ });
88
+ }
89
+ const redirectUrl = returnTo || publicConfig.afterSignInUrl || "/";
90
+ return sendRedirect(event, redirectUrl, 302);
91
+ });
@@ -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
+ * POST /api/auth/callback
20
+ *
21
+ * Exchanges an authorization code for tokens and issues a session cookie.
22
+ * Called by the client-side `AsgardeoCallback` component after the IDP
23
+ * redirects back with `?code=...&state=...`.
24
+ *
25
+ * Request body:
26
+ * - `code` — authorization code from the IDP redirect
27
+ * - `state` — state parameter from the redirect
28
+ * - `sessionState` — session_state parameter from the redirect (optional)
29
+ *
30
+ * Response shape (success):
31
+ * ```json
32
+ * { "redirectUrl": "/dashboard", "success": true }
33
+ * ```
34
+ * Response shape (error):
35
+ * ```json
36
+ * { "success": false, "error": "..." }
37
+ * ```
38
+ */
39
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
40
+ error: any;
41
+ success: boolean;
42
+ redirectUrl?: undefined;
43
+ } | {
44
+ redirectUrl: string;
45
+ success: boolean;
46
+ error?: undefined;
47
+ }>>;
48
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { defineEventHandler, readBody, getCookie, deleteCookie, createError } from "h3";
2
+ import AsgardeoNuxtClient from "../../../AsgardeoNuxtClient.js";
3
+ import {
4
+ issueSessionCookie,
5
+ verifyTempSessionToken,
6
+ getTempSessionCookieName,
7
+ getTempSessionCookieOptions
8
+ } from "../../../utils/session.js";
9
+ import { useRuntimeConfig } from "#imports";
10
+ function isTokenResponse(value) {
11
+ return typeof value === "object" && value !== null && ("accessToken" in value || "idToken" in value || "refreshToken" in value);
12
+ }
13
+ export default defineEventHandler(async (event) => {
14
+ const config = useRuntimeConfig();
15
+ const sessionSecret = config.asgardeo?.sessionSecret;
16
+ const afterSignInUrl = config.public.asgardeo?.afterSignInUrl || "/";
17
+ const body = await readBody(event);
18
+ const { code, state, sessionState } = body ?? {};
19
+ if (!code) {
20
+ throw createError({ statusCode: 400, statusMessage: "Missing required parameter: code" });
21
+ }
22
+ const tempCookie = getCookie(event, getTempSessionCookieName());
23
+ if (!tempCookie) {
24
+ throw createError({ statusCode: 400, statusMessage: "No active auth session found. Please restart sign-in." });
25
+ }
26
+ let sessionId;
27
+ try {
28
+ const tempSession = await verifyTempSessionToken(
29
+ tempCookie,
30
+ sessionSecret
31
+ );
32
+ sessionId = tempSession.sessionId;
33
+ } catch {
34
+ throw createError({ statusCode: 400, statusMessage: "Auth session expired or invalid. Please restart sign-in." });
35
+ }
36
+ const client = AsgardeoNuxtClient.getInstance();
37
+ let tokenResponse;
38
+ try {
39
+ tokenResponse = await client.signIn({ code, session_state: sessionState, state }, {}, sessionId);
40
+ } catch (err) {
41
+ return { error: err?.message ?? String(err), success: false };
42
+ }
43
+ if (!isTokenResponse(tokenResponse)) {
44
+ return { error: "Invalid token response from Identity Provider.", success: false };
45
+ }
46
+ try {
47
+ await issueSessionCookie(event, sessionId, tokenResponse, sessionSecret);
48
+ deleteCookie(event, getTempSessionCookieName(), getTempSessionCookieOptions());
49
+ } catch (err) {
50
+ return { error: `Failed to establish session: ${err?.message ?? String(err)}`, success: false };
51
+ }
52
+ return { redirectUrl: afterSignInUrl, success: true };
53
+ });
@@ -0,0 +1,26 @@
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 { AsgardeoAuthState } from '../../../../types.js';
19
+ /**
20
+ * GET /api/auth/session
21
+ *
22
+ * Returns the current auth state: { isSignedIn, user, isLoading }.
23
+ * Used by the client-side composable to hydrate auth state.
24
+ */
25
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<AsgardeoAuthState>>;
26
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import { defineEventHandler } 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
+ return { isLoading: false, isSignedIn: false, user: null };
14
+ }
15
+ try {
16
+ const client = AsgardeoNuxtClient.getInstance();
17
+ const user = await client.getUser(session.sessionId);
18
+ return { isLoading: false, isSignedIn: true, user };
19
+ } catch {
20
+ return { isLoading: false, isSignedIn: false, user: null };
21
+ }
22
+ });
@@ -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/signin
20
+ *
21
+ * Initiates the OAuth2 authorization code flow with PKCE.
22
+ * Creates a temp session, stores it in a signed JWT cookie,
23
+ * and redirects the user to Asgardeo's authorization endpoint.
24
+ *
25
+ * Accepts an optional `returnTo` query parameter to redirect
26
+ * the user to a specific page after sign-in.
27
+ */
28
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
29
+ export default _default;