@luizleon/sf.prefeiturasp.vuecomponents 0.0.27 → 0.0.28
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/index.d.ts +2 -2
- package/dist/lib.es.js +3183 -3374
- package/dist/lib.es.js.map +1 -1
- package/dist/lib.umd.js +22 -24
- package/dist/lib.umd.js.map +1 -1
- package/dist/services/authService.d.ts +3 -6
- package/package.json +1 -2
- package/src/components/internal/HeaderAvatar.vue +17 -9
- package/src/components/layout/Layout.vue +5 -1
- package/src/index.ts +3 -4
- package/src/keycloak.js +6 -17
- package/src/services/authService.ts +56 -57
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Keycloak from "./../keycloak";
|
|
1
|
+
import Keycloak, { KeycloakConfig } from "./../keycloak";
|
|
2
2
|
interface User {
|
|
3
3
|
name: string;
|
|
4
4
|
email: string;
|
|
@@ -11,13 +11,10 @@ interface User {
|
|
|
11
11
|
sub: string;
|
|
12
12
|
IsInRole: (role: string) => boolean;
|
|
13
13
|
}
|
|
14
|
-
declare const
|
|
14
|
+
declare const UseAuthService: (config: KeycloakConfig) => {
|
|
15
15
|
Instance: Keycloak;
|
|
16
16
|
User: User;
|
|
17
|
-
SetUrl: (url: string) => void;
|
|
18
|
-
SetRealm: (realm: string) => void;
|
|
19
|
-
SetClientId: (clientId: string) => void;
|
|
20
17
|
CallLogin: (onSuccess: () => void, onError: (error: any) => void) => void;
|
|
21
18
|
CallLogout: () => void;
|
|
22
19
|
};
|
|
23
|
-
export {
|
|
20
|
+
export { UseAuthService };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luizleon/sf.prefeiturasp.vuecomponents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/lib.umd.js",
|
|
6
6
|
"module": "dist/lib.es.js",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"@vitejs/plugin-vue": "4.4.1",
|
|
20
20
|
"base64-js": "1.5.1",
|
|
21
21
|
"dompurify": "3.0.6",
|
|
22
|
-
"dotenv": "16.3.1",
|
|
23
22
|
"js-sha256": "0.10.1",
|
|
24
23
|
"jwt-decode": "4.0.0",
|
|
25
24
|
"rimraf": "3.0.2",
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { computed, onMounted, ref } from "vue";
|
|
3
3
|
import { UseDialogService } from "../../services/dialogService";
|
|
4
4
|
|
|
5
5
|
const dialogService = UseDialogService();
|
|
6
6
|
|
|
7
|
-
const letters =
|
|
7
|
+
const letters = ref("");
|
|
8
|
+
|
|
9
|
+
const emit = defineEmits<{
|
|
10
|
+
(event: "logout"): void;
|
|
11
|
+
}>();
|
|
8
12
|
|
|
9
13
|
async function Logout() {
|
|
10
14
|
const confirm = await dialogService.ConfirmAsync({
|
|
11
|
-
text:
|
|
15
|
+
text: `Você deseja sair da conta?`,
|
|
12
16
|
confirmLabel: "sair",
|
|
13
17
|
});
|
|
14
18
|
if (!confirm) return;
|
|
15
|
-
|
|
19
|
+
emit("logout");
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
function Letters() {
|
|
19
|
-
const name =
|
|
23
|
+
const name = sessionStorage.getItem("name");
|
|
20
24
|
let letters = "?";
|
|
21
25
|
if (!name) return letters;
|
|
22
26
|
|
|
@@ -32,18 +36,22 @@ function Letters() {
|
|
|
32
36
|
return letters.length > 0 ? letters : "?";
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
const primeiraLetra = letters[0];
|
|
39
|
+
const color = computed(() => {
|
|
40
|
+
const primeiraLetra = letters.value[0];
|
|
37
41
|
const cor =
|
|
38
42
|
primeiraLetra === "?"
|
|
39
43
|
? 0
|
|
40
44
|
: (primeiraLetra.charCodeAt(0) - 64) % 19;
|
|
41
45
|
return Math.max(cor, 0);
|
|
42
|
-
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
letters.value = Letters();
|
|
50
|
+
});
|
|
43
51
|
</script>
|
|
44
52
|
|
|
45
53
|
<template>
|
|
46
|
-
<div id="sf-header-avatar" :data-cor="
|
|
54
|
+
<div id="sf-header-avatar" :data-cor="color" @click="Logout">
|
|
47
55
|
{{ letters }}
|
|
48
56
|
</div>
|
|
49
57
|
</template>
|
|
@@ -6,6 +6,10 @@ import MenuIcon from "../internal/MenuIcon.vue";
|
|
|
6
6
|
import ThemeToggle from "../internal/ThemeToggle.vue";
|
|
7
7
|
|
|
8
8
|
const navService = UseNavMenuService();
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<{
|
|
11
|
+
(event: "logout"): void;
|
|
12
|
+
}>();
|
|
9
13
|
</script>
|
|
10
14
|
|
|
11
15
|
<template>
|
|
@@ -26,7 +30,7 @@ const navService = UseNavMenuService();
|
|
|
26
30
|
</div>
|
|
27
31
|
<slot name="action"> </slot>
|
|
28
32
|
<ThemeToggle />
|
|
29
|
-
<HeaderAvatar />
|
|
33
|
+
<HeaderAvatar @logout="" />
|
|
30
34
|
</header>
|
|
31
35
|
<nav :class="{ visible: navService.IsVisible }">
|
|
32
36
|
<div class="sf-layout-nav-header">
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,8 @@ import SfButton from "./components/button/Button.vue";
|
|
|
7
7
|
|
|
8
8
|
import { UseNavMenuService } from "./services/navMenuService";
|
|
9
9
|
import { UseDialogService } from "./services/dialogService";
|
|
10
|
-
import {
|
|
10
|
+
import { ThemeToggleBase } from "./components/internal/ThemeToggle";
|
|
11
|
+
import { UseAuthService } from "./services/authService";
|
|
11
12
|
import { AppResult } from "./common/appResult";
|
|
12
13
|
|
|
13
14
|
import { Cor, Tamanho } from "./enum";
|
|
@@ -24,8 +25,8 @@ export {
|
|
|
24
25
|
SfContent,
|
|
25
26
|
SfTabNavigation,
|
|
26
27
|
SfButton,
|
|
27
|
-
AuthService,
|
|
28
28
|
AppResult,
|
|
29
|
+
UseAuthService,
|
|
29
30
|
UseNavMenuService,
|
|
30
31
|
UseDialogService,
|
|
31
32
|
Cor,
|
|
@@ -52,8 +53,6 @@ export {
|
|
|
52
53
|
window.addEventListener("resize", Ajusta);
|
|
53
54
|
})();
|
|
54
55
|
|
|
55
|
-
import { ThemeToggleBase } from "./components/internal/ThemeToggle";
|
|
56
|
-
|
|
57
56
|
/**
|
|
58
57
|
* Tema inicial
|
|
59
58
|
*/
|
package/src/keycloak.js
CHANGED
|
@@ -23,17 +23,12 @@
|
|
|
23
23
|
*
|
|
24
24
|
* Adaptado para expor setToken.
|
|
25
25
|
*
|
|
26
|
-
* Adpatado para usar URL absoluta em configUrl (linha 829).
|
|
27
|
-
*
|
|
28
|
-
* Adaptado para usar dotenv.
|
|
26
|
+
* Adpatado para usar URL absoluta em configUrl (linha 829). *
|
|
29
27
|
*/
|
|
30
28
|
|
|
31
29
|
import base64 from 'base64-js';
|
|
32
30
|
import sha256 from 'js-sha256';
|
|
33
31
|
import { jwtDecode } from 'jwt-decode';
|
|
34
|
-
import * as dotenv from "dotenv";
|
|
35
|
-
|
|
36
|
-
dotenv.config();
|
|
37
32
|
|
|
38
33
|
if (typeof Promise === 'undefined') {
|
|
39
34
|
throw Error('Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.');
|
|
@@ -830,17 +825,11 @@ function Keycloak (config) {
|
|
|
830
825
|
var promise = createPromise();
|
|
831
826
|
var configUrl;
|
|
832
827
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
// Alterado para usar dotenv
|
|
840
|
-
|
|
841
|
-
kc.authServerUrl = process.env.AUTHSERVICE_URL;
|
|
842
|
-
kc.realm = process.env.AUTHSERVICE_REALM;
|
|
843
|
-
kc.clientId = process.env.AUTHSERVICE_CLIENTID;
|
|
828
|
+
if (!config) {
|
|
829
|
+
configUrl = location.origin + '/keycloak.json';
|
|
830
|
+
} else if (typeof config === 'string') {
|
|
831
|
+
configUrl = config;
|
|
832
|
+
}
|
|
844
833
|
|
|
845
834
|
function setupOidcEndoints(oidcConfiguration) {
|
|
846
835
|
if (! oidcConfiguration) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Keycloak from "./../keycloak";
|
|
1
|
+
import Keycloak, { KeycloakConfig } from "./../keycloak";
|
|
2
2
|
|
|
3
3
|
interface User {
|
|
4
4
|
name: string;
|
|
@@ -13,65 +13,64 @@ interface User {
|
|
|
13
13
|
IsInRole: (role: string) => boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
function AuthService(config: KeycloakConfig) {
|
|
17
|
+
const keycloakInstance = new Keycloak(config);
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
onSuccess: () => void,
|
|
20
|
-
onError: (error: any) => void
|
|
21
|
-
) => {
|
|
22
|
-
keycloakInstance
|
|
23
|
-
.init({ onLoad: "login-required" })
|
|
24
|
-
.then(async (authenticated) => {
|
|
25
|
-
if (authenticated) {
|
|
26
|
-
await FetchUserInfo();
|
|
27
|
-
}
|
|
28
|
-
onSuccess();
|
|
29
|
-
})
|
|
30
|
-
.catch((e: any) => {
|
|
31
|
-
onError(e);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
19
|
+
const User: User = {} as User;
|
|
34
20
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
const Login = (
|
|
22
|
+
onSuccess: () => void,
|
|
23
|
+
onError: (error: any) => void
|
|
24
|
+
) => {
|
|
25
|
+
keycloakInstance
|
|
26
|
+
.init({ onLoad: "login-required" })
|
|
27
|
+
.then(async (authenticated) => {
|
|
28
|
+
if (authenticated) {
|
|
29
|
+
await FetchUserInfo();
|
|
30
|
+
}
|
|
31
|
+
onSuccess();
|
|
32
|
+
})
|
|
33
|
+
.catch((e: any) => {
|
|
34
|
+
onError(e);
|
|
35
|
+
});
|
|
48
36
|
};
|
|
49
|
-
};
|
|
50
37
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
const FetchUserInfo = async () => {
|
|
39
|
+
const info: any = await keycloakInstance.loadUserInfo();
|
|
40
|
+
User.email = info.email ?? "";
|
|
41
|
+
User.emailVerified = info.email_verified === true;
|
|
42
|
+
User.firstName = info.given_name ?? "";
|
|
43
|
+
User.lastName = info.family_name ?? "";
|
|
44
|
+
User.name = info.name ?? "";
|
|
45
|
+
User.sub = info.sub ?? "";
|
|
46
|
+
User.username = info.preferred_username ?? "";
|
|
47
|
+
User.roles = [...(info.role ?? [])];
|
|
48
|
+
User.groups = [...(info.group ?? [])];
|
|
49
|
+
User.IsInRole = (role: string) => {
|
|
50
|
+
return User.roles.includes(role);
|
|
51
|
+
};
|
|
52
|
+
sessionStorage.setItem("name", User.name);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const Logout = () => {
|
|
56
|
+
keycloakInstance
|
|
57
|
+
.logout({
|
|
58
|
+
redirectUri: location.origin,
|
|
59
|
+
})
|
|
60
|
+
.then(() => {
|
|
61
|
+
sessionStorage.removeItem("name");
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
Instance: keycloakInstance,
|
|
67
|
+
User,
|
|
68
|
+
CallLogin: Login,
|
|
69
|
+
CallLogout: Logout,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
60
72
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
User: {} as User,
|
|
64
|
-
SetUrl: (url: string) => {
|
|
65
|
-
keycloakInstance.authServerUrl = url;
|
|
66
|
-
},
|
|
67
|
-
SetRealm: (realm: string) => {
|
|
68
|
-
keycloakInstance.realm = realm;
|
|
69
|
-
},
|
|
70
|
-
SetClientId: (clientId: string) => {
|
|
71
|
-
keycloakInstance.clientId = clientId;
|
|
72
|
-
},
|
|
73
|
-
CallLogin: Login,
|
|
74
|
-
CallLogout: Logout,
|
|
75
|
-
};
|
|
73
|
+
const UseAuthService = (config: KeycloakConfig) =>
|
|
74
|
+
AuthService(config);
|
|
76
75
|
|
|
77
|
-
export {
|
|
76
|
+
export { UseAuthService };
|