@ghentcdh/authentication-vue 0.0.2-13 → 0.0.2-14
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/README.md +4 -2
- package/index.mjs +250 -246
- package/lib/request.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,9 +64,11 @@ await isAuthenticated();
|
|
|
64
64
|
```vue
|
|
65
65
|
|
|
66
66
|
<script setup lang="ts">
|
|
67
|
-
import {
|
|
67
|
+
import { useHttpRequest } from "@ghentcdh/authentication/vue";
|
|
68
|
+
|
|
69
|
+
const httpRequest = useHttpRequest();
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
httpRequest.post('/api/auth/login', {}).then(response => {
|
|
70
72
|
alert('login ok')
|
|
71
73
|
});
|
|
72
74
|
</script>
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
const
|
|
3
|
-
function
|
|
4
|
-
if (!(this instanceof
|
|
1
|
+
import { ref as ne, markRaw as oe, watch as ae, inject as se } from "vue";
|
|
2
|
+
const B = "GHENTCDH_AUTHENTICATION";
|
|
3
|
+
function X(p) {
|
|
4
|
+
if (!(this instanceof X))
|
|
5
5
|
throw new Error("The 'Keycloak' constructor must be invoked with 'new'.");
|
|
6
6
|
if (typeof p != "string" && !z(p))
|
|
7
7
|
throw new Error("The 'Keycloak' constructor must be provided with a configuration object, or a URL to a JSON configuration file.");
|
|
@@ -11,14 +11,14 @@ function W(p) {
|
|
|
11
11
|
if (!p[t])
|
|
12
12
|
throw new Error(`The configuration object is missing the required '${t}' property.`);
|
|
13
13
|
}
|
|
14
|
-
var e = this,
|
|
14
|
+
var e = this, d, m = [], k, h = {
|
|
15
15
|
enable: !0,
|
|
16
16
|
callbackList: [],
|
|
17
17
|
interval: 5
|
|
18
18
|
};
|
|
19
19
|
e.didInitialize = !1;
|
|
20
|
-
var
|
|
21
|
-
globalThis.isSecureContext ||
|
|
20
|
+
var S = !0, y = q(console.info), U = q(console.warn);
|
|
21
|
+
globalThis.isSecureContext || U(
|
|
22
22
|
`[KEYCLOAK] Keycloak JS must be used in a 'secure context' to function properly as it relies on browser APIs that are otherwise not available.
|
|
23
23
|
Continuing to run your application insecurely will lead to unexpected behavior and breakage.
|
|
24
24
|
|
|
@@ -26,9 +26,9 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
26
26
|
), e.init = function(r = {}) {
|
|
27
27
|
if (e.didInitialize)
|
|
28
28
|
throw new Error("A 'Keycloak' instance can only be initialized once.");
|
|
29
|
-
e.didInitialize = !0, e.authenticated = !1,
|
|
29
|
+
e.didInitialize = !0, e.authenticated = !1, k = te();
|
|
30
30
|
var t = ["default", "cordova", "cordova-native"];
|
|
31
|
-
if (t.indexOf(r.adapter) > -1 ?
|
|
31
|
+
if (t.indexOf(r.adapter) > -1 ? d = H(r.adapter) : typeof r.adapter == "object" ? d = r.adapter : window.Cordova || window.cordova ? d = H("cordova") : d = H(), typeof r.useNonce < "u" && (S = r.useNonce), typeof r.checkLoginIframe < "u" && (h.enable = r.checkLoginIframe), r.checkLoginIframeInterval && (h.interval = r.checkLoginIframeInterval), r.onLoad === "login-required" && (e.loginRequired = !0), r.responseMode)
|
|
32
32
|
if (r.responseMode === "query" || r.responseMode === "fragment")
|
|
33
33
|
e.responseMode = r.responseMode;
|
|
34
34
|
else
|
|
@@ -56,38 +56,38 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
56
56
|
} else
|
|
57
57
|
e.pkceMethod = "S256";
|
|
58
58
|
typeof r.enableLogging == "boolean" ? e.enableLogging = r.enableLogging : e.enableLogging = !1, r.logoutMethod === "POST" ? e.logoutMethod = "POST" : e.logoutMethod = "GET", typeof r.scope == "string" && (e.scope = r.scope), typeof r.acrValues == "string" && (e.acrValues = r.acrValues), typeof r.messageReceiveTimeout == "number" && r.messageReceiveTimeout > 0 ? e.messageReceiveTimeout = r.messageReceiveTimeout : e.messageReceiveTimeout = 1e4, e.responseMode || (e.responseMode = "fragment"), e.responseType || (e.responseType = "code", e.flow = "standard");
|
|
59
|
-
var i =
|
|
59
|
+
var i = v(), s = v();
|
|
60
60
|
s.promise.then(function() {
|
|
61
61
|
e.onReady && e.onReady(e.authenticated), i.setSuccess(e.authenticated);
|
|
62
62
|
}).catch(function(o) {
|
|
63
63
|
i.setError(o);
|
|
64
64
|
});
|
|
65
|
-
var a =
|
|
65
|
+
var a = Q();
|
|
66
66
|
function c() {
|
|
67
|
-
var o = function(
|
|
68
|
-
|
|
67
|
+
var o = function(l) {
|
|
68
|
+
l || (f.prompt = "none"), r.locale && (f.locale = r.locale), e.login(f).then(function() {
|
|
69
69
|
s.setSuccess();
|
|
70
|
-
}).catch(function(
|
|
71
|
-
s.setError(
|
|
70
|
+
}).catch(function(g) {
|
|
71
|
+
s.setError(g);
|
|
72
72
|
});
|
|
73
73
|
}, u = async function() {
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
var b = function(
|
|
77
|
-
if (!(
|
|
78
|
-
var
|
|
79
|
-
E(
|
|
74
|
+
var l = document.createElement("iframe"), g = await e.createLoginUrl({ prompt: "none", redirectUri: e.silentCheckSsoRedirectUri });
|
|
75
|
+
l.setAttribute("src", g), l.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), l.setAttribute("title", "keycloak-silent-check-sso"), l.style.display = "none", document.body.appendChild(l);
|
|
76
|
+
var b = function(I) {
|
|
77
|
+
if (!(I.origin !== window.location.origin || l.contentWindow !== I.source)) {
|
|
78
|
+
var _ = A(I.data);
|
|
79
|
+
E(_, s), document.body.removeChild(l), window.removeEventListener("message", b);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
window.addEventListener("message", b);
|
|
83
83
|
}, f = {};
|
|
84
84
|
switch (r.onLoad) {
|
|
85
85
|
case "check-sso":
|
|
86
|
-
h.enable ?
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}).catch(function(
|
|
90
|
-
s.setError(
|
|
86
|
+
h.enable ? K().then(function() {
|
|
87
|
+
x().then(function(l) {
|
|
88
|
+
l ? s.setSuccess() : e.silentCheckSsoRedirectUri ? u() : o(!1);
|
|
89
|
+
}).catch(function(l) {
|
|
90
|
+
s.setError(l);
|
|
91
91
|
});
|
|
92
92
|
}) : e.silentCheckSsoRedirectUri ? u() : o(!1);
|
|
93
93
|
break;
|
|
@@ -101,13 +101,13 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
101
101
|
function n() {
|
|
102
102
|
var o = A(window.location.href);
|
|
103
103
|
if (o && window.history.replaceState(window.history.state, null, o.newUrl), o && o.valid)
|
|
104
|
-
return
|
|
104
|
+
return K().then(function() {
|
|
105
105
|
E(o, s);
|
|
106
106
|
}).catch(function(u) {
|
|
107
107
|
s.setError(u);
|
|
108
108
|
});
|
|
109
|
-
r.token && r.refreshToken ? (
|
|
110
|
-
|
|
109
|
+
r.token && r.refreshToken ? (R(r.token, r.refreshToken, r.idToken), h.enable ? K().then(function() {
|
|
110
|
+
x().then(function(u) {
|
|
111
111
|
u ? (e.onAuthSuccess && e.onAuthSuccess(), s.setSuccess(), N()) : s.setSuccess();
|
|
112
112
|
}).catch(function(u) {
|
|
113
113
|
s.setError(u);
|
|
@@ -119,14 +119,14 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
119
119
|
})) : r.onLoad ? c() : s.setSuccess();
|
|
120
120
|
}
|
|
121
121
|
return a.then(function() {
|
|
122
|
-
|
|
122
|
+
re().then(n).catch(function(o) {
|
|
123
123
|
i.setError(o);
|
|
124
124
|
});
|
|
125
125
|
}), a.catch(function(o) {
|
|
126
126
|
i.setError(o);
|
|
127
127
|
}), i.promise;
|
|
128
128
|
}, e.login = function(r) {
|
|
129
|
-
return
|
|
129
|
+
return d.login(r);
|
|
130
130
|
};
|
|
131
131
|
function C(r) {
|
|
132
132
|
if (typeof crypto > "u" || typeof crypto.getRandomValues > "u")
|
|
@@ -134,20 +134,20 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
134
134
|
return crypto.getRandomValues(new Uint8Array(r));
|
|
135
135
|
}
|
|
136
136
|
function w(r) {
|
|
137
|
-
return
|
|
137
|
+
return P(r, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function P(r, t) {
|
|
140
140
|
for (var i = C(r), s = new Array(r), a = 0; a < r; a++)
|
|
141
141
|
s[a] = t.charCodeAt(i[a] % t.length);
|
|
142
142
|
return String.fromCharCode.apply(null, s);
|
|
143
143
|
}
|
|
144
|
-
async function
|
|
144
|
+
async function M(r, t) {
|
|
145
145
|
if (r !== "S256")
|
|
146
146
|
throw new TypeError(`Invalid value for 'pkceMethod', expected 'S256' but got '${r}'.`);
|
|
147
|
-
const i = new Uint8Array(await
|
|
148
|
-
return
|
|
147
|
+
const i = new Uint8Array(await ce(t));
|
|
148
|
+
return ie(i).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function W(r) {
|
|
151
151
|
var t = {
|
|
152
152
|
id_token: {
|
|
153
153
|
acr: r
|
|
@@ -156,7 +156,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
156
156
|
return JSON.stringify(t);
|
|
157
157
|
}
|
|
158
158
|
e.createLoginUrl = async function(r) {
|
|
159
|
-
var t =
|
|
159
|
+
var t = F(), i = F(), s = d.redirectUri(r), a = {
|
|
160
160
|
state: t,
|
|
161
161
|
nonce: i,
|
|
162
162
|
redirectUri: encodeURIComponent(s),
|
|
@@ -168,34 +168,34 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
168
168
|
var n = r && r.scope || e.scope;
|
|
169
169
|
n ? n.indexOf("openid") === -1 && (n = "openid " + n) : n = "openid";
|
|
170
170
|
var o = c + "?client_id=" + encodeURIComponent(e.clientId) + "&redirect_uri=" + encodeURIComponent(s) + "&state=" + encodeURIComponent(t) + "&response_mode=" + encodeURIComponent(e.responseMode) + "&response_type=" + encodeURIComponent(e.responseType) + "&scope=" + encodeURIComponent(n);
|
|
171
|
-
if (
|
|
172
|
-
var u =
|
|
171
|
+
if (S && (o = o + "&nonce=" + encodeURIComponent(i)), r && r.prompt && (o += "&prompt=" + encodeURIComponent(r.prompt)), r && typeof r.maxAge == "number" && (o += "&max_age=" + encodeURIComponent(r.maxAge)), r && r.loginHint && (o += "&login_hint=" + encodeURIComponent(r.loginHint)), r && r.idpHint && (o += "&kc_idp_hint=" + encodeURIComponent(r.idpHint)), r && r.action && r.action != "register" && (o += "&kc_action=" + encodeURIComponent(r.action)), r && r.locale && (o += "&ui_locales=" + encodeURIComponent(r.locale)), r && r.acr) {
|
|
172
|
+
var u = W(r.acr);
|
|
173
173
|
o += "&claims=" + encodeURIComponent(u);
|
|
174
174
|
}
|
|
175
175
|
if ((r && r.acrValues || e.acrValues) && (o += "&acr_values=" + encodeURIComponent(r.acrValues || e.acrValues)), e.pkceMethod)
|
|
176
176
|
try {
|
|
177
|
-
const f = w(96),
|
|
178
|
-
a.pkceCodeVerifier = f, o += "&code_challenge=" +
|
|
177
|
+
const f = w(96), l = await M(e.pkceMethod, f);
|
|
178
|
+
a.pkceCodeVerifier = f, o += "&code_challenge=" + l, o += "&code_challenge_method=" + e.pkceMethod;
|
|
179
179
|
} catch (f) {
|
|
180
180
|
throw new Error("Failed to generate PKCE challenge.", { cause: f });
|
|
181
181
|
}
|
|
182
|
-
return
|
|
182
|
+
return k.add(a), o;
|
|
183
183
|
}, e.logout = function(r) {
|
|
184
|
-
return
|
|
184
|
+
return d.logout(r);
|
|
185
185
|
}, e.createLogoutUrl = function(r) {
|
|
186
186
|
if (((r == null ? void 0 : r.logoutMethod) ?? e.logoutMethod) === "POST")
|
|
187
187
|
return e.endpoints.logout();
|
|
188
|
-
var i = e.endpoints.logout() + "?client_id=" + encodeURIComponent(e.clientId) + "&post_logout_redirect_uri=" + encodeURIComponent(
|
|
188
|
+
var i = e.endpoints.logout() + "?client_id=" + encodeURIComponent(e.clientId) + "&post_logout_redirect_uri=" + encodeURIComponent(d.redirectUri(r, !1));
|
|
189
189
|
return e.idToken && (i += "&id_token_hint=" + encodeURIComponent(e.idToken)), i;
|
|
190
190
|
}, e.register = function(r) {
|
|
191
|
-
return
|
|
191
|
+
return d.register(r);
|
|
192
192
|
}, e.createRegisterUrl = async function(r) {
|
|
193
193
|
return r || (r = {}), r.action = "register", await e.createLoginUrl(r);
|
|
194
194
|
}, e.createAccountUrl = function(r) {
|
|
195
|
-
var t =
|
|
196
|
-
return typeof t < "u" && (i = t + "/account?referrer=" + encodeURIComponent(e.clientId) + "&referrer_uri=" + encodeURIComponent(
|
|
195
|
+
var t = T(), i = void 0;
|
|
196
|
+
return typeof t < "u" && (i = t + "/account?referrer=" + encodeURIComponent(e.clientId) + "&referrer_uri=" + encodeURIComponent(d.redirectUri(r))), i;
|
|
197
197
|
}, e.accountManagement = function() {
|
|
198
|
-
return
|
|
198
|
+
return d.accountManagement();
|
|
199
199
|
}, e.hasRealmRole = function(r) {
|
|
200
200
|
var t = e.realmAccess;
|
|
201
201
|
return !!t && t.roles.indexOf(r) >= 0;
|
|
@@ -205,16 +205,16 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
205
205
|
var i = e.resourceAccess[t || e.clientId];
|
|
206
206
|
return !!i && i.roles.indexOf(r) >= 0;
|
|
207
207
|
}, e.loadUserProfile = function() {
|
|
208
|
-
var r =
|
|
208
|
+
var r = T() + "/account", t = new XMLHttpRequest();
|
|
209
209
|
t.open("GET", r, !0), t.setRequestHeader("Accept", "application/json"), t.setRequestHeader("Authorization", "bearer " + e.token);
|
|
210
|
-
var i =
|
|
210
|
+
var i = v();
|
|
211
211
|
return t.onreadystatechange = function() {
|
|
212
212
|
t.readyState == 4 && (t.status == 200 ? (e.profile = JSON.parse(t.responseText), i.setSuccess(e.profile)) : i.setError());
|
|
213
213
|
}, t.send(), i.promise;
|
|
214
214
|
}, e.loadUserInfo = function() {
|
|
215
215
|
var r = e.endpoints.userinfo(), t = new XMLHttpRequest();
|
|
216
216
|
t.open("GET", r, !0), t.setRequestHeader("Accept", "application/json"), t.setRequestHeader("Authorization", "bearer " + e.token);
|
|
217
|
-
var i =
|
|
217
|
+
var i = v();
|
|
218
218
|
return t.onreadystatechange = function() {
|
|
219
219
|
t.readyState == 4 && (t.status == 200 ? (e.userInfo = JSON.parse(t.responseText), i.setSuccess(e.userInfo)) : i.setError());
|
|
220
220
|
}, t.send(), i.promise;
|
|
@@ -231,7 +231,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
231
231
|
}
|
|
232
232
|
return t < 0;
|
|
233
233
|
}, e.updateToken = function(r) {
|
|
234
|
-
var t =
|
|
234
|
+
var t = v();
|
|
235
235
|
if (!e.refreshToken)
|
|
236
236
|
return t.setError(), t.promise;
|
|
237
237
|
r = r || 5;
|
|
@@ -250,20 +250,20 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
250
250
|
if (o.status == 200) {
|
|
251
251
|
y("[KEYCLOAK] Token refreshed"), u = (u + (/* @__PURE__ */ new Date()).getTime()) / 2;
|
|
252
252
|
var f = JSON.parse(o.responseText);
|
|
253
|
-
|
|
254
|
-
for (var
|
|
255
|
-
|
|
253
|
+
R(f.access_token, f.refresh_token, f.id_token, u), e.onAuthRefreshSuccess && e.onAuthRefreshSuccess();
|
|
254
|
+
for (var l = m.pop(); l != null; l = m.pop())
|
|
255
|
+
l.setSuccess(!0);
|
|
256
256
|
} else {
|
|
257
|
-
|
|
258
|
-
for (var
|
|
259
|
-
|
|
257
|
+
U("[KEYCLOAK] Failed to refresh token"), o.status == 400 && e.clearToken(), e.onAuthRefreshError && e.onAuthRefreshError();
|
|
258
|
+
for (var l = m.pop(); l != null; l = m.pop())
|
|
259
|
+
l.setError("Failed to refresh token: An unexpected HTTP error occurred while attempting to refresh the token.");
|
|
260
260
|
}
|
|
261
261
|
}, o.send(c);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
265
|
if (h.enable) {
|
|
266
|
-
var s =
|
|
266
|
+
var s = x();
|
|
267
267
|
s.then(function() {
|
|
268
268
|
i();
|
|
269
269
|
}).catch(function(a) {
|
|
@@ -273,13 +273,13 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
273
273
|
i();
|
|
274
274
|
return t.promise;
|
|
275
275
|
}, e.clearToken = function() {
|
|
276
|
-
e.token && (
|
|
276
|
+
e.token && (R(null, null, null), e.onAuthLogout && e.onAuthLogout(), e.loginRequired && e.login());
|
|
277
277
|
};
|
|
278
|
-
function
|
|
278
|
+
function T() {
|
|
279
279
|
if (typeof e.authServerUrl < "u")
|
|
280
280
|
return e.authServerUrl.charAt(e.authServerUrl.length - 1) == "/" ? e.authServerUrl + "realms/" + encodeURIComponent(e.realm) : e.authServerUrl + "/realms/" + encodeURIComponent(e.realm);
|
|
281
281
|
}
|
|
282
|
-
function
|
|
282
|
+
function $() {
|
|
283
283
|
return window.location.origin ? window.location.origin : window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
|
|
284
284
|
}
|
|
285
285
|
function E(r, t) {
|
|
@@ -295,24 +295,24 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
295
295
|
else
|
|
296
296
|
t && t.setSuccess();
|
|
297
297
|
return;
|
|
298
|
-
} else e.flow != "standard" && (r.access_token || r.id_token) &&
|
|
298
|
+
} else e.flow != "standard" && (r.access_token || r.id_token) && l(r.access_token, null, r.id_token, !0);
|
|
299
299
|
if (e.flow != "implicit" && i) {
|
|
300
300
|
var o = "code=" + i + "&grant_type=authorization_code", u = e.endpoints.token(), f = new XMLHttpRequest();
|
|
301
301
|
f.open("POST", u, !0), f.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), o += "&client_id=" + encodeURIComponent(e.clientId), o += "&redirect_uri=" + r.redirectUri, r.pkceCodeVerifier && (o += "&code_verifier=" + r.pkceCodeVerifier), f.withCredentials = !0, f.onreadystatechange = function() {
|
|
302
302
|
if (f.readyState == 4)
|
|
303
303
|
if (f.status == 200) {
|
|
304
|
-
var
|
|
305
|
-
|
|
304
|
+
var g = JSON.parse(f.responseText);
|
|
305
|
+
l(g.access_token, g.refresh_token, g.id_token, e.flow === "standard"), N();
|
|
306
306
|
} else
|
|
307
307
|
e.onAuthError && e.onAuthError(), t && t.setError();
|
|
308
308
|
}, f.send(o);
|
|
309
309
|
}
|
|
310
|
-
function
|
|
311
|
-
c = (c + (/* @__PURE__ */ new Date()).getTime()) / 2,
|
|
310
|
+
function l(g, b, I, _) {
|
|
311
|
+
c = (c + (/* @__PURE__ */ new Date()).getTime()) / 2, R(g, b, I, c), S && e.idTokenParsed && e.idTokenParsed.nonce != r.storedNonce ? (y("[KEYCLOAK] Invalid nonce, clearing token"), e.clearToken(), t && t.setError()) : _ && (e.onAuthSuccess && e.onAuthSuccess(), t && t.setSuccess());
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
function
|
|
315
|
-
var r =
|
|
314
|
+
function Q() {
|
|
315
|
+
var r = v(), t;
|
|
316
316
|
typeof p == "string" && (t = p);
|
|
317
317
|
function i(n) {
|
|
318
318
|
n ? e.endpoints = {
|
|
@@ -342,25 +342,25 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
342
342
|
}
|
|
343
343
|
} : e.endpoints = {
|
|
344
344
|
authorize: function() {
|
|
345
|
-
return
|
|
345
|
+
return T() + "/protocol/openid-connect/auth";
|
|
346
346
|
},
|
|
347
347
|
token: function() {
|
|
348
|
-
return
|
|
348
|
+
return T() + "/protocol/openid-connect/token";
|
|
349
349
|
},
|
|
350
350
|
logout: function() {
|
|
351
|
-
return
|
|
351
|
+
return T() + "/protocol/openid-connect/logout";
|
|
352
352
|
},
|
|
353
353
|
checkSessionIframe: function() {
|
|
354
|
-
return
|
|
354
|
+
return T() + "/protocol/openid-connect/login-status-iframe.html";
|
|
355
355
|
},
|
|
356
356
|
thirdPartyCookiesIframe: function() {
|
|
357
|
-
return
|
|
357
|
+
return T() + "/protocol/openid-connect/3p-cookies/step1.html";
|
|
358
358
|
},
|
|
359
359
|
register: function() {
|
|
360
|
-
return
|
|
360
|
+
return T() + "/protocol/openid-connect/registrations";
|
|
361
361
|
},
|
|
362
362
|
userinfo: function() {
|
|
363
|
-
return
|
|
363
|
+
return T() + "/protocol/openid-connect/userinfo";
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
366
|
}
|
|
@@ -368,7 +368,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
368
368
|
var s = new XMLHttpRequest();
|
|
369
369
|
s.open("GET", t, !0), s.setRequestHeader("Accept", "application/json"), s.onreadystatechange = function() {
|
|
370
370
|
if (s.readyState == 4)
|
|
371
|
-
if (s.status == 200 ||
|
|
371
|
+
if (s.status == 200 || Y(s)) {
|
|
372
372
|
var n = JSON.parse(s.responseText);
|
|
373
373
|
e.authServerUrl = n["auth-server-url"], e.realm = n.realm, e.clientId = n.resource, i(null), r.setSuccess();
|
|
374
374
|
} else
|
|
@@ -385,7 +385,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
385
385
|
var s = new XMLHttpRequest();
|
|
386
386
|
s.open("GET", c, !0), s.setRequestHeader("Accept", "application/json"), s.onreadystatechange = function() {
|
|
387
387
|
if (s.readyState == 4)
|
|
388
|
-
if (s.status == 200 ||
|
|
388
|
+
if (s.status == 200 || Y(s)) {
|
|
389
389
|
var o = JSON.parse(s.responseText);
|
|
390
390
|
i(o), r.setSuccess();
|
|
391
391
|
} else
|
|
@@ -396,31 +396,31 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
396
396
|
}
|
|
397
397
|
return r.promise;
|
|
398
398
|
}
|
|
399
|
-
function
|
|
399
|
+
function Y(r) {
|
|
400
400
|
return r.status == 0 && r.responseText && r.responseURL.startsWith("file:");
|
|
401
401
|
}
|
|
402
|
-
function
|
|
403
|
-
if (e.tokenTimeoutHandle && (clearTimeout(e.tokenTimeoutHandle), e.tokenTimeoutHandle = null), t ? (e.refreshToken = t, e.refreshTokenParsed =
|
|
404
|
-
if (e.token = r, e.tokenParsed =
|
|
402
|
+
function R(r, t, i, s) {
|
|
403
|
+
if (e.tokenTimeoutHandle && (clearTimeout(e.tokenTimeoutHandle), e.tokenTimeoutHandle = null), t ? (e.refreshToken = t, e.refreshTokenParsed = J(t)) : (delete e.refreshToken, delete e.refreshTokenParsed), i ? (e.idToken = i, e.idTokenParsed = J(i)) : (delete e.idToken, delete e.idTokenParsed), r) {
|
|
404
|
+
if (e.token = r, e.tokenParsed = J(r), e.sessionId = e.tokenParsed.sid, e.authenticated = !0, e.subject = e.tokenParsed.sub, e.realmAccess = e.tokenParsed.realm_access, e.resourceAccess = e.tokenParsed.resource_access, s && (e.timeSkew = Math.floor(s / 1e3) - e.tokenParsed.iat), e.timeSkew != null && (y("[KEYCLOAK] Estimated time difference between browser and server is " + e.timeSkew + " seconds"), e.onTokenExpired)) {
|
|
405
405
|
var a = (e.tokenParsed.exp - (/* @__PURE__ */ new Date()).getTime() / 1e3 + e.timeSkew) * 1e3;
|
|
406
406
|
y("[KEYCLOAK] Token expires in " + Math.round(a / 1e3) + " s"), a <= 0 ? e.onTokenExpired() : e.tokenTimeoutHandle = setTimeout(e.onTokenExpired, a);
|
|
407
407
|
}
|
|
408
408
|
} else
|
|
409
409
|
delete e.token, delete e.tokenParsed, delete e.subject, delete e.realmAccess, delete e.resourceAccess, e.authenticated = !1;
|
|
410
410
|
}
|
|
411
|
-
function
|
|
411
|
+
function F() {
|
|
412
412
|
if (typeof crypto > "u" || typeof crypto.randomUUID > "u")
|
|
413
413
|
throw new Error("Web Crypto API is not available.");
|
|
414
414
|
return crypto.randomUUID();
|
|
415
415
|
}
|
|
416
416
|
function A(r) {
|
|
417
|
-
var t =
|
|
417
|
+
var t = Z(r);
|
|
418
418
|
if (t) {
|
|
419
|
-
var i =
|
|
419
|
+
var i = k.get(t.state);
|
|
420
420
|
return i && (t.valid = !0, t.redirectUri = i.redirectUri, t.storedNonce = i.nonce, t.prompt = i.prompt, t.pkceCodeVerifier = i.pkceCodeVerifier, t.loginOptions = i.loginOptions), t;
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
function
|
|
423
|
+
function Z(r) {
|
|
424
424
|
var t;
|
|
425
425
|
switch (e.flow) {
|
|
426
426
|
case "standard":
|
|
@@ -435,7 +435,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
435
435
|
}
|
|
436
436
|
t.push("error"), t.push("error_description"), t.push("error_uri");
|
|
437
437
|
var i = r.indexOf("?"), s = r.indexOf("#"), a, c;
|
|
438
|
-
if (e.responseMode === "query" && i !== -1 ? (a = r.substring(0, i), c =
|
|
438
|
+
if (e.responseMode === "query" && i !== -1 ? (a = r.substring(0, i), c = G(r.substring(i + 1, s !== -1 ? s : r.length), t), c.paramsString !== "" && (a += "?" + c.paramsString), s !== -1 && (a += r.substring(s))) : e.responseMode === "fragment" && s !== -1 && (a = r.substring(0, s), c = G(r.substring(s + 1), t), c.paramsString !== "" && (a += "#" + c.paramsString)), c && c.oauthParams) {
|
|
439
439
|
if (e.flow === "standard" || e.flow === "hybrid") {
|
|
440
440
|
if ((c.oauthParams.code || c.oauthParams.error) && c.oauthParams.state)
|
|
441
441
|
return c.oauthParams.newUrl = a, c.oauthParams;
|
|
@@ -443,7 +443,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
443
443
|
return c.oauthParams.newUrl = a, c.oauthParams;
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
|
-
function
|
|
446
|
+
function G(r, t) {
|
|
447
447
|
for (var i = r.split("&"), s = {
|
|
448
448
|
paramsString: "",
|
|
449
449
|
oauthParams: {}
|
|
@@ -453,7 +453,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
453
453
|
}
|
|
454
454
|
return s;
|
|
455
455
|
}
|
|
456
|
-
function
|
|
456
|
+
function v() {
|
|
457
457
|
var r = {
|
|
458
458
|
setSuccess: function(t) {
|
|
459
459
|
r.resolve(t);
|
|
@@ -466,7 +466,7 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
466
466
|
r.resolve = t, r.reject = i;
|
|
467
467
|
}), r;
|
|
468
468
|
}
|
|
469
|
-
function
|
|
469
|
+
function ee(r, t, i) {
|
|
470
470
|
var s = null, a = new Promise(function(c, n) {
|
|
471
471
|
s = setTimeout(function() {
|
|
472
472
|
n({ error: i });
|
|
@@ -476,14 +476,14 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
476
476
|
clearTimeout(s);
|
|
477
477
|
});
|
|
478
478
|
}
|
|
479
|
-
function
|
|
480
|
-
var r =
|
|
479
|
+
function K() {
|
|
480
|
+
var r = v();
|
|
481
481
|
if (!h.enable || h.iframe)
|
|
482
482
|
return r.setSuccess(), r.promise;
|
|
483
483
|
var t = document.createElement("iframe");
|
|
484
484
|
h.iframe = t, t.onload = function() {
|
|
485
485
|
var a = e.endpoints.authorize();
|
|
486
|
-
a.charAt(0) === "/" ? h.iframeOrigin =
|
|
486
|
+
a.charAt(0) === "/" ? h.iframeOrigin = $() : h.iframeOrigin = a.substring(0, a.indexOf("/", 8)), r.setSuccess();
|
|
487
487
|
};
|
|
488
488
|
var i = e.endpoints.checkSessionIframe();
|
|
489
489
|
t.setAttribute("src", i), t.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), t.setAttribute("title", "keycloak-session-iframe"), t.style.display = "none", document.body.appendChild(t);
|
|
@@ -500,13 +500,13 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
500
500
|
}
|
|
501
501
|
function N() {
|
|
502
502
|
h.enable && e.token && setTimeout(function() {
|
|
503
|
-
|
|
503
|
+
x().then(function(r) {
|
|
504
504
|
r && N();
|
|
505
505
|
});
|
|
506
506
|
}, h.interval * 1e3);
|
|
507
507
|
}
|
|
508
|
-
function
|
|
509
|
-
var r =
|
|
508
|
+
function x() {
|
|
509
|
+
var r = v();
|
|
510
510
|
if (h.iframe && h.iframeOrigin) {
|
|
511
511
|
var t = e.clientId + " " + (e.sessionId ? e.sessionId : "");
|
|
512
512
|
h.callbackList.push(r);
|
|
@@ -516,13 +516,13 @@ For more information see: https://developer.mozilla.org/en-US/docs/Web/Security/
|
|
|
516
516
|
r.setSuccess();
|
|
517
517
|
return r.promise;
|
|
518
518
|
}
|
|
519
|
-
function
|
|
520
|
-
var r =
|
|
519
|
+
function re() {
|
|
520
|
+
var r = v();
|
|
521
521
|
if ((h.enable || e.silentCheckSsoRedirectUri) && typeof e.endpoints.thirdPartyCookiesIframe == "function") {
|
|
522
522
|
var t = document.createElement("iframe");
|
|
523
523
|
t.setAttribute("src", e.endpoints.thirdPartyCookiesIframe()), t.setAttribute("sandbox", "allow-storage-access-by-user-activation allow-scripts allow-same-origin"), t.setAttribute("title", "keycloak-3p-check-iframe"), t.style.display = "none", document.body.appendChild(t);
|
|
524
524
|
var i = function(s) {
|
|
525
|
-
t.contentWindow === s.source && (s.data !== "supported" && s.data !== "unsupported" || (s.data === "unsupported" && (
|
|
525
|
+
t.contentWindow === s.source && (s.data !== "supported" && s.data !== "unsupported" || (s.data === "unsupported" && (U(
|
|
526
526
|
`[KEYCLOAK] Your browser is blocking access to 3rd-party cookies, this means:
|
|
527
527
|
|
|
528
528
|
- It is not possible to retrieve tokens without redirecting to the Keycloak server (a.k.a. no support for silent authentication).
|
|
@@ -534,13 +534,13 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
534
534
|
window.addEventListener("message", i, !1);
|
|
535
535
|
} else
|
|
536
536
|
r.setSuccess();
|
|
537
|
-
return
|
|
537
|
+
return ee(r.promise, e.messageReceiveTimeout, "Timeout when waiting for 3rd party check iframe message.");
|
|
538
538
|
}
|
|
539
|
-
function
|
|
539
|
+
function H(r) {
|
|
540
540
|
if (!r || r == "default")
|
|
541
541
|
return {
|
|
542
542
|
login: async function(n) {
|
|
543
|
-
return window.location.assign(await e.createLoginUrl(n)),
|
|
543
|
+
return window.location.assign(await e.createLoginUrl(n)), v().promise;
|
|
544
544
|
},
|
|
545
545
|
logout: async function(n) {
|
|
546
546
|
if (((n == null ? void 0 : n.logoutMethod) ?? e.logoutMethod) === "GET") {
|
|
@@ -552,16 +552,16 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
552
552
|
const f = {
|
|
553
553
|
id_token_hint: e.idToken,
|
|
554
554
|
client_id: e.clientId,
|
|
555
|
-
post_logout_redirect_uri:
|
|
555
|
+
post_logout_redirect_uri: d.redirectUri(n, !1)
|
|
556
556
|
};
|
|
557
|
-
for (const [
|
|
557
|
+
for (const [l, g] of Object.entries(f)) {
|
|
558
558
|
const b = document.createElement("input");
|
|
559
|
-
b.setAttribute("type", "hidden"), b.setAttribute("name",
|
|
559
|
+
b.setAttribute("type", "hidden"), b.setAttribute("name", l), b.setAttribute("value", g), u.appendChild(b);
|
|
560
560
|
}
|
|
561
561
|
document.body.appendChild(u), u.submit();
|
|
562
562
|
},
|
|
563
563
|
register: async function(n) {
|
|
564
|
-
return window.location.assign(await e.createRegisterUrl(n)),
|
|
564
|
+
return window.location.assign(await e.createRegisterUrl(n)), v().promise;
|
|
565
565
|
},
|
|
566
566
|
accountManagement: function() {
|
|
567
567
|
var n = e.createAccountUrl();
|
|
@@ -569,7 +569,7 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
569
569
|
window.location.href = n;
|
|
570
570
|
else
|
|
571
571
|
throw "Not supported by the OIDC server";
|
|
572
|
-
return
|
|
572
|
+
return v().promise;
|
|
573
573
|
},
|
|
574
574
|
redirectUri: function(n, o) {
|
|
575
575
|
return n && n.redirectUri ? n.redirectUri : e.redirectUri ? e.redirectUri : location.href;
|
|
@@ -595,43 +595,43 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
595
595
|
};
|
|
596
596
|
return {
|
|
597
597
|
login: async function(n) {
|
|
598
|
-
var o =
|
|
599
|
-
b = !0,
|
|
598
|
+
var o = v(), u = a(n), f = await e.createLoginUrl(n), l = t(f, "_blank", u), g = !1, b = !1, I = function() {
|
|
599
|
+
b = !0, l.close();
|
|
600
600
|
};
|
|
601
|
-
return
|
|
602
|
-
if (
|
|
603
|
-
var
|
|
604
|
-
E(
|
|
601
|
+
return l.addEventListener("loadstart", function(_) {
|
|
602
|
+
if (_.url.indexOf(c()) == 0) {
|
|
603
|
+
var j = A(_.url);
|
|
604
|
+
E(j, o), I(), g = !0;
|
|
605
605
|
}
|
|
606
|
-
}),
|
|
607
|
-
if (!
|
|
608
|
-
if (
|
|
609
|
-
var
|
|
610
|
-
E(
|
|
606
|
+
}), l.addEventListener("loaderror", function(_) {
|
|
607
|
+
if (!g)
|
|
608
|
+
if (_.url.indexOf(c()) == 0) {
|
|
609
|
+
var j = A(_.url);
|
|
610
|
+
E(j, o), I(), g = !0;
|
|
611
611
|
} else
|
|
612
|
-
o.setError(),
|
|
613
|
-
}),
|
|
612
|
+
o.setError(), I();
|
|
613
|
+
}), l.addEventListener("exit", function(_) {
|
|
614
614
|
b || o.setError({
|
|
615
615
|
reason: "closed_by_user"
|
|
616
616
|
});
|
|
617
617
|
}), o.promise;
|
|
618
618
|
},
|
|
619
619
|
logout: function(n) {
|
|
620
|
-
var o =
|
|
621
|
-
return f.addEventListener("loadstart", function(
|
|
622
|
-
|
|
623
|
-
}), f.addEventListener("loaderror", function(
|
|
624
|
-
|
|
625
|
-
}), f.addEventListener("exit", function(
|
|
626
|
-
|
|
620
|
+
var o = v(), u = e.createLogoutUrl(n), f = t(u, "_blank", "location=no,hidden=yes,clearcache=yes"), l;
|
|
621
|
+
return f.addEventListener("loadstart", function(g) {
|
|
622
|
+
g.url.indexOf(c()) == 0 && f.close();
|
|
623
|
+
}), f.addEventListener("loaderror", function(g) {
|
|
624
|
+
g.url.indexOf(c()) == 0 || (l = !0), f.close();
|
|
625
|
+
}), f.addEventListener("exit", function(g) {
|
|
626
|
+
l ? o.setError() : (e.clearToken(), o.setSuccess());
|
|
627
627
|
}), o.promise;
|
|
628
628
|
},
|
|
629
629
|
register: async function(n) {
|
|
630
|
-
var o =
|
|
631
|
-
return
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
var b = A(
|
|
630
|
+
var o = v(), u = await e.createRegisterUrl(), f = a(n), l = t(u, "_blank", f);
|
|
631
|
+
return l.addEventListener("loadstart", function(g) {
|
|
632
|
+
if (g.url.indexOf(c()) == 0) {
|
|
633
|
+
l.close();
|
|
634
|
+
var b = A(g.url);
|
|
635
635
|
E(b, o);
|
|
636
636
|
}
|
|
637
637
|
}), o.promise;
|
|
@@ -654,25 +654,25 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
654
654
|
if (r == "cordova-native")
|
|
655
655
|
return h.enable = !1, {
|
|
656
656
|
login: async function(n) {
|
|
657
|
-
var o =
|
|
657
|
+
var o = v(), u = await e.createLoginUrl(n);
|
|
658
658
|
return universalLinks.subscribe("keycloak", function(f) {
|
|
659
659
|
universalLinks.unsubscribe("keycloak"), window.cordova.plugins.browsertab.close();
|
|
660
|
-
var
|
|
661
|
-
E(
|
|
660
|
+
var l = A(f.url);
|
|
661
|
+
E(l, o);
|
|
662
662
|
}), window.cordova.plugins.browsertab.openUrl(u), o.promise;
|
|
663
663
|
},
|
|
664
664
|
logout: function(n) {
|
|
665
|
-
var o =
|
|
665
|
+
var o = v(), u = e.createLogoutUrl(n);
|
|
666
666
|
return universalLinks.subscribe("keycloak", function(f) {
|
|
667
667
|
universalLinks.unsubscribe("keycloak"), window.cordova.plugins.browsertab.close(), e.clearToken(), o.setSuccess();
|
|
668
668
|
}), window.cordova.plugins.browsertab.openUrl(u), o.promise;
|
|
669
669
|
},
|
|
670
670
|
register: async function(n) {
|
|
671
|
-
var o =
|
|
671
|
+
var o = v(), u = await e.createRegisterUrl(n);
|
|
672
672
|
return universalLinks.subscribe("keycloak", function(f) {
|
|
673
673
|
universalLinks.unsubscribe("keycloak"), window.cordova.plugins.browsertab.close();
|
|
674
|
-
var
|
|
675
|
-
E(
|
|
674
|
+
var l = A(f.url);
|
|
675
|
+
E(l, o);
|
|
676
676
|
}), window.cordova.plugins.browsertab.openUrl(u), o.promise;
|
|
677
677
|
},
|
|
678
678
|
accountManagement: function() {
|
|
@@ -689,9 +689,9 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
689
689
|
throw "invalid adapter type: " + r;
|
|
690
690
|
}
|
|
691
691
|
const L = "kc-callback-";
|
|
692
|
-
var
|
|
693
|
-
if (!(this instanceof
|
|
694
|
-
return new
|
|
692
|
+
var D = function() {
|
|
693
|
+
if (!(this instanceof D))
|
|
694
|
+
return new D();
|
|
695
695
|
localStorage.setItem("kc-test", "test"), localStorage.removeItem("kc-test");
|
|
696
696
|
var r = this;
|
|
697
697
|
function t() {
|
|
@@ -735,9 +735,9 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
735
735
|
i(), localStorage.setItem(n, o);
|
|
736
736
|
}
|
|
737
737
|
};
|
|
738
|
-
},
|
|
739
|
-
if (!(this instanceof
|
|
740
|
-
return new
|
|
738
|
+
}, O = function() {
|
|
739
|
+
if (!(this instanceof O))
|
|
740
|
+
return new O();
|
|
741
741
|
var r = this;
|
|
742
742
|
r.get = function(a) {
|
|
743
743
|
if (a) {
|
|
@@ -766,46 +766,46 @@ For more information see: https://www.keycloak.org/securing-apps/javascript-adap
|
|
|
766
766
|
document.cookie = o;
|
|
767
767
|
};
|
|
768
768
|
};
|
|
769
|
-
function
|
|
769
|
+
function te() {
|
|
770
770
|
try {
|
|
771
|
-
return new
|
|
771
|
+
return new D();
|
|
772
772
|
} catch {
|
|
773
773
|
}
|
|
774
|
-
return new
|
|
774
|
+
return new O();
|
|
775
775
|
}
|
|
776
|
-
function
|
|
776
|
+
function q(r) {
|
|
777
777
|
return function() {
|
|
778
778
|
e.enableLogging && r.apply(console, Array.prototype.slice.call(arguments));
|
|
779
779
|
};
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
|
-
function
|
|
782
|
+
function ie(p) {
|
|
783
783
|
const e = String.fromCodePoint(...p);
|
|
784
784
|
return btoa(e);
|
|
785
785
|
}
|
|
786
|
-
async function
|
|
787
|
-
const
|
|
786
|
+
async function ce(p) {
|
|
787
|
+
const d = new TextEncoder().encode(p);
|
|
788
788
|
if (typeof crypto > "u" || typeof crypto.subtle > "u")
|
|
789
789
|
throw new Error("Web Crypto API is not available.");
|
|
790
|
-
return await crypto.subtle.digest("SHA-256",
|
|
790
|
+
return await crypto.subtle.digest("SHA-256", d);
|
|
791
791
|
}
|
|
792
|
-
function
|
|
793
|
-
const [e,
|
|
794
|
-
if (typeof
|
|
792
|
+
function J(p) {
|
|
793
|
+
const [e, d] = p.split(".");
|
|
794
|
+
if (typeof d != "string")
|
|
795
795
|
throw new Error("Unable to decode token, payload not found.");
|
|
796
796
|
let m;
|
|
797
797
|
try {
|
|
798
|
-
m =
|
|
799
|
-
} catch (
|
|
800
|
-
throw new Error("Unable to decode token, payload is not a valid Base64URL value.", { cause:
|
|
798
|
+
m = ue(d);
|
|
799
|
+
} catch (k) {
|
|
800
|
+
throw new Error("Unable to decode token, payload is not a valid Base64URL value.", { cause: k });
|
|
801
801
|
}
|
|
802
802
|
try {
|
|
803
803
|
return JSON.parse(m);
|
|
804
|
-
} catch (
|
|
805
|
-
throw new Error("Unable to decode token, payload is not a valid JSON value.", { cause:
|
|
804
|
+
} catch (k) {
|
|
805
|
+
throw new Error("Unable to decode token, payload is not a valid JSON value.", { cause: k });
|
|
806
806
|
}
|
|
807
807
|
}
|
|
808
|
-
function
|
|
808
|
+
function ue(p) {
|
|
809
809
|
let e = p.replaceAll("-", "+").replaceAll("_", "/");
|
|
810
810
|
switch (e.length % 4) {
|
|
811
811
|
case 0:
|
|
@@ -820,43 +820,42 @@ function le(p) {
|
|
|
820
820
|
throw new Error("Input is not of the correct length.");
|
|
821
821
|
}
|
|
822
822
|
try {
|
|
823
|
-
return
|
|
823
|
+
return le(e);
|
|
824
824
|
} catch {
|
|
825
825
|
return atob(e);
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
|
-
function
|
|
829
|
-
return decodeURIComponent(atob(p).replace(/(.)/g, (e,
|
|
830
|
-
let m =
|
|
828
|
+
function le(p) {
|
|
829
|
+
return decodeURIComponent(atob(p).replace(/(.)/g, (e, d) => {
|
|
830
|
+
let m = d.charCodeAt(0).toString(16).toUpperCase();
|
|
831
831
|
return m.length < 2 && (m = "0" + m), "%" + m;
|
|
832
832
|
}));
|
|
833
833
|
}
|
|
834
834
|
function z(p) {
|
|
835
835
|
return typeof p == "object" && p !== null;
|
|
836
836
|
}
|
|
837
|
-
const
|
|
838
|
-
class
|
|
837
|
+
const de = {};
|
|
838
|
+
class V extends X {
|
|
839
839
|
constructor() {
|
|
840
|
-
const { VITE_KEYCLOAK_REALM: e, VITE_KEYCLOAK_HOST:
|
|
840
|
+
const { VITE_KEYCLOAK_REALM: e, VITE_KEYCLOAK_HOST: d, VITE_KEYCLOAK_CLIENT_ID: m } = de;
|
|
841
841
|
super({
|
|
842
|
-
url:
|
|
842
|
+
url: d,
|
|
843
843
|
realm: e,
|
|
844
844
|
clientId: m
|
|
845
845
|
});
|
|
846
846
|
}
|
|
847
847
|
async initialize() {
|
|
848
848
|
try {
|
|
849
|
-
await this.init(
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
) && console.log("User is authenticated"), console.log("User is not authenticated");
|
|
849
|
+
const e = await this.init({
|
|
850
|
+
onLoad: "login-required"
|
|
851
|
+
});
|
|
852
|
+
console.log(e ? "User is authenticated" : "User is not authenticated");
|
|
854
853
|
} catch (e) {
|
|
855
854
|
console.error("Failed to initialize adapter:", e);
|
|
856
855
|
}
|
|
857
856
|
}
|
|
858
857
|
static async init() {
|
|
859
|
-
const e = new
|
|
858
|
+
const e = new V();
|
|
860
859
|
return await e.initialize(), e;
|
|
861
860
|
}
|
|
862
861
|
get userInfo() {
|
|
@@ -869,94 +868,99 @@ class Y extends W {
|
|
|
869
868
|
return this.authenticated ?? !1;
|
|
870
869
|
}
|
|
871
870
|
}
|
|
872
|
-
const
|
|
871
|
+
const fe = {
|
|
873
872
|
skipAuthentication: !1
|
|
874
|
-
},
|
|
875
|
-
const e =
|
|
876
|
-
let
|
|
877
|
-
const m = () =>
|
|
878
|
-
if (!
|
|
873
|
+
}, he = (p) => {
|
|
874
|
+
const e = ne(!1);
|
|
875
|
+
let d;
|
|
876
|
+
const m = () => V.init().then((w) => (d = w, e.value = !0, w)), k = () => d == null ? void 0 : d.token, h = async () => {
|
|
877
|
+
if (!d)
|
|
879
878
|
return m();
|
|
880
879
|
e.value || await new Promise((w) => {
|
|
881
|
-
const
|
|
882
|
-
|
|
880
|
+
const P = ae(e, (M) => {
|
|
881
|
+
M && (P(), w());
|
|
883
882
|
});
|
|
884
883
|
});
|
|
885
|
-
},
|
|
884
|
+
}, S = async () => {
|
|
886
885
|
var w;
|
|
887
886
|
return (w = await h()) == null ? void 0 : w.userInfo;
|
|
888
887
|
}, y = async () => {
|
|
889
888
|
var w;
|
|
890
889
|
return (w = await h()) == null ? void 0 : w.updateToken();
|
|
891
|
-
},
|
|
890
|
+
}, U = { ...fe, ...p }, C = oe({
|
|
892
891
|
install(w) {
|
|
893
|
-
w.config.globalProperties.$auth =
|
|
892
|
+
w.config.globalProperties.$auth = U, w.provide(B, C);
|
|
894
893
|
},
|
|
895
894
|
updateToken: y,
|
|
896
|
-
token:
|
|
897
|
-
user:
|
|
898
|
-
options:
|
|
895
|
+
token: k,
|
|
896
|
+
user: S,
|
|
897
|
+
options: U
|
|
899
898
|
});
|
|
900
899
|
return C;
|
|
901
|
-
},
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
900
|
+
}, me = () => {
|
|
901
|
+
const p = se(B);
|
|
902
|
+
p || console.warn("No auth provided, authorized calls may not work");
|
|
903
|
+
const e = async (d, m, k = { contentType: "application/json" }) => {
|
|
904
|
+
const h = (k == null ? void 0 : k.skipAuth) ?? (p == null ? void 0 : p.options.skipAuthentication), S = {
|
|
905
|
+
accept: "application/json",
|
|
906
|
+
...m.headers ?? {}
|
|
907
|
+
};
|
|
908
|
+
k.contentType && (S["Content-Type"] = k.contentType), h || (await (p == null ? void 0 : p.updateToken()), S.Authorization = `Bearer ${p == null ? void 0 : p.token()}`);
|
|
909
|
+
const y = new URL(d, window.location.href);
|
|
910
|
+
if (k != null && k.queryParams)
|
|
911
|
+
for (const [C, w] of Object.entries(k.queryParams))
|
|
912
|
+
y.searchParams.set(C, w);
|
|
913
|
+
const U = await fetch(y.toString(), {
|
|
914
|
+
...m,
|
|
915
|
+
headers: S
|
|
916
|
+
});
|
|
917
|
+
return U.ok ? U.json() : (k != null && k.skipAuth, Promise.reject({
|
|
918
|
+
content: U.body,
|
|
919
|
+
status: U.status
|
|
920
|
+
}));
|
|
905
921
|
};
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
for (const h in l)
|
|
924
|
-
v.append(h, l[h]);
|
|
925
|
-
return v.append("file", e), R(
|
|
926
|
-
p,
|
|
922
|
+
return {
|
|
923
|
+
get: (d, m) => e(d, { method: "GET" }, m),
|
|
924
|
+
postFile: (d, m, k = {}, h) => {
|
|
925
|
+
const S = new FormData();
|
|
926
|
+
for (const y in k)
|
|
927
|
+
S.append(y, k[y]);
|
|
928
|
+
return S.append("file", m), e(
|
|
929
|
+
d,
|
|
930
|
+
{
|
|
931
|
+
method: "POST",
|
|
932
|
+
body: S
|
|
933
|
+
},
|
|
934
|
+
{ ...h, contentType: void 0 }
|
|
935
|
+
);
|
|
936
|
+
},
|
|
937
|
+
post: (d, m, k) => e(
|
|
938
|
+
d,
|
|
927
939
|
{
|
|
928
940
|
method: "POST",
|
|
929
|
-
body:
|
|
941
|
+
body: JSON.stringify(m)
|
|
930
942
|
},
|
|
931
|
-
|
|
932
|
-
)
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
delete: (p, e, l) => R(
|
|
951
|
-
p,
|
|
952
|
-
{
|
|
953
|
-
method: "DELETE",
|
|
954
|
-
body: JSON.stringify(e)
|
|
955
|
-
},
|
|
956
|
-
l
|
|
957
|
-
)
|
|
943
|
+
k
|
|
944
|
+
),
|
|
945
|
+
patch: (d, m, k) => e(
|
|
946
|
+
d,
|
|
947
|
+
{
|
|
948
|
+
method: "PATCH",
|
|
949
|
+
body: JSON.stringify(m)
|
|
950
|
+
},
|
|
951
|
+
k
|
|
952
|
+
),
|
|
953
|
+
delete: (d, m, k) => e(
|
|
954
|
+
d,
|
|
955
|
+
{
|
|
956
|
+
method: "DELETE",
|
|
957
|
+
body: JSON.stringify(m)
|
|
958
|
+
},
|
|
959
|
+
k
|
|
960
|
+
)
|
|
961
|
+
};
|
|
958
962
|
};
|
|
959
963
|
export {
|
|
960
|
-
|
|
961
|
-
me as
|
|
964
|
+
he as createAuth,
|
|
965
|
+
me as useHttpRequest
|
|
962
966
|
};
|
package/lib/request.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type RequestOptions = {
|
|
|
3
3
|
queryParams?: Record<string, any>;
|
|
4
4
|
contentType?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const useHttpRequest: () => {
|
|
7
7
|
get: <T>(url: string, options?: RequestOptions) => Promise<T>;
|
|
8
8
|
postFile: <T>(url: string, file: File, data?: any, options?: RequestOptions) => Promise<T>;
|
|
9
9
|
post: <T>(url: string, data: any, options?: RequestOptions) => Promise<T>;
|