@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.
- package/README.md +482 -6
- package/dist/module.d.mts +17 -24
- package/dist/module.json +2 -2
- package/dist/module.mjs +174 -48
- package/dist/runtime/components/AsgardeoRoot.d.ts +52 -0
- package/dist/runtime/components/AsgardeoRoot.js +160 -0
- package/dist/runtime/components/actions/SignInButton.d.ts +37 -0
- package/dist/runtime/components/actions/SignInButton.js +51 -0
- package/dist/runtime/components/actions/SignOutButton.d.ts +34 -0
- package/dist/runtime/components/actions/SignOutButton.js +43 -0
- package/dist/runtime/components/actions/SignUpButton.d.ts +33 -0
- package/dist/runtime/components/actions/SignUpButton.js +48 -0
- package/dist/runtime/components/auth/Callback.d.ts +43 -0
- package/dist/runtime/components/auth/Callback.js +93 -0
- package/dist/runtime/components/auth/SignIn.d.ts +38 -0
- package/dist/runtime/components/auth/SignIn.js +60 -0
- package/dist/runtime/components/auth/SignUp.d.ts +40 -0
- package/dist/runtime/components/auth/SignUp.js +79 -0
- package/dist/runtime/components/control/Loading.d.ts +36 -0
- package/dist/runtime/components/control/Loading.js +17 -0
- package/dist/runtime/components/control/SignedIn.d.ts +38 -0
- package/dist/runtime/components/control/SignedIn.js +17 -0
- package/dist/runtime/components/control/SignedOut.d.ts +37 -0
- package/dist/runtime/components/control/SignedOut.js +17 -0
- package/dist/runtime/components/organization/CreateOrganization.d.ts +32 -0
- package/dist/runtime/components/organization/CreateOrganization.js +29 -0
- package/dist/runtime/components/organization/Organization.d.ts +39 -0
- package/dist/runtime/components/organization/Organization.js +17 -0
- package/dist/runtime/components/organization/OrganizationList.d.ts +34 -0
- package/dist/runtime/components/organization/OrganizationList.js +30 -0
- package/dist/runtime/components/organization/OrganizationProfile.d.ts +32 -0
- package/dist/runtime/components/organization/OrganizationProfile.js +32 -0
- package/dist/runtime/components/organization/OrganizationSwitcher.d.ts +36 -0
- package/dist/runtime/components/organization/OrganizationSwitcher.js +26 -0
- package/dist/runtime/components/user/User.d.ts +38 -0
- package/dist/runtime/components/user/User.js +17 -0
- package/dist/runtime/components/user/UserDropdown.d.ts +38 -0
- package/dist/runtime/components/user/UserDropdown.js +45 -0
- package/dist/runtime/components/user/UserProfile.d.ts +35 -0
- package/dist/runtime/components/user/UserProfile.js +35 -0
- package/dist/runtime/composables/useAsgardeo.d.ts +38 -0
- package/dist/runtime/composables/useAsgardeo.js +73 -0
- package/dist/runtime/errors/asgardeo-error.d.ts +47 -0
- package/dist/runtime/errors/asgardeo-error.js +15 -0
- package/dist/runtime/errors/error-codes.d.ts +40 -0
- package/dist/runtime/errors/error-codes.js +19 -0
- package/dist/runtime/{composables/asgardeo/useAuth.d.ts → errors/index.d.ts} +2 -2
- package/dist/runtime/errors/index.js +2 -0
- package/dist/runtime/middleware/auth.d.ts +35 -0
- package/dist/runtime/middleware/auth.js +2 -0
- package/dist/runtime/middleware/defineAsgardeoMiddleware.d.ts +53 -0
- package/dist/runtime/middleware/defineAsgardeoMiddleware.js +24 -0
- package/dist/runtime/plugins/asgardeo.d.ts +40 -0
- package/dist/runtime/plugins/asgardeo.js +129 -0
- package/dist/runtime/server/AsgardeoNuxtClient.d.ts +182 -0
- package/dist/runtime/server/AsgardeoNuxtClient.js +366 -0
- package/dist/runtime/server/index.d.ts +33 -0
- package/dist/runtime/server/index.js +3 -0
- package/dist/runtime/server/plugins/asgardeo-ssr.d.ts +41 -0
- package/dist/runtime/server/plugins/asgardeo-ssr.js +134 -0
- package/dist/runtime/server/routes/auth/branding/branding.get.d.ts +31 -0
- package/dist/runtime/server/routes/auth/branding/branding.get.js +40 -0
- package/dist/runtime/server/routes/auth/organizations/current.get.d.ts +29 -0
- package/dist/runtime/server/routes/auth/organizations/current.get.js +24 -0
- package/dist/runtime/server/routes/auth/organizations/id.get.d.ts +28 -0
- package/dist/runtime/server/routes/auth/organizations/id.get.js +28 -0
- package/dist/runtime/server/routes/auth/organizations/index.get.d.ts +28 -0
- package/dist/runtime/server/routes/auth/organizations/index.get.js +24 -0
- package/dist/runtime/server/routes/auth/organizations/index.post.d.ts +30 -0
- package/dist/runtime/server/routes/auth/organizations/index.post.js +30 -0
- package/dist/runtime/server/routes/auth/organizations/me.get.d.ts +28 -0
- package/dist/runtime/server/routes/auth/organizations/me.get.js +24 -0
- package/dist/runtime/server/routes/auth/organizations/switch.post.d.ts +32 -0
- package/dist/runtime/server/routes/auth/organizations/switch.post.js +49 -0
- package/dist/runtime/server/routes/auth/session/callback.get.d.ts +27 -0
- package/dist/runtime/server/routes/auth/session/callback.get.js +91 -0
- package/dist/runtime/server/routes/auth/session/callback.post.d.ts +48 -0
- package/dist/runtime/server/routes/auth/session/callback.post.js +53 -0
- package/dist/runtime/server/routes/auth/session/session.get.d.ts +26 -0
- package/dist/runtime/server/routes/auth/session/session.get.js +22 -0
- package/dist/runtime/server/routes/auth/session/signin.get.d.ts +29 -0
- package/dist/runtime/server/routes/auth/session/signin.get.js +37 -0
- package/dist/runtime/server/routes/auth/session/signin.post.d.ts +37 -0
- package/dist/runtime/server/routes/auth/session/signin.post.js +102 -0
- package/dist/runtime/server/routes/auth/session/signout.post.d.ts +31 -0
- package/dist/runtime/server/routes/auth/session/signout.post.js +38 -0
- package/dist/runtime/server/routes/auth/session/signup.post.d.ts +36 -0
- package/dist/runtime/server/routes/auth/session/signup.post.js +30 -0
- package/dist/runtime/server/routes/auth/session/token.get.d.ts +29 -0
- package/dist/runtime/server/routes/auth/session/token.get.js +6 -0
- package/dist/runtime/server/routes/auth/user/profile.get.d.ts +29 -0
- package/dist/runtime/server/routes/auth/user/profile.get.js +24 -0
- package/dist/runtime/server/{handler.d.ts → routes/auth/user/profile.patch.d.ts} +17 -13
- package/dist/runtime/server/routes/auth/user/profile.patch.js +33 -0
- package/dist/runtime/server/{services/asgardeo/index.d.ts → routes/auth/user/user.get.d.ts} +6 -4
- package/dist/runtime/server/routes/auth/user/user.get.js +21 -0
- package/dist/runtime/server/utils/event-context.d.ts +49 -0
- package/dist/runtime/server/utils/event-context.js +3 -0
- package/dist/runtime/server/utils/serverSession.d.ts +65 -0
- package/dist/runtime/server/utils/serverSession.js +44 -0
- package/dist/runtime/server/utils/session.d.ts +85 -0
- package/dist/runtime/server/utils/session.js +106 -0
- package/dist/runtime/server/utils/token-refresh.d.ts +42 -0
- package/dist/runtime/server/utils/token-refresh.js +65 -0
- package/dist/runtime/types/augments.d.ts +61 -0
- package/dist/runtime/types.d.ts +115 -38
- package/dist/runtime/utils/createRouteMatcher.d.ts +40 -0
- package/dist/runtime/utils/createRouteMatcher.js +7 -0
- package/dist/runtime/utils/index.d.ts +30 -0
- package/dist/runtime/utils/index.js +1 -0
- package/dist/runtime/utils/log.d.ts +44 -0
- package/dist/runtime/utils/log.js +25 -0
- package/dist/runtime/utils/url-validation.d.ts +49 -0
- package/dist/runtime/utils/url-validation.js +38 -0
- package/dist/types.d.mts +0 -2
- package/package.json +48 -23
- package/dist/runtime/composables/asgardeo/useAuth.js +0 -129
- package/dist/runtime/server/handler.js +0 -231
- package/dist/runtime/server/services/asgardeo/index.js +0 -18
package/dist/module.mjs
CHANGED
|
@@ -1,67 +1,193 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addImports,
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addServerPlugin, addPlugin, addRouteMiddleware, addImports, addComponent } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const PACKAGE_NAME = "@asgardeo/nuxt";
|
|
5
5
|
const module = defineNuxtModule({
|
|
6
|
-
defaults: {
|
|
7
|
-
baseUrl: process.env.ASGARDEO_BASE_URL || "",
|
|
8
|
-
clientID: process.env.ASGARDEO_CLIENT_ID || "",
|
|
9
|
-
clientSecret: process.env.ASGARDEO_CLIENT_SECRET || "",
|
|
10
|
-
scope: ["openid", "profile"],
|
|
11
|
-
signInRedirectURL: process.env.ASGARDEO_SIGN_IN_REDIRECT_URL || "",
|
|
12
|
-
signOutRedirectURL: process.env.ASGARDEO_SIGN_OUT_REDIRECT_URL || ""
|
|
13
|
-
},
|
|
6
|
+
defaults: {},
|
|
14
7
|
meta: {
|
|
15
|
-
configKey: "
|
|
8
|
+
configKey: "asgardeo",
|
|
16
9
|
name: PACKAGE_NAME
|
|
17
10
|
},
|
|
18
11
|
setup(userOptions, nuxt) {
|
|
19
|
-
const
|
|
12
|
+
const { resolve } = createResolver(import.meta.url);
|
|
13
|
+
const publicConfig = defu(
|
|
14
|
+
// Layer 1: environment variables — only win when actually set
|
|
15
|
+
{
|
|
16
|
+
afterSignInUrl: process.env["NUXT_PUBLIC_ASGARDEO_AFTER_SIGN_IN_URL"],
|
|
17
|
+
afterSignOutUrl: process.env["NUXT_PUBLIC_ASGARDEO_AFTER_SIGN_OUT_URL"],
|
|
18
|
+
applicationId: process.env["NUXT_PUBLIC_ASGARDEO_APPLICATION_ID"],
|
|
19
|
+
baseUrl: process.env["NUXT_PUBLIC_ASGARDEO_BASE_URL"],
|
|
20
|
+
clientId: process.env["NUXT_PUBLIC_ASGARDEO_CLIENT_ID"],
|
|
21
|
+
signInUrl: process.env["NUXT_PUBLIC_ASGARDEO_SIGN_IN_URL"],
|
|
22
|
+
signUpUrl: process.env["NUXT_PUBLIC_ASGARDEO_SIGN_UP_URL"]
|
|
23
|
+
},
|
|
24
|
+
// Layer 2: nuxt.config.ts options
|
|
20
25
|
userOptions,
|
|
21
|
-
|
|
22
|
-
nuxt.options.runtimeConfig.public.asgardeoAuth,
|
|
26
|
+
// Layer 3: hard defaults
|
|
23
27
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
scope: ["openid", "profile"],
|
|
28
|
-
serverOrigin: process.env.ASGARDEO_BASE_URL,
|
|
29
|
-
signInRedirectURL: process.env.ASGARDEO_SIGN_IN_REDIRECT_URL || "",
|
|
30
|
-
signOutRedirectURL: process.env.ASGARDEO_SIGN_OUT_REDIRECT_URL || ""
|
|
28
|
+
afterSignInUrl: "/",
|
|
29
|
+
afterSignOutUrl: "/",
|
|
30
|
+
scopes: ["openid", "profile"]
|
|
31
31
|
}
|
|
32
32
|
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const { resolve } = createResolver(import.meta.url);
|
|
45
|
-
const runtimeDir = resolve("./runtime");
|
|
46
|
-
const runtimeServerDir = resolve("./runtime/server");
|
|
47
|
-
addImports({
|
|
48
|
-
from: resolve(runtimeDir, "composables/asgardeo/useAuth"),
|
|
49
|
-
name: "useAuth"
|
|
50
|
-
});
|
|
51
|
-
addServerImports([
|
|
33
|
+
const privateConfig = {
|
|
34
|
+
clientSecret: process.env["ASGARDEO_CLIENT_SECRET"] || userOptions.clientSecret || "",
|
|
35
|
+
sessionSecret: process.env["ASGARDEO_SESSION_SECRET"] || userOptions.sessionSecret || ""
|
|
36
|
+
};
|
|
37
|
+
const { options } = nuxt;
|
|
38
|
+
options.runtimeConfig.asgardeo = defu(
|
|
39
|
+
options.runtimeConfig.asgardeo || {},
|
|
40
|
+
privateConfig
|
|
41
|
+
);
|
|
42
|
+
options.runtimeConfig.public.asgardeo = defu(
|
|
43
|
+
options.runtimeConfig.public.asgardeo || {},
|
|
52
44
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
afterSignInUrl: publicConfig.afterSignInUrl,
|
|
46
|
+
afterSignOutUrl: publicConfig.afterSignOutUrl,
|
|
47
|
+
applicationId: publicConfig.applicationId,
|
|
48
|
+
baseUrl: publicConfig.baseUrl,
|
|
49
|
+
clientId: publicConfig.clientId,
|
|
50
|
+
preferences: publicConfig.preferences,
|
|
51
|
+
scopes: publicConfig.scopes,
|
|
52
|
+
signInUrl: publicConfig.signInUrl,
|
|
53
|
+
signUpUrl: publicConfig.signUpUrl
|
|
56
54
|
}
|
|
55
|
+
);
|
|
56
|
+
const publicAsgardeo = options.runtimeConfig.public.asgardeo;
|
|
57
|
+
if (publicAsgardeo?.["clientSecret"]) {
|
|
58
|
+
delete publicAsgardeo["clientSecret"];
|
|
59
|
+
console.error(
|
|
60
|
+
`[${PACKAGE_NAME}] SECURITY: clientSecret found in public config. Removed. Use ASGARDEO_CLIENT_SECRET env var.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (publicAsgardeo?.["sessionSecret"]) {
|
|
64
|
+
delete publicAsgardeo["sessionSecret"];
|
|
65
|
+
console.error(
|
|
66
|
+
`[${PACKAGE_NAME}] SECURITY: sessionSecret found in public config. Removed. Use ASGARDEO_SESSION_SECRET env var.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const serverRoutes = [
|
|
70
|
+
// ── Auth flow ──────────────────────────────────────────────────────
|
|
71
|
+
{ handler: resolve("./runtime/server/routes/auth/session/signin.get"), route: "/api/auth/signin" },
|
|
72
|
+
{
|
|
73
|
+
handler: resolve("./runtime/server/routes/auth/session/signin.post"),
|
|
74
|
+
method: "post",
|
|
75
|
+
route: "/api/auth/signin"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
handler: resolve("./runtime/server/routes/auth/session/signup.post"),
|
|
79
|
+
method: "post",
|
|
80
|
+
route: "/api/auth/signup"
|
|
81
|
+
},
|
|
82
|
+
{ handler: resolve("./runtime/server/routes/auth/session/callback.get"), route: "/api/auth/callback" },
|
|
83
|
+
{
|
|
84
|
+
handler: resolve("./runtime/server/routes/auth/session/callback.post"),
|
|
85
|
+
method: "post",
|
|
86
|
+
route: "/api/auth/callback"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
handler: resolve("./runtime/server/routes/auth/session/signout.post"),
|
|
90
|
+
method: "post",
|
|
91
|
+
route: "/api/auth/signout"
|
|
92
|
+
},
|
|
93
|
+
// ── Session / token ───────────────────────────────────────────────
|
|
94
|
+
{ handler: resolve("./runtime/server/routes/auth/session/session.get"), route: "/api/auth/session" },
|
|
95
|
+
{ handler: resolve("./runtime/server/routes/auth/session/token.get"), route: "/api/auth/token" },
|
|
96
|
+
// ── User ──────────────────────────────────────────────────────────
|
|
97
|
+
{ handler: resolve("./runtime/server/routes/auth/user/user.get"), route: "/api/auth/user" },
|
|
98
|
+
{ handler: resolve("./runtime/server/routes/auth/user/profile.get"), route: "/api/auth/user/profile" },
|
|
99
|
+
{
|
|
100
|
+
handler: resolve("./runtime/server/routes/auth/user/profile.patch"),
|
|
101
|
+
method: "patch",
|
|
102
|
+
route: "/api/auth/user/profile"
|
|
103
|
+
},
|
|
104
|
+
// ── Organisations ─────────────────────────────────────────────────
|
|
105
|
+
{
|
|
106
|
+
handler: resolve("./runtime/server/routes/auth/organizations/index.get"),
|
|
107
|
+
route: "/api/auth/organizations"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
handler: resolve("./runtime/server/routes/auth/organizations/index.post"),
|
|
111
|
+
method: "post",
|
|
112
|
+
route: "/api/auth/organizations"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
handler: resolve("./runtime/server/routes/auth/organizations/me.get"),
|
|
116
|
+
route: "/api/auth/organizations/me"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
handler: resolve("./runtime/server/routes/auth/organizations/current.get"),
|
|
120
|
+
route: "/api/auth/organizations/current"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
handler: resolve("./runtime/server/routes/auth/organizations/id.get"),
|
|
124
|
+
route: "/api/auth/organizations/:id"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
handler: resolve("./runtime/server/routes/auth/organizations/switch.post"),
|
|
128
|
+
method: "post",
|
|
129
|
+
route: "/api/auth/organizations/switch"
|
|
130
|
+
},
|
|
131
|
+
// ── Branding ──────────────────────────────────────────────────────
|
|
132
|
+
{ handler: resolve("./runtime/server/routes/auth/branding/branding.get"), route: "/api/auth/branding" }
|
|
133
|
+
];
|
|
134
|
+
serverRoutes.forEach((sr) => {
|
|
135
|
+
addServerHandler({ handler: sr.handler, method: "method" in sr ? sr.method : void 0, route: sr.route });
|
|
136
|
+
});
|
|
137
|
+
addServerPlugin(resolve("./runtime/server/plugins/asgardeo-ssr"));
|
|
138
|
+
addPlugin(resolve("./runtime/plugins/asgardeo"));
|
|
139
|
+
addRouteMiddleware({
|
|
140
|
+
name: "auth",
|
|
141
|
+
path: resolve("./runtime/middleware/auth")
|
|
142
|
+
});
|
|
143
|
+
addImports([
|
|
144
|
+
// Core auth composable (Nuxt-specific wrapper around @asgardeo/vue)
|
|
145
|
+
{ from: resolve("./runtime/composables/useAsgardeo"), name: "useAsgardeo" },
|
|
146
|
+
// Composables from @asgardeo/vue — auto-imported directly, no local wrappers
|
|
147
|
+
{ from: "@asgardeo/vue", name: "useUser" },
|
|
148
|
+
{ from: "@asgardeo/vue", name: "useOrganization" },
|
|
149
|
+
{ from: "@asgardeo/vue", name: "useFlow" },
|
|
150
|
+
{ from: "@asgardeo/vue", name: "useFlowMeta" },
|
|
151
|
+
{ from: "@asgardeo/vue", name: "useTheme" },
|
|
152
|
+
{ from: "@asgardeo/vue", name: "useBranding" },
|
|
153
|
+
// useI18n aliased to `useAsgardeoI18n` to avoid collision with @nuxtjs/i18n
|
|
154
|
+
{ as: "useAsgardeoI18n", from: "@asgardeo/vue", name: "useI18n" },
|
|
155
|
+
// Middleware factory
|
|
156
|
+
{ from: resolve("./runtime/middleware/defineAsgardeoMiddleware"), name: "defineAsgardeoMiddleware" }
|
|
57
157
|
]);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
158
|
+
addComponent({
|
|
159
|
+
filePath: resolve("./runtime/components/AsgardeoRoot"),
|
|
160
|
+
name: "AsgardeoRoot"
|
|
161
|
+
});
|
|
162
|
+
addComponent({ filePath: resolve("./runtime/components/control/SignedIn"), name: "AsgardeoSignedIn" });
|
|
163
|
+
addComponent({ filePath: resolve("./runtime/components/control/SignedOut"), name: "AsgardeoSignedOut" });
|
|
164
|
+
addComponent({ filePath: resolve("./runtime/components/control/Loading"), name: "AsgardeoLoading" });
|
|
165
|
+
addComponent({ filePath: resolve("./runtime/components/actions/SignInButton"), name: "AsgardeoSignInButton" });
|
|
166
|
+
addComponent({ filePath: resolve("./runtime/components/actions/SignOutButton"), name: "AsgardeoSignOutButton" });
|
|
167
|
+
addComponent({ filePath: resolve("./runtime/components/actions/SignUpButton"), name: "AsgardeoSignUpButton" });
|
|
168
|
+
addComponent({ filePath: resolve("./runtime/components/auth/SignIn"), name: "AsgardeoSignIn" });
|
|
169
|
+
addComponent({ filePath: resolve("./runtime/components/auth/SignUp"), name: "AsgardeoSignUp" });
|
|
170
|
+
addComponent({ filePath: resolve("./runtime/components/user/User"), name: "AsgardeoUser" });
|
|
171
|
+
addComponent({ filePath: resolve("./runtime/components/user/UserProfile"), name: "AsgardeoUserProfile" });
|
|
172
|
+
addComponent({ filePath: resolve("./runtime/components/user/UserDropdown"), name: "AsgardeoUserDropdown" });
|
|
173
|
+
addComponent({ filePath: resolve("./runtime/components/organization/Organization"), name: "AsgardeoOrganization" });
|
|
174
|
+
addComponent({
|
|
175
|
+
filePath: resolve("./runtime/components/organization/OrganizationProfile"),
|
|
176
|
+
name: "AsgardeoOrganizationProfile"
|
|
177
|
+
});
|
|
178
|
+
addComponent({
|
|
179
|
+
filePath: resolve("./runtime/components/organization/OrganizationSwitcher"),
|
|
180
|
+
name: "AsgardeoOrganizationSwitcher"
|
|
181
|
+
});
|
|
182
|
+
addComponent({
|
|
183
|
+
filePath: resolve("./runtime/components/organization/OrganizationList"),
|
|
184
|
+
name: "AsgardeoOrganizationList"
|
|
185
|
+
});
|
|
186
|
+
addComponent({
|
|
187
|
+
filePath: resolve("./runtime/components/organization/CreateOrganization"),
|
|
188
|
+
name: "AsgardeoCreateOrganization"
|
|
64
189
|
});
|
|
190
|
+
addComponent({ filePath: resolve("./runtime/components/auth/Callback"), name: "AsgardeoCallback" });
|
|
65
191
|
}
|
|
66
192
|
});
|
|
67
193
|
|
|
@@ -0,0 +1,52 @@
|
|
|
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 Component } from 'vue';
|
|
19
|
+
/**
|
|
20
|
+
* Nuxt root wrapper that mounts the full Asgardeo Vue provider tree.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors `AsgardeoClientProvider` in the Next.js SDK — reads the SSR-hydrated
|
|
23
|
+
* `useState` keys written by the universal Nuxt plugin and passes the resolved
|
|
24
|
+
* data as props to each Vue provider:
|
|
25
|
+
*
|
|
26
|
+
* - {@link I18nProvider} ← `preferences.i18n`
|
|
27
|
+
* - {@link BrandingProvider} ← `brandingPreference` (from `asgardeo:branding`)
|
|
28
|
+
* - {@link ThemeProvider} ← `inheritFromBranding`, `mode`
|
|
29
|
+
* - {@link FlowProvider}
|
|
30
|
+
* - {@link UserProvider} ← `profile`, `flattenedProfile`, `schemas`,
|
|
31
|
+
* `updateProfile`, `revalidateProfile`, `onUpdateProfile`
|
|
32
|
+
* - {@link OrganizationProvider} ← `currentOrganization`, `myOrganizations`,
|
|
33
|
+
* `onOrganizationSwitch`, `getAllOrganizations`,
|
|
34
|
+
* `revalidateMyOrganizations`
|
|
35
|
+
*
|
|
36
|
+
* The `ASGARDEO_KEY` (config + auth state + actions) is still provided at the
|
|
37
|
+
* app level by the Nuxt plugin; this component only supplies the auxiliary
|
|
38
|
+
* provider contexts so downstream composables (`useUser`, `useOrganization`,
|
|
39
|
+
* `useTheme`, `useBranding`, `useAsgardeoI18n`) receive real data.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```vue
|
|
43
|
+
* <!-- app.vue -->
|
|
44
|
+
* <template>
|
|
45
|
+
* <AsgardeoRoot>
|
|
46
|
+
* <NuxtPage />
|
|
47
|
+
* </AsgardeoRoot>
|
|
48
|
+
* </template>
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare const AsgardeoRoot: Component;
|
|
52
|
+
export default AsgardeoRoot;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { generateFlattenedUserProfile } from "@asgardeo/node";
|
|
2
|
+
import {
|
|
3
|
+
BrandingProvider,
|
|
4
|
+
FlowMetaProvider,
|
|
5
|
+
FlowProvider,
|
|
6
|
+
I18nProvider,
|
|
7
|
+
OrganizationProvider,
|
|
8
|
+
ThemeProvider,
|
|
9
|
+
UserProvider
|
|
10
|
+
} from "@asgardeo/vue";
|
|
11
|
+
import { defineComponent, h } from "vue";
|
|
12
|
+
import { useState, useRuntimeConfig } from "#imports";
|
|
13
|
+
const AsgardeoRoot = defineComponent({
|
|
14
|
+
name: "AsgardeoRoot",
|
|
15
|
+
setup(_props, { slots }) {
|
|
16
|
+
const userProfileState = useState("asgardeo:user-profile");
|
|
17
|
+
const currentOrgState = useState("asgardeo:current-org");
|
|
18
|
+
const myOrgsState = useState("asgardeo:my-orgs");
|
|
19
|
+
const brandingState = useState("asgardeo:branding");
|
|
20
|
+
const authState = useState("asgardeo:auth");
|
|
21
|
+
const prefs = useRuntimeConfig().public.asgardeo?.preferences;
|
|
22
|
+
const shouldFetchProfile = prefs?.user?.fetchUserProfile !== false;
|
|
23
|
+
const shouldFetchOrgs = prefs?.user?.fetchOrganizations !== false;
|
|
24
|
+
const shouldFetchBranding = prefs?.theme?.inheritFromBranding !== false;
|
|
25
|
+
const themeMode = prefs?.theme?.mode ?? "light";
|
|
26
|
+
const onUpdateProfile = (payload) => {
|
|
27
|
+
const prev = userProfileState.value;
|
|
28
|
+
userProfileState.value = prev ? {
|
|
29
|
+
...prev,
|
|
30
|
+
flattenedProfile: generateFlattenedUserProfile(payload, prev.schemas),
|
|
31
|
+
profile: payload
|
|
32
|
+
} : {
|
|
33
|
+
flattenedProfile: generateFlattenedUserProfile(payload, []),
|
|
34
|
+
profile: payload,
|
|
35
|
+
schemas: []
|
|
36
|
+
};
|
|
37
|
+
authState.value = { ...authState.value, user: payload };
|
|
38
|
+
};
|
|
39
|
+
const updateProfile = async (requestConfig, _sessionId) => {
|
|
40
|
+
if (_sessionId) {
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = await $fetch("/api/auth/user/profile", {
|
|
44
|
+
body: requestConfig,
|
|
45
|
+
method: "PATCH"
|
|
46
|
+
});
|
|
47
|
+
if (result?.success && result.data?.user) {
|
|
48
|
+
onUpdateProfile(result.data.user);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
} catch (err) {
|
|
52
|
+
return { data: { user: {} }, error: String(err), success: false };
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const revalidateProfile = async () => {
|
|
56
|
+
try {
|
|
57
|
+
const res = await $fetch("/api/auth/user/profile");
|
|
58
|
+
if (res) userProfileState.value = res;
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const onOrganizationSwitch = async (organization) => $fetch("/api/auth/organizations/switch", { body: { organization }, method: "POST" });
|
|
63
|
+
const getAllOrganizations = async () => $fetch("/api/auth/organizations");
|
|
64
|
+
const revalidateMyOrganizations = async () => {
|
|
65
|
+
try {
|
|
66
|
+
const res = await $fetch("/api/auth/organizations/me");
|
|
67
|
+
myOrgsState.value = res ?? [];
|
|
68
|
+
return myOrgsState.value;
|
|
69
|
+
} catch {
|
|
70
|
+
return myOrgsState.value;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const createOrganization = async (payload) => $fetch("/api/auth/organizations", { body: payload, method: "POST" });
|
|
74
|
+
const revalidateCurrentOrganization = async () => {
|
|
75
|
+
try {
|
|
76
|
+
const res = await $fetch("/api/auth/organizations/current");
|
|
77
|
+
currentOrgState.value = res ?? null;
|
|
78
|
+
return currentOrgState.value;
|
|
79
|
+
} catch {
|
|
80
|
+
return currentOrgState.value;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const revalidateBranding = async () => {
|
|
84
|
+
try {
|
|
85
|
+
const res = await $fetch("/api/auth/branding");
|
|
86
|
+
if (res) brandingState.value = res;
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return () => h(
|
|
91
|
+
I18nProvider,
|
|
92
|
+
{ preferences: prefs?.i18n },
|
|
93
|
+
{
|
|
94
|
+
default: () => h(
|
|
95
|
+
FlowMetaProvider,
|
|
96
|
+
{ enabled: false },
|
|
97
|
+
{
|
|
98
|
+
default: () => h(
|
|
99
|
+
BrandingProvider,
|
|
100
|
+
{
|
|
101
|
+
// When inheritFromBranding is disabled, pass null so the provider
|
|
102
|
+
// falls back to its own default theme without using SSR-fetched data.
|
|
103
|
+
brandingPreference: shouldFetchBranding ? brandingState.value : null,
|
|
104
|
+
revalidateBranding: shouldFetchBranding ? revalidateBranding : void 0
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
default: () => h(
|
|
108
|
+
ThemeProvider,
|
|
109
|
+
{
|
|
110
|
+
// Mirror the same flag used in the Nitro plugin gate.
|
|
111
|
+
inheritFromBranding: shouldFetchBranding,
|
|
112
|
+
mode: themeMode
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
default: () => h(FlowProvider, null, {
|
|
116
|
+
default: () => h(
|
|
117
|
+
UserProvider,
|
|
118
|
+
{
|
|
119
|
+
// When fetchUserProfile is false the Nitro plugin
|
|
120
|
+
// skips SCIM calls, so we must also pass empty values
|
|
121
|
+
// here to keep SSR and client in sync.
|
|
122
|
+
flattenedProfile: shouldFetchProfile ? userProfileState.value?.flattenedProfile ?? null : null,
|
|
123
|
+
onUpdateProfile: shouldFetchProfile ? onUpdateProfile : void 0,
|
|
124
|
+
profile: shouldFetchProfile ? userProfileState.value : null,
|
|
125
|
+
revalidateProfile: shouldFetchProfile ? revalidateProfile : void 0,
|
|
126
|
+
schemas: shouldFetchProfile ? userProfileState.value?.schemas ?? null : null,
|
|
127
|
+
updateProfile: shouldFetchProfile ? updateProfile : void 0
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
default: () => h(
|
|
131
|
+
OrganizationProvider,
|
|
132
|
+
{
|
|
133
|
+
// When fetchOrganizations is false pass empty
|
|
134
|
+
// values so the provider renders without org data.
|
|
135
|
+
createOrganization: shouldFetchOrgs ? createOrganization : void 0,
|
|
136
|
+
currentOrganization: shouldFetchOrgs ? currentOrgState.value : null,
|
|
137
|
+
getAllOrganizations: shouldFetchOrgs ? getAllOrganizations : void 0,
|
|
138
|
+
myOrganizations: shouldFetchOrgs ? myOrgsState.value : [],
|
|
139
|
+
onOrganizationSwitch: shouldFetchOrgs ? onOrganizationSwitch : void 0,
|
|
140
|
+
revalidateCurrentOrganization: shouldFetchOrgs ? revalidateCurrentOrganization : void 0,
|
|
141
|
+
revalidateMyOrganizations: shouldFetchOrgs ? revalidateMyOrganizations : void 0
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
default: () => slots["default"]?.()
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
export default AsgardeoRoot;
|
|
@@ -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
|
+
import { type Component } from 'vue';
|
|
19
|
+
/**
|
|
20
|
+
* Nuxt-specific SignInButton container.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors the Next.js SDK's SignInButton: imports {@link BaseSignInButton} from
|
|
23
|
+
* `@asgardeo/vue` and wires navigation through Nuxt's `navigateTo` so
|
|
24
|
+
* server-side redirects work correctly (no `window.location` access).
|
|
25
|
+
*
|
|
26
|
+
* The `signIn` action and `signInUrl` come from the Nuxt-specific
|
|
27
|
+
* {@link useAsgardeo} composable which is provided via the Nuxt auto-import
|
|
28
|
+
* layer — not directly from `@asgardeo/vue`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```vue
|
|
32
|
+
* <AsgardeoSignInButton />
|
|
33
|
+
* <AsgardeoSignInButton class="btn-primary">Log in</AsgardeoSignInButton>
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const SignInButton: Component;
|
|
37
|
+
export default SignInButton;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AsgardeoRuntimeError } from "@asgardeo/browser";
|
|
2
|
+
import { BaseSignInButton } from "@asgardeo/vue";
|
|
3
|
+
import { defineComponent, h, ref } from "vue";
|
|
4
|
+
import { navigateTo } from "#app";
|
|
5
|
+
import { useAsgardeo } from "#imports";
|
|
6
|
+
const SignInButton = defineComponent({
|
|
7
|
+
emits: ["click", "error"],
|
|
8
|
+
name: "SignInButton",
|
|
9
|
+
props: {
|
|
10
|
+
signInOptions: { default: void 0, type: Object }
|
|
11
|
+
},
|
|
12
|
+
setup(props, { slots, emit, attrs }) {
|
|
13
|
+
const { signIn, signInUrl, signInOptions: contextSignInOptions } = useAsgardeo();
|
|
14
|
+
const isLoading = ref(false);
|
|
15
|
+
const handleSignIn = async (e) => {
|
|
16
|
+
try {
|
|
17
|
+
isLoading.value = true;
|
|
18
|
+
if (signInUrl) {
|
|
19
|
+
await navigateTo(signInUrl, { external: true });
|
|
20
|
+
} else {
|
|
21
|
+
await signIn(props.signInOptions ?? contextSignInOptions);
|
|
22
|
+
}
|
|
23
|
+
if (e) emit("click", e);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
emit("error", error);
|
|
26
|
+
throw new AsgardeoRuntimeError(
|
|
27
|
+
`Sign in failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
28
|
+
"SignInButton-handleSignIn-RuntimeError-001",
|
|
29
|
+
"nuxt",
|
|
30
|
+
"Something went wrong while trying to sign in. Please try again later."
|
|
31
|
+
);
|
|
32
|
+
} finally {
|
|
33
|
+
isLoading.value = false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return () => {
|
|
37
|
+
const slotContent = slots["default"] ? () => slots["default"]({ isLoading: isLoading.value }) : void 0;
|
|
38
|
+
return h(
|
|
39
|
+
BaseSignInButton,
|
|
40
|
+
{
|
|
41
|
+
class: attrs["class"],
|
|
42
|
+
isLoading: isLoading.value,
|
|
43
|
+
onClick: handleSignIn,
|
|
44
|
+
style: attrs["style"]
|
|
45
|
+
},
|
|
46
|
+
slotContent
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export default SignInButton;
|
|
@@ -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
|
+
import { type Component } from 'vue';
|
|
19
|
+
/**
|
|
20
|
+
* Nuxt-specific SignOutButton container.
|
|
21
|
+
*
|
|
22
|
+
* Imports {@link BaseSignOutButton} from `@asgardeo/vue` and wires the
|
|
23
|
+
* `signOut` action through the Nuxt-specific {@link useAsgardeo} composable
|
|
24
|
+
* (auto-import layer), which uses Nuxt's `navigateTo` instead of
|
|
25
|
+
* `window.location`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```vue
|
|
29
|
+
* <AsgardeoSignOutButton />
|
|
30
|
+
* <AsgardeoSignOutButton class="btn-secondary">Sign out</AsgardeoSignOutButton>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare const SignOutButton: Component;
|
|
34
|
+
export default SignOutButton;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AsgardeoRuntimeError } from "@asgardeo/browser";
|
|
2
|
+
import { BaseSignOutButton } from "@asgardeo/vue";
|
|
3
|
+
import { defineComponent, h, ref } from "vue";
|
|
4
|
+
import { useAsgardeo } from "#imports";
|
|
5
|
+
const SignOutButton = defineComponent({
|
|
6
|
+
emits: ["click", "error"],
|
|
7
|
+
name: "SignOutButton",
|
|
8
|
+
setup(_, { slots, emit, attrs }) {
|
|
9
|
+
const { signOut } = useAsgardeo();
|
|
10
|
+
const isLoading = ref(false);
|
|
11
|
+
const handleSignOut = async (e) => {
|
|
12
|
+
try {
|
|
13
|
+
isLoading.value = true;
|
|
14
|
+
await signOut();
|
|
15
|
+
if (e) emit("click", e);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
emit("error", error);
|
|
18
|
+
throw new AsgardeoRuntimeError(
|
|
19
|
+
`Sign out failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
20
|
+
"SignOutButton-handleSignOut-RuntimeError-001",
|
|
21
|
+
"nuxt",
|
|
22
|
+
"Something went wrong while trying to sign out. Please try again later."
|
|
23
|
+
);
|
|
24
|
+
} finally {
|
|
25
|
+
isLoading.value = false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return () => {
|
|
29
|
+
const slotContent = slots["default"] ? () => slots["default"]({ isLoading: isLoading.value }) : void 0;
|
|
30
|
+
return h(
|
|
31
|
+
BaseSignOutButton,
|
|
32
|
+
{
|
|
33
|
+
class: attrs["class"],
|
|
34
|
+
isLoading: isLoading.value,
|
|
35
|
+
onClick: handleSignOut,
|
|
36
|
+
style: attrs["style"]
|
|
37
|
+
},
|
|
38
|
+
slotContent
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export default SignOutButton;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 Component } from 'vue';
|
|
19
|
+
/**
|
|
20
|
+
* Nuxt-specific SignUpButton container.
|
|
21
|
+
*
|
|
22
|
+
* Imports {@link BaseSignUpButton} from `@asgardeo/vue` and wires navigation
|
|
23
|
+
* through Nuxt's `navigateTo` so a configured `signUpUrl` is followed
|
|
24
|
+
* SSR-safely instead of via `window.location`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```vue
|
|
28
|
+
* <AsgardeoSignUpButton />
|
|
29
|
+
* <AsgardeoSignUpButton class="btn-primary">Create account</AsgardeoSignUpButton>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare const SignUpButton: Component;
|
|
33
|
+
export default SignUpButton;
|