una-nuxt-module 3.0.3 → 3.0.5
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 +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/auth/composables/useAuthorization.js +10 -11
- package/dist/runtime/auth/middleware/authentication.js +5 -5
- package/dist/runtime/auth/plugins/auth.js +4 -3
- package/dist/runtime/types/index.d.ts +4 -25
- package/package.json +1 -1
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
package/dist/module.mjs
CHANGED
|
@@ -20,19 +20,18 @@ export const useAuthorization = () => {
|
|
|
20
20
|
if (authStore.authData) {
|
|
21
21
|
authStore.authData.accessToken = token;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const baseURL = runtimeConfig.public.apiBaseUrl;
|
|
24
|
+
const modulo = runtimeConfig.public.unaxt.authorization.modulo;
|
|
25
|
+
const endpoint = `/api/recurso/modulo/${modulo}`;
|
|
24
26
|
try {
|
|
25
|
-
const response = await $fetch(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Se agrega el token de la sesión
|
|
32
|
-
Authorization: `Bearer ${token}`
|
|
33
|
-
}
|
|
27
|
+
const response = await $fetch(endpoint, {
|
|
28
|
+
baseURL,
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: {
|
|
31
|
+
// Se agrega el token de la sesión
|
|
32
|
+
Authorization: `Bearer ${token}`
|
|
34
33
|
}
|
|
35
|
-
);
|
|
34
|
+
});
|
|
36
35
|
if (response) return response.data;
|
|
37
36
|
} catch (error) {
|
|
38
37
|
console.error("Error obteniendo recursos:", error);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineNuxtRouteMiddleware, useNuxtApp } from "#app";
|
|
2
|
-
import { upperFirst } from "scule";
|
|
3
2
|
import { useAuthStore } from "../stores/auth.js";
|
|
4
3
|
import { useAuthorization } from "../composables/useAuthorization.js";
|
|
5
4
|
export default defineNuxtRouteMiddleware(async () => {
|
|
@@ -19,11 +18,12 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
19
18
|
const resources = await authorization.getResources(token);
|
|
20
19
|
const getUserInfo = () => {
|
|
21
20
|
if (authResponse?.email) {
|
|
22
|
-
const [
|
|
21
|
+
const email = Array.isArray(authResponse?.email) ? authResponse?.email[0] : authResponse?.email;
|
|
22
|
+
const [name, lastName] = email.toUpperCase().split(".");
|
|
23
23
|
return {
|
|
24
|
-
name
|
|
25
|
-
lastName
|
|
26
|
-
fullName:
|
|
24
|
+
name,
|
|
25
|
+
lastName,
|
|
26
|
+
fullName: name + " " + lastName
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
};
|
|
@@ -9,14 +9,15 @@ export default defineNuxtPlugin(() => {
|
|
|
9
9
|
const auth = AsgardeoSPAClient.getInstance();
|
|
10
10
|
const runtimeConfig = useRuntimeConfig();
|
|
11
11
|
const ssoConfig = runtimeConfig.public.unaxt.sso;
|
|
12
|
+
const DEFAULT_SCOPES = ["openid", "profile", "email"];
|
|
13
|
+
const scope = ssoConfig.scopes !== "" ? ssoConfig.scopes.split("|") : DEFAULT_SCOPES;
|
|
12
14
|
const config = {
|
|
13
15
|
baseUrl: ssoConfig.baseUrl,
|
|
14
16
|
clientID: ssoConfig.clientId,
|
|
15
17
|
clientSecret: ssoConfig.clientSecret,
|
|
16
|
-
scope
|
|
18
|
+
scope,
|
|
17
19
|
signInRedirectURL: ssoConfig.signInRedirectUrl,
|
|
18
|
-
signOutRedirectURL: ssoConfig.signOutRedirectUrl
|
|
19
|
-
validateIDToken: ssoConfig.validateIdToken
|
|
20
|
+
signOutRedirectURL: ssoConfig.signOutRedirectUrl
|
|
20
21
|
};
|
|
21
22
|
auth?.initialize(config);
|
|
22
23
|
auth?.signIn();
|
|
@@ -35,34 +35,13 @@ export interface IUnaxtModuleOptions {
|
|
|
35
35
|
/**
|
|
36
36
|
* Lista de permisos o alcances solicitados.
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Indica si se debe validar el IDToken.
|
|
41
|
-
*/
|
|
42
|
-
validateIdToken?: boolean;
|
|
38
|
+
scopes: string;
|
|
43
39
|
};
|
|
44
40
|
/**
|
|
45
|
-
* Configuración de
|
|
41
|
+
* Configuración de la API de autorización.
|
|
46
42
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* Configuración de la API de autorización.
|
|
50
|
-
*/
|
|
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;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
43
|
+
authorization: {
|
|
44
|
+
modulo: string;
|
|
66
45
|
};
|
|
67
46
|
/**
|
|
68
47
|
* Configuración general del módulo.
|