una-nuxt-module 3.0.4 → 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.d.mts CHANGED
@@ -4,6 +4,7 @@ import { IUnaxtModuleOptions } from '../dist/runtime/types/index.js';
4
4
  declare const _default: _nuxt_schema.NuxtModule<IUnaxtModuleOptions, IUnaxtModuleOptions, false>;
5
5
 
6
6
  interface ModulePublicRuntimeConfig {
7
+ apiBaseUrl: string;
7
8
  unaxt: IUnaxtModuleOptions;
8
9
  }
9
10
  declare module '@nuxt/schema' {
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "una-nuxt-module",
3
- "version": "3.0.4",
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.4";
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();
@@ -20,19 +22,18 @@ export const useAuthorization = () => {
20
22
  if (authStore.authData) {
21
23
  authStore.authData.accessToken = token;
22
24
  }
23
- const AUTHORIZATION_API = runtimeConfig.public.unaxt.apis.authorization;
25
+ const baseURL = runtimeConfig.public.apiBaseUrl;
26
+ const modulo = runtimeConfig.public.unaxt.auth.modulo;
27
+ const endpoint = `/api/recurso/modulo/${modulo}`;
24
28
  try {
25
- const response = await $fetch(
26
- AUTHORIZATION_API.endpoints.getResources,
27
- {
28
- baseURL: AUTHORIZATION_API.baseUrl,
29
- method: "GET",
30
- headers: {
31
- // Se agrega el token de la sesión
32
- Authorization: `Bearer ${token}`
33
- }
29
+ const response = await $fetch(endpoint, {
30
+ baseURL,
31
+ method: "GET",
32
+ headers: {
33
+ // Se agrega el token de la sesión
34
+ Authorization: `Bearer ${token}`
34
35
  }
35
- );
36
+ });
36
37
  if (response) return response.data;
37
38
  } catch (error) {
38
39
  console.error("Error obteniendo recursos:", error);
@@ -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,18 +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
+ const DEFAULT_SCOPES = ["openid", "profile", "email"];
13
+ const scope = authConfig.sso?.scopes !== "" ? authConfig.sso?.scopes?.split("|") : DEFAULT_SCOPES;
12
14
  const config = {
13
- baseUrl: ssoConfig.baseUrl,
14
- clientID: ssoConfig.clientId,
15
- clientSecret: ssoConfig.clientSecret,
16
- scope: ssoConfig.scope?.split("|") || [],
17
- signInRedirectURL: ssoConfig.signInRedirectUrl,
18
- signOutRedirectURL: ssoConfig.signOutRedirectUrl,
19
- validateIDToken: ssoConfig.validateIdToken
15
+ baseUrl: authConfig.sso?.baseUrl ?? "",
16
+ clientID: authConfig.sso?.clientId ?? "",
17
+ clientSecret: authConfig.sso?.clientSecret ?? "",
18
+ scope,
19
+ signInRedirectURL: "https://" + window.location.host + (authConfig.sso?.signInRedirectUrl ?? "/"),
20
+ signOutRedirectURL: "https://" + window.location.host + (authConfig.sso?.signOutRedirectUrl ?? "/")
20
21
  };
21
22
  auth?.initialize(config);
22
- auth?.signIn();
23
+ if (authConfig.sso?.automaticSignIn) {
24
+ auth?.signIn();
25
+ }
23
26
  auth?.on(Hooks.SignIn, async (response) => {
24
27
  const authorization = useAuthorization();
25
28
  const authStore = useAuthStore();
@@ -50,6 +53,12 @@ export default defineNuxtPlugin(() => {
50
53
  });
51
54
  return {
52
55
  provide: {
56
+ /**
57
+ * Método para iniciar la sesión del usuario en WSO2.
58
+ */
59
+ signIn: async () => {
60
+ auth?.signIn();
61
+ },
53
62
  /**
54
63
  * Método para cerrar la sesión del usuario en WSO2.
55
64
  */
@@ -57,7 +66,7 @@ export default defineNuxtPlugin(() => {
57
66
  auth?.signOut();
58
67
  },
59
68
  /**
60
- * Método si el usuario esta autenticado en WSO2.
69
+ * Método que retorna si el usuario esta autenticado en WSO2.
61
70
  */
62
71
  isAuthenticated: async () => {
63
72
  return await auth?.isAuthenticated();
@@ -2,81 +2,76 @@ 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: {
48
+ components?: boolean;
49
+ auth: {
15
50
  /**
16
- * URL de redirección después de iniciar sesión.
51
+ * Activa o desactiva SSO.
17
52
  */
18
- signInRedirectUrl: string;
53
+ enabled: boolean;
54
+ sso?: Partial<ISSOConfig>;
19
55
  /**
20
- * URL de redirección después de cerrar sesión.
56
+ * Modulo para obtener recursos.
21
57
  */
22
- signOutRedirectUrl: string;
58
+ modulo?: string;
23
59
  /**
24
- * ID del cliente para la autenticación (OAuth Client Key del Service Provider).
25
- */
26
- clientId: string;
27
- /**
28
- * OAuth Client Secret del Service Provider)
29
- */
30
- clientSecret: string;
31
- /**
32
- * URL base del servicio SSO (servidor WSO2).
33
- */
34
- baseUrl: string;
35
- /**
36
- * Lista de permisos o alcances solicitados.
37
- */
38
- scope: string;
39
- /**
40
- * Indica si se debe validar el IDToken.
60
+ * Páginas que no requieren autenticación.
41
61
  */
42
- validateIdToken?: boolean;
43
- };
44
- /**
45
- * Configuración de las APIs utilizadas por el módulo.
46
- */
47
- apis: {
62
+ unprotectedPages?: string[];
48
63
  /**
49
- * Configuración de la API de autorización.
64
+ * Configuracion de registro global de middlewares.
50
65
  */
51
- authorization: {
52
- /**
53
- * URL base de la API de autorización.
54
- */
55
- baseUrl: string;
56
- /**
57
- * Endpoints disponibles en la API de autorización.
58
- */
59
- endpoints: {
60
- /**
61
- * Endpoint para obtener los recursos disponibles.
62
- */
63
- getResources: string;
66
+ middleware?: {
67
+ authentication: {
68
+ global: boolean;
69
+ };
70
+ authorization: {
71
+ global: boolean;
64
72
  };
65
73
  };
66
74
  };
67
- /**
68
- * Configuración general del módulo.
69
- */
70
- navigation: {
71
- /**
72
- * Páginas que no requieren autenticación.
73
- */
74
- unprotectedPages: string[];
75
- };
76
- use: {
77
- sso: boolean;
78
- components: boolean;
79
- };
80
75
  }
81
76
  /** Tipo de autorización. */
82
77
  export type TAuthorization = keyof typeof EAuthorization;
@@ -313,3 +308,4 @@ export interface IBreadcrumb {
313
308
  label: string;
314
309
  to?: string;
315
310
  }
311
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "una-nuxt-module",
3
- "version": "3.0.4",
3
+ "version": "3.0.7",
4
4
  "description": "Módulo Nuxt para desarrollo CGI",
5
5
  "repository": {
6
6
  "type": "git",