@sedoo/unidoo 0.1.8 → 0.1.10

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/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@sedoo/unidoo",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "private": false,
5
5
  "scripts": {
6
- "build": "vue-cli-service build --target lib --name unidoo src/plugin.js",
6
+ "build": "npm run build:unidoo && npm run build:auth",
7
+ "build:unidoo": "vue-cli-service build --target lib --dest dist/unidoo --name unidoo src/plugin.js",
8
+ "build:auth": "vue-cli-service build --target lib --dest dist/auth --name auth src/auth.js",
7
9
  "lint": "vue-cli-service lint --fix && vue-cli-service lint dev --fix",
8
10
  "docs:dev": "vuepress dev docs",
9
11
  "docs:build": "vuepress build docs"
10
12
  },
11
13
  "comments": {
12
- "scripts": "The npm run build is used by github for publishing. It musn't be removed"
14
+ "scripts": "The build and docs:build script are used in the continuous integration process. They musn't be removed."
13
15
  },
14
16
  "files": [
15
17
  "dist",
@@ -18,6 +20,7 @@
18
20
  "dependencies": {
19
21
  "date-fns": "^2.28.0",
20
22
  "date-fns-tz": "^1.3.6",
23
+ "keycloak-js": "^8.0.2",
21
24
  "ol": "^6.8.1",
22
25
  "v-tooltip": "^2.1.3",
23
26
  "vue-axios": "3.2.4"
@@ -77,11 +80,11 @@
77
80
  "module": "./dist/unidoo.umd.min.js",
78
81
  "repository": {
79
82
  "type": "git",
80
- "url": "git+https://github.com/sedoo/unidoo.git"
83
+ "url": "git+https://gitlab.in2p3.fr/sedoo/unidoo.git"
81
84
  },
82
85
  "author": "SEDOO",
83
86
  "bugs": {
84
- "url": "https://github.com/sedoo/unidoo/issues"
87
+ "url": "https://gitlab.in2p3.fr/sedoo/unidoo/-/issues"
85
88
  },
86
- "homepage": "https://github.com/sedoo/unidoo#readme"
89
+ "homepage": "https://sedoo.pages.in2p3.fr/unidoo"
87
90
  }
package/src/auth.js ADDED
@@ -0,0 +1,87 @@
1
+ import { isEmpty } from "lodash";
2
+ import Keycloak from "keycloak-js";
3
+
4
+ const SedooKeycloak = {
5
+ install(Vue, { axios }) {
6
+ if (this.installed) return;
7
+ this.installed = true;
8
+
9
+ Vue.prototype.$initSedooKeycloak = async (options) => {
10
+ handleErrors(options);
11
+
12
+ let defaultOptions = {
13
+ ssoParams: {}
14
+ };
15
+ defaultOptions = { ...options };
16
+
17
+ const keycloak = Keycloak(defaultOptions.ssoParams);
18
+ Vue.prototype.$keycloak = keycloak;
19
+
20
+ keycloak
21
+ .init({
22
+ onLoad: "check-sso",
23
+ promiseType: "native",
24
+ checkLoginIframe: false
25
+ })
26
+ .then(() => {
27
+ // Intercepteur qui ajoute le token aux requêtes
28
+ interceptRequests(
29
+ axios,
30
+ defaultOptions.ssoParams.authorizedDomains,
31
+ keycloak.token
32
+ );
33
+ updateSSoToken(keycloak);
34
+ });
35
+ };
36
+ }
37
+ };
38
+
39
+ export default SedooKeycloak;
40
+
41
+ function handleErrors(options) {
42
+ if (!options.ssoParams || Object.keys(options.ssoParams).length === 0) {
43
+ throw new Error(
44
+ "You need to provide sso parameters for the plugin to work."
45
+ );
46
+ }
47
+
48
+ const someParametersAreNull = Object.values(
49
+ options.ssoParams
50
+ ).some((parameter) => isEmpty(parameter));
51
+
52
+ if (someParametersAreNull) {
53
+ const emptyProperties = [];
54
+ for (const property in options.ssoParams) {
55
+ if (isEmpty(options.ssoParams[property])) {
56
+ emptyProperties.push(property);
57
+ }
58
+ }
59
+
60
+ throw new Error(
61
+ `The following properties are required : ${emptyProperties.join(", ")}`
62
+ );
63
+ }
64
+ }
65
+
66
+ function updateSSoToken(keycloak) {
67
+ setTimeout(function() {
68
+ keycloak.updateToken(200000);
69
+ updateSSoToken(keycloak);
70
+ }, 200000);
71
+ }
72
+
73
+ function interceptRequests(axios, authorizedDomains, token) {
74
+ axios.interceptors.request.use(
75
+ (config) => {
76
+ if (
77
+ authorizedDomains.some((url) => config.url.startsWith(url)) &&
78
+ token
79
+ ) {
80
+ config.headers.Authorization = "Bearer " + token;
81
+ config.headers.Accept = "application/json, text/plain, */*";
82
+ }
83
+ return config;
84
+ },
85
+ (error) => Promise.reject(error)
86
+ );
87
+ }
File without changes
File without changes