una-nuxt-module 3.0.5 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "una-nuxt-module",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "configKey": "unaxt",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
package/dist/module.mjs CHANGED
@@ -167,7 +167,7 @@ function addTemplates() {
167
167
  }
168
168
 
169
169
  const name = "una-nuxt-module";
170
- const version = "3.0.5";
170
+ const version = "3.0.7";
171
171
 
172
172
  const module$1 = defineNuxtModule({
173
173
  meta: {
@@ -179,9 +179,23 @@ const module$1 = defineNuxtModule({
179
179
  }
180
180
  },
181
181
  defaults: {
182
- use: {
183
- sso: true,
184
- components: true
182
+ components: true,
183
+ auth: {
184
+ enabled: true,
185
+ sso: {
186
+ automaticSignIn: true,
187
+ postLoginRedirectUrl: "/",
188
+ signInRedirectUrl: "/auth/sso/login",
189
+ signOutRedirectUrl: "/auth/sso/login"
190
+ },
191
+ middleware: {
192
+ authentication: {
193
+ global: true
194
+ },
195
+ authorization: {
196
+ global: true
197
+ }
198
+ }
185
199
  }
186
200
  },
187
201
  moduleDependencies: {
@@ -213,6 +227,7 @@ const module$1 = defineNuxtModule({
213
227
  const logger = useLogger(name);
214
228
  const { resolve } = createResolver(import.meta.url);
215
229
  options = defu(nuxt.options.runtimeConfig.public.unaxt, options);
230
+ nuxt.options.runtimeConfig.public.unaxt = options;
216
231
  nuxt.options.alias["#unaxt"] = resolve("./runtime");
217
232
  function setupAutoImports() {
218
233
  addImportsDir(
@@ -254,7 +269,7 @@ const module$1 = defineNuxtModule({
254
269
  logger.ready(green("Internacionalizaci\xF3n inicializada"));
255
270
  }
256
271
  function setupComponents() {
257
- if (options.use.components) {
272
+ if (options.components) {
258
273
  addComponentsDir({
259
274
  path: resolve("./runtime/components/shared"),
260
275
  prefix: "",
@@ -278,7 +293,7 @@ const module$1 = defineNuxtModule({
278
293
  }
279
294
  }
280
295
  function setupAuth() {
281
- if (options.use.sso) {
296
+ if (options.auth?.enabled) {
282
297
  logger.ready(green("Iniciando m\xF3dulo de autenticaci\xF3n"));
283
298
  addImportsDir(
284
299
  ["auth/stores", "auth/composables"].map(
@@ -296,18 +311,18 @@ const module$1 = defineNuxtModule({
296
311
  addRouteMiddleware({
297
312
  name: "authentication",
298
313
  path: resolve("./runtime/auth/middleware/authentication"),
299
- global: true
314
+ global: options.auth.middleware?.authentication.global
300
315
  });
301
316
  addRouteMiddleware({
302
317
  name: "authorization",
303
318
  path: resolve("./runtime/auth/middleware/authorization"),
304
- global: true
319
+ global: options.auth.middleware?.authorization.global
305
320
  });
306
321
  logger.ready("\u251C\u2500\u2500 " + gray("Middlewares registrados"));
307
322
  nuxt.options.runtimeConfig.public.unaxt = defu(
308
323
  nuxt.options.runtimeConfig.public.unaxt,
309
324
  {
310
- navigation: {
325
+ auth: {
311
326
  unprotectedPages: ["/401", "/403", "/auth/sso/login"]
312
327
  }
313
328
  }
@@ -2,9 +2,11 @@ import { useRuntimeConfig } from "#imports";
2
2
  import { useAuthStore } from "../stores/auth.js";
3
3
  export const useAuthorization = () => {
4
4
  const isPageUnprotected = (page) => {
5
- return useRuntimeConfig().public.unaxt.navigation.unprotectedPages.includes(
6
- page
7
- );
5
+ const unprotectedPages = useRuntimeConfig().public.unaxt.auth.unprotectedPages;
6
+ if (!unprotectedPages) {
7
+ return false;
8
+ }
9
+ return unprotectedPages.includes(page);
8
10
  };
9
11
  const hasAccessTo = (resource) => {
10
12
  const authStore = useAuthStore();
@@ -21,7 +23,7 @@ export const useAuthorization = () => {
21
23
  authStore.authData.accessToken = token;
22
24
  }
23
25
  const baseURL = runtimeConfig.public.apiBaseUrl;
24
- const modulo = runtimeConfig.public.unaxt.authorization.modulo;
26
+ const modulo = runtimeConfig.public.unaxt.auth.modulo;
25
27
  const endpoint = `/api/recurso/modulo/${modulo}`;
26
28
  try {
27
29
  const response = await $fetch(endpoint, {
@@ -1,4 +1,4 @@
1
- import { defineNuxtRouteMiddleware, useNuxtApp } from "#app";
1
+ import { defineNuxtRouteMiddleware, useNuxtApp, useRuntimeConfig } from "#app";
2
2
  import { useAuthStore } from "../stores/auth.js";
3
3
  import { useAuthorization } from "../composables/useAuthorization.js";
4
4
  export default defineNuxtRouteMiddleware(async () => {
@@ -8,9 +8,14 @@ export default defineNuxtRouteMiddleware(async () => {
8
8
  const authorization = useAuthorization();
9
9
  const authStore = useAuthStore();
10
10
  if (!authStore.isAuthenticated) {
11
- const { $authData, $isAuthenticated, $accessToken } = useNuxtApp();
11
+ const { $signIn, $authData, $isAuthenticated, $accessToken } = useNuxtApp();
12
12
  const isAuthenticated = await $isAuthenticated();
13
13
  if (!isAuthenticated) {
14
+ const runtimeConfig = useRuntimeConfig();
15
+ const authConfig = runtimeConfig.public.unaxt.auth;
16
+ if (!authConfig.sso?.automaticSignIn) {
17
+ await $signIn();
18
+ }
14
19
  return;
15
20
  }
16
21
  const authResponse = await $authData();
@@ -3,9 +3,11 @@
3
3
  </template>
4
4
 
5
5
  <script setup>
6
+ import { useRuntimeConfig } from "#app";
6
7
  import { navigateTo } from "#imports";
7
8
  import { onMounted } from "vue";
9
+ const runtimeConfig = useRuntimeConfig();
8
10
  onMounted(() => {
9
- navigateTo("/");
11
+ navigateTo(runtimeConfig.public.unaxt.auth.sso?.postLoginRedirectUrl ?? "/");
10
12
  });
11
13
  </script>
@@ -2,19 +2,18 @@
2
2
  * Plugin encargado de implementar autenticación SSO mediante WSO2.
3
3
  *
4
4
  * Se expone la información de la sesión proporcionando helpers en la instancia NuxtApp.
5
- *
6
- * @example
7
- * ```ts
8
- const { $isAuthenticated, $authData } = useNuxtApp();
9
- * ```
10
5
  */
11
6
  declare const _default: import("#app").Plugin<{
7
+ /**
8
+ * Método para iniciar la sesión del usuario en WSO2.
9
+ */
10
+ signIn: () => Promise<void>;
12
11
  /**
13
12
  * Método para cerrar la sesión del usuario en WSO2.
14
13
  */
15
14
  signOut: () => Promise<void>;
16
15
  /**
17
- * Método si el usuario esta autenticado en WSO2.
16
+ * Método que retorna si el usuario esta autenticado en WSO2.
18
17
  */
19
18
  isAuthenticated: () => Promise<boolean | undefined>;
20
19
  /**
@@ -38,12 +37,16 @@ declare const _default: import("#app").Plugin<{
38
37
  */
39
38
  OIDCServiceEndpoints: () => Promise<import("@asgardeo/auth-spa").OIDCEndpoints | undefined>;
40
39
  }> & import("#app").ObjectPlugin<{
40
+ /**
41
+ * Método para iniciar la sesión del usuario en WSO2.
42
+ */
43
+ signIn: () => Promise<void>;
41
44
  /**
42
45
  * Método para cerrar la sesión del usuario en WSO2.
43
46
  */
44
47
  signOut: () => Promise<void>;
45
48
  /**
46
- * Método si el usuario esta autenticado en WSO2.
49
+ * Método que retorna si el usuario esta autenticado en WSO2.
47
50
  */
48
51
  isAuthenticated: () => Promise<boolean | undefined>;
49
52
  /**
@@ -8,19 +8,21 @@ import { useAuthorization } from "../composables/useAuthorization.js";
8
8
  export default defineNuxtPlugin(() => {
9
9
  const auth = AsgardeoSPAClient.getInstance();
10
10
  const runtimeConfig = useRuntimeConfig();
11
- const ssoConfig = runtimeConfig.public.unaxt.sso;
11
+ const authConfig = runtimeConfig.public.unaxt.auth;
12
12
  const DEFAULT_SCOPES = ["openid", "profile", "email"];
13
- const scope = ssoConfig.scopes !== "" ? ssoConfig.scopes.split("|") : DEFAULT_SCOPES;
13
+ const scope = authConfig.sso?.scopes !== "" ? authConfig.sso?.scopes?.split("|") : DEFAULT_SCOPES;
14
14
  const config = {
15
- baseUrl: ssoConfig.baseUrl,
16
- clientID: ssoConfig.clientId,
17
- clientSecret: ssoConfig.clientSecret,
15
+ baseUrl: authConfig.sso?.baseUrl ?? "",
16
+ clientID: authConfig.sso?.clientId ?? "",
17
+ clientSecret: authConfig.sso?.clientSecret ?? "",
18
18
  scope,
19
- signInRedirectURL: ssoConfig.signInRedirectUrl,
20
- signOutRedirectURL: ssoConfig.signOutRedirectUrl
19
+ signInRedirectURL: "https://" + window.location.host + (authConfig.sso?.signInRedirectUrl ?? "/"),
20
+ signOutRedirectURL: "https://" + window.location.host + (authConfig.sso?.signOutRedirectUrl ?? "/")
21
21
  };
22
22
  auth?.initialize(config);
23
- auth?.signIn();
23
+ if (authConfig.sso?.automaticSignIn) {
24
+ auth?.signIn();
25
+ }
24
26
  auth?.on(Hooks.SignIn, async (response) => {
25
27
  const authorization = useAuthorization();
26
28
  const authStore = useAuthStore();
@@ -51,6 +53,12 @@ export default defineNuxtPlugin(() => {
51
53
  });
52
54
  return {
53
55
  provide: {
56
+ /**
57
+ * Método para iniciar la sesión del usuario en WSO2.
58
+ */
59
+ signIn: async () => {
60
+ auth?.signIn();
61
+ },
54
62
  /**
55
63
  * Método para cerrar la sesión del usuario en WSO2.
56
64
  */
@@ -58,7 +66,7 @@ export default defineNuxtPlugin(() => {
58
66
  auth?.signOut();
59
67
  },
60
68
  /**
61
- * Método si el usuario esta autenticado en WSO2.
69
+ * Método que retorna si el usuario esta autenticado en WSO2.
62
70
  */
63
71
  isAuthenticated: async () => {
64
72
  return await auth?.isAuthenticated();
@@ -2,59 +2,75 @@ import type { EAuthorization, EFormMode } from '../enums/index.js';
2
2
  /**
3
3
  * Los tipos definidos en este archivo son exportados globalmente, lo que hace que no sea necesario importarlos para usarlos.
4
4
  */
5
+ /**
6
+ * Configuración de inicio de sesión único (SSO) con WSO2.
7
+ */
8
+ interface ISSOConfig {
9
+ /**
10
+ * Inicio de sesión automatico.
11
+ */
12
+ automaticSignIn: boolean;
13
+ /**
14
+ * URL de redirección después de iniciar sesión.
15
+ */
16
+ signInRedirectUrl: string;
17
+ /**
18
+ * URL de redirección después de cerrar sesión.
19
+ */
20
+ signOutRedirectUrl: string;
21
+ /**
22
+ * URL de redirección final después de completar el login SSO.
23
+ */
24
+ postLoginRedirectUrl: string;
25
+ /**
26
+ * ID del cliente para la autenticación (OAuth Client Key del Service Provider).
27
+ */
28
+ clientId: string;
29
+ /**
30
+ * OAuth Client Secret del Service Provider)
31
+ */
32
+ clientSecret: string;
33
+ /**
34
+ * URL base del servicio SSO (servidor WSO2).
35
+ */
36
+ baseUrl: string;
37
+ /**
38
+ * Lista de permisos o alcances solicitados.
39
+ */
40
+ scopes: string;
41
+ }
5
42
  /**
6
43
  * Opciones de configuración para el módulo Nuxt.
7
44
  *
8
45
  * @interface IUnaxtModuleOptions
9
46
  */
10
47
  export interface IUnaxtModuleOptions {
11
- /**
12
- * Configuración de inicio de sesión único (SSO) con WSO2.
13
- */
14
- sso: {
15
- /**
16
- * URL de redirección después de iniciar sesión.
17
- */
18
- signInRedirectUrl: string;
19
- /**
20
- * URL de redirección después de cerrar sesión.
21
- */
22
- signOutRedirectUrl: string;
23
- /**
24
- * ID del cliente para la autenticación (OAuth Client Key del Service Provider).
25
- */
26
- clientId: string;
48
+ components?: boolean;
49
+ auth: {
27
50
  /**
28
- * OAuth Client Secret del Service Provider)
51
+ * Activa o desactiva SSO.
29
52
  */
30
- clientSecret: string;
53
+ enabled: boolean;
54
+ sso?: Partial<ISSOConfig>;
31
55
  /**
32
- * URL base del servicio SSO (servidor WSO2).
56
+ * Modulo para obtener recursos.
33
57
  */
34
- baseUrl: string;
58
+ modulo?: string;
35
59
  /**
36
- * Lista de permisos o alcances solicitados.
60
+ * Páginas que no requieren autenticación.
37
61
  */
38
- scopes: string;
39
- };
40
- /**
41
- * Configuración de la API de autorización.
42
- */
43
- authorization: {
44
- modulo: string;
45
- };
46
- /**
47
- * Configuración general del módulo.
48
- */
49
- navigation: {
62
+ unprotectedPages?: string[];
50
63
  /**
51
- * Páginas que no requieren autenticación.
64
+ * Configuracion de registro global de middlewares.
52
65
  */
53
- unprotectedPages: string[];
54
- };
55
- use: {
56
- sso: boolean;
57
- components: boolean;
66
+ middleware?: {
67
+ authentication: {
68
+ global: boolean;
69
+ };
70
+ authorization: {
71
+ global: boolean;
72
+ };
73
+ };
58
74
  };
59
75
  }
60
76
  /** Tipo de autorización. */
@@ -292,3 +308,4 @@ export interface IBreadcrumb {
292
308
  label: string;
293
309
  to?: string;
294
310
  }
311
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "una-nuxt-module",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Módulo Nuxt para desarrollo CGI",
5
5
  "repository": {
6
6
  "type": "git",