@multiplatform.one/keycloak 0.7.1 → 0.7.3
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/lib/@types/coreJsPure.d.d.mts +2 -0
- package/lib/@types/coreJsPure.d.d.ts +2 -0
- package/lib/@types/coreJsPure.d.js +1 -0
- package/lib/@types/coreJsPure.d.mjs +0 -0
- package/lib/@types/expoKeycloakAuth.d.d.mts +28 -0
- package/lib/@types/expoKeycloakAuth.d.d.ts +28 -0
- package/lib/@types/expoKeycloakAuth.d.js +1 -0
- package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
- package/lib/Authenticated.d.mts +36 -0
- package/lib/Authenticated.d.ts +36 -0
- package/lib/Authenticated.js +19 -0
- package/lib/Authenticated.mjs +20 -0
- package/lib/authConfig.d.mts +37 -0
- package/lib/authConfig.d.ts +37 -0
- package/lib/authConfig.js +8 -0
- package/lib/authConfig.mjs +9 -0
- package/lib/chunk-2GUOEPFY.mjs +0 -0
- package/lib/chunk-3ZPHNEJL.js +11 -0
- package/lib/chunk-64PPU7Q3.mjs +13 -0
- package/lib/chunk-6NDWOV55.js +1 -0
- package/lib/chunk-7MTPH6XK.mjs +26 -0
- package/lib/chunk-A7UBOIAL.js +13 -0
- package/lib/chunk-AD6VPMID.mjs +20 -0
- package/lib/chunk-AOKVCTMY.mjs +76 -0
- package/lib/chunk-AYKQVWMR.mjs +0 -0
- package/lib/chunk-BJ2OPIMW.js +78 -0
- package/lib/chunk-BTCP7NB3.js +443 -0
- package/lib/chunk-C2FNSVJO.js +17 -0
- package/lib/chunk-DKRUDENY.mjs +265 -0
- package/lib/chunk-E2X33LSD.js +460 -0
- package/lib/chunk-FXGWERIA.js +161 -0
- package/lib/chunk-HDNHCVXT.js +33 -0
- package/lib/chunk-KLLABHIC.js +13 -0
- package/lib/chunk-KMAXXKJT.js +22 -0
- package/lib/chunk-L5HMOY4M.mjs +18 -0
- package/lib/chunk-NU2SJ3ST.mjs +84 -0
- package/lib/chunk-NWRANDZ6.js +98 -0
- package/lib/chunk-NXTVYIBR.mjs +11 -0
- package/lib/chunk-OYWAYMFN.js +17 -0
- package/lib/chunk-S237YNYQ.mjs +10 -0
- package/lib/chunk-SK4YK6KE.mjs +50 -0
- package/lib/chunk-UBCNCE73.js +56 -0
- package/lib/chunk-UBVYEZI3.js +1 -0
- package/lib/chunk-UOKDJT5L.mjs +16 -0
- package/lib/chunk-VLUTEDDM.mjs +41 -0
- package/lib/chunk-Y4XMF3R6.mjs +13 -0
- package/lib/chunk-YGNNHTFE.js +12 -0
- package/lib/chunk-ZVG3OFME.mjs +52 -0
- package/lib/hooks/index.d.mts +9 -0
- package/lib/hooks/index.d.ts +9 -0
- package/lib/hooks/index.js +23 -0
- package/lib/hooks/index.mjs +34 -0
- package/lib/hooks/useAuthConfig.d.mts +29 -0
- package/lib/hooks/useAuthConfig.d.ts +29 -0
- package/lib/hooks/useAuthConfig.js +8 -0
- package/lib/hooks/useAuthConfig.mjs +8 -0
- package/lib/hooks/useCurrentRouteName/index.d.mts +26 -0
- package/lib/hooks/useCurrentRouteName/index.d.ts +26 -0
- package/lib/hooks/useCurrentRouteName/index.js +7 -0
- package/lib/hooks/useCurrentRouteName/index.mjs +7 -0
- package/lib/hooks/useCurrentRouteName/index.native.d.mts +26 -0
- package/lib/hooks/useCurrentRouteName/index.native.d.ts +26 -0
- package/lib/hooks/useCurrentRouteName/index.native.js +14 -0
- package/lib/hooks/useCurrentRouteName/index.native.mjs +14 -0
- package/lib/hooks/useKeycloak/index.d.mts +70 -0
- package/lib/hooks/useKeycloak/index.d.ts +70 -0
- package/lib/hooks/useKeycloak/index.js +11 -0
- package/lib/hooks/useKeycloak/index.mjs +12 -0
- package/lib/hooks/useKeycloak/useKeycloak.d.mts +2 -0
- package/lib/hooks/useKeycloak/useKeycloak.d.ts +2 -0
- package/lib/hooks/useKeycloak/useKeycloak.js +10 -0
- package/lib/hooks/useKeycloak/useKeycloak.mjs +11 -0
- package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +44 -0
- package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +44 -0
- package/lib/hooks/useKeycloak/useKeycloak.native.js +80 -0
- package/lib/hooks/useKeycloak/useKeycloak.native.mjs +69 -0
- package/lib/hooks/useLogin.d.mts +26 -0
- package/lib/hooks/useLogin.d.ts +26 -0
- package/lib/hooks/useLogin.js +11 -0
- package/lib/hooks/useLogin.mjs +11 -0
- package/lib/hooks/useTokensFromQuery/index.d.mts +26 -0
- package/lib/hooks/useTokensFromQuery/index.d.ts +26 -0
- package/lib/hooks/useTokensFromQuery/index.js +7 -0
- package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
- package/lib/hooks/useTokensFromQuery/index.native.d.mts +26 -0
- package/lib/hooks/useTokensFromQuery/index.native.d.ts +26 -0
- package/lib/hooks/useTokensFromQuery/index.native.js +10 -0
- package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
- package/lib/hooks/useTokensFromState.d.mts +26 -0
- package/lib/hooks/useTokensFromState.d.ts +26 -0
- package/lib/hooks/useTokensFromState.js +9 -0
- package/lib/hooks/useTokensFromState.mjs +9 -0
- package/lib/index.d.mts +13 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +15 -15
- package/lib/index.mjs +56 -0
- package/lib/provider/afterAuth.d.mts +32 -0
- package/lib/provider/afterAuth.d.ts +32 -0
- package/lib/provider/afterAuth.js +18 -0
- package/lib/provider/afterAuth.mjs +18 -0
- package/lib/provider/index.d.mts +42 -0
- package/lib/provider/index.d.ts +42 -0
- package/lib/provider/index.js +22 -0
- package/lib/provider/index.mjs +25 -0
- package/lib/provider/keycloakProvider.d.mts +45 -0
- package/lib/provider/keycloakProvider.d.ts +45 -0
- package/lib/provider/keycloakProvider.js +20 -0
- package/lib/provider/keycloakProvider.mjs +21 -0
- package/lib/provider/keycloakProvider.native.d.mts +32 -0
- package/lib/provider/keycloakProvider.native.d.ts +32 -0
- package/lib/provider/keycloakProvider.native.js +87 -0
- package/lib/provider/keycloakProvider.native.mjs +30 -0
- package/lib/state/index.d.mts +34 -0
- package/lib/state/index.d.ts +34 -0
- package/lib/state/index.js +7 -0
- package/lib/state/index.mjs +7 -0
- package/lib/types.d.mts +40 -0
- package/lib/types.d.ts +40 -0
- package/lib/types.js +8 -0
- package/lib/types.mjs +7 -0
- package/lib/util.d.mts +27 -0
- package/lib/util.d.ts +27 -0
- package/lib/util.js +8 -0
- package/lib/util.mjs +9 -0
- package/package.json +30 -30
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/hooks/useCurrentRouteName/index.ts
|
|
2
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
3
|
+
import { useRoute } from "@react-navigation/native";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
5
|
+
function useCurrentRouteName() {
|
|
6
|
+
if (MultiPlatform.isStorybook)
|
|
7
|
+
return null;
|
|
8
|
+
if (MultiPlatform.isNext) {
|
|
9
|
+
const router = useRouter();
|
|
10
|
+
return router.route;
|
|
11
|
+
}
|
|
12
|
+
const route = useRoute();
|
|
13
|
+
return route.name;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
useCurrentRouteName
|
|
18
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuthConfig
|
|
3
|
+
} from "./chunk-Y4XMF3R6.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__publicField
|
|
6
|
+
} from "./chunk-S237YNYQ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/hooks/useKeycloak/useKeycloak.ts
|
|
9
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
10
|
+
import { useKeycloak as useReactKeycloak } from "@bitspur/react-keycloak-web";
|
|
11
|
+
import { useKeycloak as useSsrKeycloak } from "@bitspur/react-keycloak-ssr";
|
|
12
|
+
function useKeycloak() {
|
|
13
|
+
const authConfig = useAuthConfig();
|
|
14
|
+
if (MultiPlatform.isStorybook) {
|
|
15
|
+
return new Keycloak(
|
|
16
|
+
{
|
|
17
|
+
email: "storybook@example.com",
|
|
18
|
+
login: async () => void 0,
|
|
19
|
+
logout: async () => void 0,
|
|
20
|
+
subject: "0",
|
|
21
|
+
username: "storybook"
|
|
22
|
+
},
|
|
23
|
+
true
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
if (MultiPlatform.isNext && authConfig.ssr) {
|
|
27
|
+
const { keycloak: keycloak2, initialized: initialized2 } = useSsrKeycloak();
|
|
28
|
+
return new Keycloak(keycloak2, initialized2);
|
|
29
|
+
}
|
|
30
|
+
const { keycloak, initialized } = useReactKeycloak();
|
|
31
|
+
return new Keycloak(keycloak, initialized);
|
|
32
|
+
}
|
|
33
|
+
var Keycloak = class {
|
|
34
|
+
constructor(keycloak, initialized) {
|
|
35
|
+
this.keycloak = keycloak;
|
|
36
|
+
__publicField(this, "authenticated");
|
|
37
|
+
this.authenticated = initialized ? keycloak?.authenticated : void 0;
|
|
38
|
+
}
|
|
39
|
+
get idToken() {
|
|
40
|
+
return this.keycloak?.idToken;
|
|
41
|
+
}
|
|
42
|
+
get realmAccess() {
|
|
43
|
+
return this.keycloak?.realmAccess;
|
|
44
|
+
}
|
|
45
|
+
get refreshToken() {
|
|
46
|
+
return this.keycloak?.refreshToken;
|
|
47
|
+
}
|
|
48
|
+
get refreshTokenParsed() {
|
|
49
|
+
return this.keycloak?.refreshTokenParsed;
|
|
50
|
+
}
|
|
51
|
+
get resourceAccess() {
|
|
52
|
+
return this.keycloak?.resourceAccess;
|
|
53
|
+
}
|
|
54
|
+
get subject() {
|
|
55
|
+
return this.keycloak?.subject;
|
|
56
|
+
}
|
|
57
|
+
get token() {
|
|
58
|
+
return this.keycloak?.token;
|
|
59
|
+
}
|
|
60
|
+
get tokenParsed() {
|
|
61
|
+
return this.keycloak?.tokenParsed;
|
|
62
|
+
}
|
|
63
|
+
get email() {
|
|
64
|
+
return this.keycloak?.tokenParsed?.email;
|
|
65
|
+
}
|
|
66
|
+
get username() {
|
|
67
|
+
return this.keycloak?.tokenParsed?.preferred_username;
|
|
68
|
+
}
|
|
69
|
+
async login() {
|
|
70
|
+
if (!this.keycloak)
|
|
71
|
+
return;
|
|
72
|
+
return this.keycloak.login();
|
|
73
|
+
}
|
|
74
|
+
async logout() {
|
|
75
|
+
if (!this.keycloak)
|
|
76
|
+
return;
|
|
77
|
+
return this.keycloak.logout();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
useKeycloak,
|
|
83
|
+
Keycloak
|
|
84
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_without_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
9
|
+
}
|
|
10
|
+
function _instanceof(left, right) {
|
|
11
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
12
|
+
return !!right[Symbol.hasInstance](left);
|
|
13
|
+
} else {
|
|
14
|
+
return left instanceof right;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _iterable_to_array(iter) {
|
|
18
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
19
|
+
}
|
|
20
|
+
function _non_iterable_spread() {
|
|
21
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
22
|
+
}
|
|
23
|
+
function _to_consumable_array(arr) {
|
|
24
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
25
|
+
}
|
|
26
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
27
|
+
if (!o) return;
|
|
28
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
29
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
30
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
31
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
32
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, "__esModule", {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
function _optionalChain(ops) {
|
|
38
|
+
var lastAccessLHS = undefined;
|
|
39
|
+
var value = ops[0];
|
|
40
|
+
var i = 1;
|
|
41
|
+
while(i < ops.length){
|
|
42
|
+
var op = ops[i];
|
|
43
|
+
var fn = ops[i + 1];
|
|
44
|
+
i += 2;
|
|
45
|
+
if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
if (op === "access" || op === "optionalAccess") {
|
|
49
|
+
lastAccessLHS = value;
|
|
50
|
+
value = fn(value);
|
|
51
|
+
} else if (op === "call" || op === "optionalCall") {
|
|
52
|
+
var _value;
|
|
53
|
+
value = fn(function() {
|
|
54
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
55
|
+
args[_key] = arguments[_key];
|
|
56
|
+
}
|
|
57
|
+
return (_value = value).call.apply(_value, [
|
|
58
|
+
lastAccessLHS
|
|
59
|
+
].concat(_to_consumable_array(args)));
|
|
60
|
+
});
|
|
61
|
+
lastAccessLHS = undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
} // src/util.ts
|
|
66
|
+
function validToken(token, refreshToken) {
|
|
67
|
+
if (typeof token !== "string") return token;
|
|
68
|
+
if (refreshToken) {
|
|
69
|
+
if (refreshToken === true || isTokenValid(refreshToken)) return token;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return isTokenValid(token) ? token : false;
|
|
73
|
+
}
|
|
74
|
+
function isTokenValid(token) {
|
|
75
|
+
try {
|
|
76
|
+
var exp = JSON.parse(Buffer.from(_optionalChain([
|
|
77
|
+
token,
|
|
78
|
+
"access",
|
|
79
|
+
function(_) {
|
|
80
|
+
return _.split;
|
|
81
|
+
},
|
|
82
|
+
"call",
|
|
83
|
+
function(_2) {
|
|
84
|
+
return _2(".");
|
|
85
|
+
},
|
|
86
|
+
"optionalAccess",
|
|
87
|
+
function(_3) {
|
|
88
|
+
return _3[1];
|
|
89
|
+
}
|
|
90
|
+
]) || "", "base64").toString() || "{}").exp;
|
|
91
|
+
return Math.floor(Date.now() / 1e3) <= exp;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (_instanceof(err, SyntaxError)) return false;
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.validToken = validToken;
|
|
98
|
+
exports.isTokenValid = isTokenValid;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/hooks/useTokensFromQuery/index.ts
|
|
2
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
3
|
+
import { useRouter } from "next/router";
|
|
4
|
+
function useTokensFromQuery() {
|
|
5
|
+
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
6
|
+
return "idToken" in query || "token" in query || "refreshToken" in query;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
useTokensFromQuery
|
|
11
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
}); // src/hooks/useCurrentRouteName/index.ts
|
|
5
|
+
var _multiplatformone = require("multiplatform.one");
|
|
6
|
+
var _native = require("@react-navigation/native");
|
|
7
|
+
var _router = require("next/router");
|
|
8
|
+
function useCurrentRouteName() {
|
|
9
|
+
if (_multiplatformone.MultiPlatform.isStorybook) return null;
|
|
10
|
+
if (_multiplatformone.MultiPlatform.isNext) {
|
|
11
|
+
var router = _router.useRouter.call(void 0);
|
|
12
|
+
return router.route;
|
|
13
|
+
}
|
|
14
|
+
var route = _native.useRoute.call(void 0);
|
|
15
|
+
return route.name;
|
|
16
|
+
}
|
|
17
|
+
exports.useCurrentRouteName = useCurrentRouteName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__publicField
|
|
10
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useKeycloak
|
|
3
|
+
} from "./chunk-NU2SJ3ST.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useAuthConfig
|
|
6
|
+
} from "./chunk-Y4XMF3R6.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useAuthState
|
|
9
|
+
} from "./chunk-AD6VPMID.mjs";
|
|
10
|
+
|
|
11
|
+
// src/provider/afterAuth.tsx
|
|
12
|
+
import React, { useEffect } from "react";
|
|
13
|
+
var logger = console;
|
|
14
|
+
var AfterAuth = ({ children }) => {
|
|
15
|
+
const authConfig = useAuthConfig();
|
|
16
|
+
const authState = useAuthState();
|
|
17
|
+
const { token, refreshToken, authenticated, idToken } = useKeycloak();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!authenticated)
|
|
20
|
+
return;
|
|
21
|
+
if (authConfig.persist && token) {
|
|
22
|
+
authState.setToken(token);
|
|
23
|
+
if (idToken)
|
|
24
|
+
authState.setIdToken(idToken);
|
|
25
|
+
if (authConfig.ensureFreshness && refreshToken)
|
|
26
|
+
authState.setRefreshToken(refreshToken);
|
|
27
|
+
}
|
|
28
|
+
}, [token, refreshToken, idToken]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (authConfig.debug && authState.token)
|
|
31
|
+
logger.debug("token", authState.token);
|
|
32
|
+
}, [authState.token]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (authConfig.debug && authState.idToken)
|
|
35
|
+
logger.debug("idToken", authState.idToken);
|
|
36
|
+
}, [authState.idToken]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (authConfig.debug && authState.refreshToken)
|
|
39
|
+
logger.debug("refreshToken", authState.refreshToken);
|
|
40
|
+
}, [authState.refreshToken]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (authConfig.debug)
|
|
43
|
+
logger.debug("authenticated", authenticated);
|
|
44
|
+
}, [authenticated]);
|
|
45
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
AfterAuth
|
|
50
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _interopRequireDefault(obj) {
|
|
6
|
+
return obj && obj.__esModule ? obj : {
|
|
7
|
+
default: obj
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
var _chunkE2X33LSDjs = require("./chunk-E2X33LSD.js");
|
|
11
|
+
var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
|
|
12
|
+
var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
|
|
13
|
+
// src/provider/afterAuth.tsx
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
var _react2 = _interopRequireDefault(_react);
|
|
16
|
+
var logger = console;
|
|
17
|
+
var AfterAuth = function(param) {
|
|
18
|
+
var children = param.children;
|
|
19
|
+
var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
|
|
20
|
+
var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
|
|
21
|
+
var _chunkE2X33LSDjs_useKeycloak_call = _chunkE2X33LSDjs.useKeycloak.call(void 0), token = _chunkE2X33LSDjs_useKeycloak_call.token, refreshToken = _chunkE2X33LSDjs_useKeycloak_call.refreshToken, authenticated = _chunkE2X33LSDjs_useKeycloak_call.authenticated, idToken = _chunkE2X33LSDjs_useKeycloak_call.idToken;
|
|
22
|
+
_react.useEffect.call(void 0, function() {
|
|
23
|
+
if (!authenticated) return;
|
|
24
|
+
if (authConfig.persist && token) {
|
|
25
|
+
authState.setToken(token);
|
|
26
|
+
if (idToken) authState.setIdToken(idToken);
|
|
27
|
+
if (authConfig.ensureFreshness && refreshToken) authState.setRefreshToken(refreshToken);
|
|
28
|
+
}
|
|
29
|
+
}, [
|
|
30
|
+
token,
|
|
31
|
+
refreshToken,
|
|
32
|
+
idToken
|
|
33
|
+
]);
|
|
34
|
+
_react.useEffect.call(void 0, function() {
|
|
35
|
+
if (authConfig.debug && authState.token) logger.debug("token", authState.token);
|
|
36
|
+
}, [
|
|
37
|
+
authState.token
|
|
38
|
+
]);
|
|
39
|
+
_react.useEffect.call(void 0, function() {
|
|
40
|
+
if (authConfig.debug && authState.idToken) logger.debug("idToken", authState.idToken);
|
|
41
|
+
}, [
|
|
42
|
+
authState.idToken
|
|
43
|
+
]);
|
|
44
|
+
_react.useEffect.call(void 0, function() {
|
|
45
|
+
if (authConfig.debug && authState.refreshToken) logger.debug("refreshToken", authState.refreshToken);
|
|
46
|
+
}, [
|
|
47
|
+
authState.refreshToken
|
|
48
|
+
]);
|
|
49
|
+
_react.useEffect.call(void 0, function() {
|
|
50
|
+
if (authConfig.debug) logger.debug("authenticated", authenticated);
|
|
51
|
+
}, [
|
|
52
|
+
authenticated
|
|
53
|
+
]);
|
|
54
|
+
return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
|
|
55
|
+
};
|
|
56
|
+
exports.AfterAuth = AfterAuth;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuthState
|
|
3
|
+
} from "./chunk-AD6VPMID.mjs";
|
|
4
|
+
import {
|
|
5
|
+
validToken
|
|
6
|
+
} from "./chunk-7MTPH6XK.mjs";
|
|
7
|
+
|
|
8
|
+
// src/hooks/useTokensFromState.ts
|
|
9
|
+
function useTokensFromState() {
|
|
10
|
+
const authState = useAuthState();
|
|
11
|
+
return !!validToken(authState.token, authState.refreshToken);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
useTokensFromState
|
|
16
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCurrentRouteName
|
|
3
|
+
} from "./chunk-L5HMOY4M.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useKeycloak
|
|
6
|
+
} from "./chunk-NU2SJ3ST.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useAuthConfig
|
|
9
|
+
} from "./chunk-Y4XMF3R6.mjs";
|
|
10
|
+
|
|
11
|
+
// src/hooks/useLogin.ts
|
|
12
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
13
|
+
import { useRouter } from "solito/router";
|
|
14
|
+
function useLogin(loginRoute) {
|
|
15
|
+
if (MultiPlatform.isStorybook)
|
|
16
|
+
return () => null;
|
|
17
|
+
const keycloak = useKeycloak();
|
|
18
|
+
const authConfig = useAuthConfig();
|
|
19
|
+
const currentRouteName = useCurrentRouteName();
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
return () => {
|
|
22
|
+
if (!loginRoute)
|
|
23
|
+
loginRoute = authConfig.loginRoute;
|
|
24
|
+
if (!loginRoute) {
|
|
25
|
+
keycloak.login();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const url = new URL(`x://${loginRoute}`);
|
|
29
|
+
const searchParams = new URLSearchParams(url.search);
|
|
30
|
+
if (currentRouteName)
|
|
31
|
+
searchParams.append("backTo", currentRouteName);
|
|
32
|
+
let query = searchParams.toString();
|
|
33
|
+
if (query.length)
|
|
34
|
+
query = `?${query}`;
|
|
35
|
+
router.push(`${url.pathname.substring(2)}${query}`);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
useLogin
|
|
41
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
|
|
6
|
+
var _chunkNWRANDZ6js = require("./chunk-NWRANDZ6.js");
|
|
7
|
+
// src/hooks/useTokensFromState.ts
|
|
8
|
+
function useTokensFromState() {
|
|
9
|
+
var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
|
|
10
|
+
return !!_chunkNWRANDZ6js.validToken.call(void 0, authState.token, authState.refreshToken);
|
|
11
|
+
}
|
|
12
|
+
exports.useTokensFromState = useTokensFromState;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTokensFromQuery
|
|
3
|
+
} from "./chunk-NXTVYIBR.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useLogin
|
|
6
|
+
} from "./chunk-VLUTEDDM.mjs";
|
|
7
|
+
import {
|
|
8
|
+
useKeycloak
|
|
9
|
+
} from "./chunk-NU2SJ3ST.mjs";
|
|
10
|
+
import {
|
|
11
|
+
useAuthConfig
|
|
12
|
+
} from "./chunk-Y4XMF3R6.mjs";
|
|
13
|
+
import {
|
|
14
|
+
useTokensFromState
|
|
15
|
+
} from "./chunk-UOKDJT5L.mjs";
|
|
16
|
+
import {
|
|
17
|
+
useAuthState
|
|
18
|
+
} from "./chunk-AD6VPMID.mjs";
|
|
19
|
+
|
|
20
|
+
// src/Authenticated.tsx
|
|
21
|
+
import React, { useEffect } from "react";
|
|
22
|
+
function Authenticated({ children, disabled, loginRoute, loggedOutComponent }) {
|
|
23
|
+
const authConfig = useAuthConfig();
|
|
24
|
+
const authState = useAuthState();
|
|
25
|
+
const login = useLogin(loginRoute);
|
|
26
|
+
const tokensFromQuery = useTokensFromQuery();
|
|
27
|
+
const tokensFromState = useTokensFromState();
|
|
28
|
+
const { authenticated } = useKeycloak();
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (authenticated !== false)
|
|
31
|
+
return;
|
|
32
|
+
if (authConfig.persist) {
|
|
33
|
+
authState.setIdToken("");
|
|
34
|
+
authState.setRefreshToken("");
|
|
35
|
+
authState.setToken("");
|
|
36
|
+
}
|
|
37
|
+
if (typeof window !== "undefined" && !tokensFromQuery && !tokensFromState && window.self === window.top)
|
|
38
|
+
login();
|
|
39
|
+
}, [authenticated]);
|
|
40
|
+
if (disabled || authenticated)
|
|
41
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
42
|
+
const LoggedOutComponent = loggedOutComponent || (() => /* @__PURE__ */ React.createElement(React.Fragment, null, authConfig.debug ? "not authenticated" : null));
|
|
43
|
+
return /* @__PURE__ */ React.createElement(LoggedOutComponent, null);
|
|
44
|
+
}
|
|
45
|
+
function withAuthenticated(Component) {
|
|
46
|
+
return (props) => /* @__PURE__ */ React.createElement(Authenticated, null, /* @__PURE__ */ React.createElement(Component, { ...props }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
Authenticated,
|
|
51
|
+
withAuthenticated
|
|
52
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useAuthConfig } from './useAuthConfig.mjs';
|
|
2
|
+
export { useCurrentRouteName } from './useCurrentRouteName/index.mjs';
|
|
3
|
+
export { IKeycloak, ITokenParsed, Keycloak, useKeycloak } from './useKeycloak/index.mjs';
|
|
4
|
+
export { useLogin } from './useLogin.mjs';
|
|
5
|
+
export { useTokensFromQuery } from './useTokensFromQuery/index.mjs';
|
|
6
|
+
export { useTokensFromState } from './useTokensFromState.mjs';
|
|
7
|
+
import '../authConfig.mjs';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@bitspur/keycloak-js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useAuthConfig } from './useAuthConfig.js';
|
|
2
|
+
export { useCurrentRouteName } from './useCurrentRouteName/index.js';
|
|
3
|
+
export { IKeycloak, ITokenParsed, Keycloak, useKeycloak } from './useKeycloak/index.js';
|
|
4
|
+
export { useLogin } from './useLogin.js';
|
|
5
|
+
export { useTokensFromQuery } from './useTokensFromQuery/index.js';
|
|
6
|
+
export { useTokensFromState } from './useTokensFromState.js';
|
|
7
|
+
import '../authConfig.js';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@bitspur/keycloak-js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
require("../chunk-UBVYEZI3.js");
|
|
6
|
+
require("../chunk-6NDWOV55.js");
|
|
7
|
+
var _chunkKLLABHICjs = require("../chunk-KLLABHIC.js");
|
|
8
|
+
var _chunkHDNHCVXTjs = require("../chunk-HDNHCVXT.js");
|
|
9
|
+
var _chunkOYWAYMFNjs = require("../chunk-OYWAYMFN.js");
|
|
10
|
+
var _chunkE2X33LSDjs = require("../chunk-E2X33LSD.js");
|
|
11
|
+
var _chunk3ZPHNEJLjs = require("../chunk-3ZPHNEJL.js");
|
|
12
|
+
var _chunkYGNNHTFEjs = require("../chunk-YGNNHTFE.js");
|
|
13
|
+
require("../chunk-C2FNSVJO.js");
|
|
14
|
+
require("../chunk-A7UBOIAL.js");
|
|
15
|
+
require("../chunk-NWRANDZ6.js");
|
|
16
|
+
require("../chunk-KMAXXKJT.js");
|
|
17
|
+
exports.Keycloak = _chunkE2X33LSDjs.Keycloak;
|
|
18
|
+
exports.useAuthConfig = _chunk3ZPHNEJLjs.useAuthConfig;
|
|
19
|
+
exports.useCurrentRouteName = _chunkOYWAYMFNjs.useCurrentRouteName;
|
|
20
|
+
exports.useKeycloak = _chunkE2X33LSDjs.useKeycloak;
|
|
21
|
+
exports.useLogin = _chunkHDNHCVXTjs.useLogin;
|
|
22
|
+
exports.useTokensFromQuery = _chunkKLLABHICjs.useTokensFromQuery;
|
|
23
|
+
exports.useTokensFromState = _chunkYGNNHTFEjs.useTokensFromState;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "../chunk-AYKQVWMR.mjs";
|
|
2
|
+
import "../chunk-2GUOEPFY.mjs";
|
|
3
|
+
import {
|
|
4
|
+
useTokensFromQuery
|
|
5
|
+
} from "../chunk-NXTVYIBR.mjs";
|
|
6
|
+
import {
|
|
7
|
+
useLogin
|
|
8
|
+
} from "../chunk-VLUTEDDM.mjs";
|
|
9
|
+
import {
|
|
10
|
+
useCurrentRouteName
|
|
11
|
+
} from "../chunk-L5HMOY4M.mjs";
|
|
12
|
+
import {
|
|
13
|
+
Keycloak,
|
|
14
|
+
useKeycloak
|
|
15
|
+
} from "../chunk-NU2SJ3ST.mjs";
|
|
16
|
+
import {
|
|
17
|
+
useAuthConfig
|
|
18
|
+
} from "../chunk-Y4XMF3R6.mjs";
|
|
19
|
+
import {
|
|
20
|
+
useTokensFromState
|
|
21
|
+
} from "../chunk-UOKDJT5L.mjs";
|
|
22
|
+
import "../chunk-AD6VPMID.mjs";
|
|
23
|
+
import "../chunk-64PPU7Q3.mjs";
|
|
24
|
+
import "../chunk-7MTPH6XK.mjs";
|
|
25
|
+
import "../chunk-S237YNYQ.mjs";
|
|
26
|
+
export {
|
|
27
|
+
Keycloak,
|
|
28
|
+
useAuthConfig,
|
|
29
|
+
useCurrentRouteName,
|
|
30
|
+
useKeycloak,
|
|
31
|
+
useLogin,
|
|
32
|
+
useTokensFromQuery,
|
|
33
|
+
useTokensFromState
|
|
34
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthConfig } from '../authConfig.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* File: /src/hooks/useAuthConfig.ts
|
|
6
|
+
* Project: app
|
|
7
|
+
* File Created: 08-11-2022 09:20:41
|
|
8
|
+
* Author: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Last Modified: 25-11-2022 09:52:31
|
|
11
|
+
* Modified By: Clay Risser
|
|
12
|
+
* -----
|
|
13
|
+
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
declare function useAuthConfig(): AuthConfig;
|
|
28
|
+
|
|
29
|
+
export { useAuthConfig };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthConfig } from '../authConfig.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* File: /src/hooks/useAuthConfig.ts
|
|
6
|
+
* Project: app
|
|
7
|
+
* File Created: 08-11-2022 09:20:41
|
|
8
|
+
* Author: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Last Modified: 25-11-2022 09:52:31
|
|
11
|
+
* Modified By: Clay Risser
|
|
12
|
+
* -----
|
|
13
|
+
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
declare function useAuthConfig(): AuthConfig;
|
|
28
|
+
|
|
29
|
+
export { useAuthConfig };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
var _chunk3ZPHNEJLjs = require("../chunk-3ZPHNEJL.js");
|
|
6
|
+
require("../chunk-A7UBOIAL.js");
|
|
7
|
+
require("../chunk-KMAXXKJT.js");
|
|
8
|
+
exports.useAuthConfig = _chunk3ZPHNEJLjs.useAuthConfig;
|