@multiplatform.one/keycloak 0.0.1 → 0.0.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/esm/Authenticated.js +8 -19
- package/esm/Authenticated.js.map +1 -1
- package/esm/authConfig.js +2 -2
- package/esm/authConfig.js.map +1 -1
- package/esm/expo/ExpoKeycloakContext.js +28 -0
- package/esm/expo/ExpoKeycloakContext.js.map +1 -0
- package/esm/expo/ExpoKeycloakProvider.js +113 -0
- package/esm/expo/ExpoKeycloakProvider.js.map +1 -0
- package/esm/expo/KeycloakContext.js +28 -0
- package/esm/expo/KeycloakContext.js.map +1 -0
- package/esm/expo/KeycloakProvider.js +142 -0
- package/esm/expo/KeycloakProvider.js.map +1 -0
- package/esm/expo/const.js +42 -0
- package/esm/expo/const.js.map +1 -0
- package/esm/expo/helpers.js +56 -0
- package/esm/expo/helpers.js.map +1 -0
- package/esm/expo/index.js +28 -0
- package/esm/expo/index.js.map +1 -0
- package/esm/expo/useExpoKeycloak.js +44 -0
- package/esm/expo/useExpoKeycloak.js.map +1 -0
- package/esm/expo/useTokenStorage.js +153 -0
- package/esm/expo/useTokenStorage.js.map +1 -0
- package/esm/hooks/useCurrentRouteName.js +2 -3
- package/esm/hooks/useCurrentRouteName.js.map +1 -1
- package/esm/hooks/useKeycloak/index.js +1 -1
- package/esm/hooks/useKeycloak/index.js.map +1 -1
- package/esm/hooks/useKeycloak/useKeycloak.js +17 -24
- package/esm/hooks/useKeycloak/useKeycloak.js.map +1 -1
- package/esm/hooks/useKeycloak/useKeycloak.native.js +60 -19
- package/esm/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
- package/esm/hooks/useLogin.js +12 -30
- package/esm/hooks/useLogin.js.map +1 -1
- package/esm/provider/afterAuth.js +21 -39
- package/esm/provider/afterAuth.js.map +1 -1
- package/esm/provider/index.js +11 -28
- package/esm/provider/index.js.map +1 -1
- package/esm/provider/keycloakProvider.js +55 -100
- package/esm/provider/keycloakProvider.js.map +1 -1
- package/esm/provider/keycloakProvider.native.js +12 -11
- package/esm/provider/keycloakProvider.native.js.map +1 -1
- package/esm/state/index.js +2 -2
- package/esm/state/index.js.map +1 -1
- package/lib/Authenticated.js +38 -26
- package/lib/Authenticated.js.map +1 -1
- package/lib/authConfig.js +2 -4
- package/lib/authConfig.js.map +1 -1
- package/lib/expo/ExpoKeycloakContext.d.ts +32 -0
- package/lib/expo/ExpoKeycloakContext.js +47 -0
- package/lib/expo/ExpoKeycloakContext.js.map +1 -0
- package/lib/expo/ExpoKeycloakProvider.d.ts +37 -0
- package/lib/expo/ExpoKeycloakProvider.js +130 -0
- package/lib/expo/ExpoKeycloakProvider.js.map +1 -0
- package/lib/expo/KeycloakContext.d.ts +32 -0
- package/lib/expo/KeycloakContext.js +49 -0
- package/lib/expo/KeycloakContext.js.map +1 -0
- package/lib/expo/KeycloakProvider.d.ts +37 -0
- package/lib/expo/KeycloakProvider.js +138 -0
- package/lib/expo/KeycloakProvider.js.map +1 -0
- package/lib/expo/const.d.ts +33 -0
- package/lib/expo/const.js +66 -0
- package/lib/expo/const.js.map +1 -0
- package/lib/expo/helpers.d.ts +41 -0
- package/lib/expo/helpers.js +77 -0
- package/lib/expo/helpers.js.map +1 -0
- package/lib/expo/index.d.ts +26 -0
- package/lib/expo/index.js +50 -0
- package/lib/expo/index.js.map +1 -0
- package/lib/expo/useExpoKeycloak.d.ts +31 -0
- package/lib/expo/useExpoKeycloak.js +62 -0
- package/lib/expo/useExpoKeycloak.js.map +1 -0
- package/lib/expo/useTokenStorage.d.ts +36 -0
- package/lib/expo/useTokenStorage.js +166 -0
- package/lib/expo/useTokenStorage.js.map +1 -0
- package/lib/hooks/index.js +3 -9
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useAuthConfig.js +0 -2
- package/lib/hooks/useAuthConfig.js.map +1 -1
- package/lib/hooks/useCurrentRouteName.js +6 -8
- package/lib/hooks/useCurrentRouteName.js.map +1 -1
- package/lib/hooks/useKeycloak/index.d.ts +7 -4
- package/lib/hooks/useKeycloak/index.js +1 -7
- package/lib/hooks/useKeycloak/index.js.map +1 -1
- package/lib/hooks/useKeycloak/useKeycloak.js +45 -30
- package/lib/hooks/useKeycloak/useKeycloak.js.map +1 -1
- package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +13 -3
- package/lib/hooks/useKeycloak/useKeycloak.native.js +61 -25
- package/lib/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
- package/lib/hooks/useLogin.js +16 -25
- package/lib/hooks/useLogin.js.map +1 -1
- package/lib/index.js +4 -10
- package/lib/index.js.map +1 -1
- package/lib/provider/afterAuth.js +52 -52
- package/lib/provider/afterAuth.js.map +1 -1
- package/lib/provider/index.js +44 -43
- package/lib/provider/index.js.map +1 -1
- package/lib/provider/keycloakProvider.js +93 -114
- package/lib/provider/keycloakProvider.js.map +1 -1
- package/lib/provider/keycloakProvider.native.js +39 -15
- package/lib/provider/keycloakProvider.native.js.map +1 -1
- package/lib/state/index.js +3 -5
- package/lib/state/index.js.map +1 -1
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/types.js +2 -4
- package/lib/types.js.map +1 -1
- package/package.json +5 -4
- package/src/expo/ExpoKeycloakContext.ts +41 -0
- package/src/expo/ExpoKeycloakProvider.tsx +139 -0
- package/src/expo/NOTES +1 -0
- package/src/expo/const.ts +42 -0
- package/src/expo/helpers.ts +74 -0
- package/src/{@types/expoKeycloakAuth.d.ts → expo/index.ts} +6 -7
- package/src/expo/useExpoKeycloak.ts +44 -0
- package/src/expo/useTokenStorage.ts +168 -0
- package/src/hooks/useKeycloak/index.ts +11 -4
- package/src/hooks/useKeycloak/useKeycloak.native.ts +72 -8
- package/src/provider/keycloakProvider.native.tsx +8 -4
package/esm/provider/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
|
|
3
|
-
var _this = this;
|
|
4
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
import "core-js/modules/es.function.bind.js";
|
|
7
|
-
import "core-js/modules/es.object.keys.js";
|
|
8
|
-
import "core-js/modules/es.symbol.js";
|
|
9
|
-
import "core-js/modules/es.array.filter.js";
|
|
10
|
-
import "core-js/modules/es.object.to-string.js";
|
|
11
|
-
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
12
|
-
import "core-js/modules/es.array.for-each.js";
|
|
13
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
14
|
-
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
15
|
-
import "core-js/modules/es.object.define-properties.js";
|
|
16
|
-
import "core-js/modules/es.object.define-property.js";
|
|
17
1
|
/**
|
|
18
2
|
* File: /auth/provider/index.tsx
|
|
19
3
|
* Project: app
|
|
@@ -41,20 +25,19 @@ import "core-js/modules/es.object.define-property.js";
|
|
|
41
25
|
import React, { useMemo } from "react";
|
|
42
26
|
import { AuthConfigContext, defaultAuthConfig } from "../authConfig";
|
|
43
27
|
import { KeycloakProvider } from "./keycloakProvider";
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}.bind(this), []);
|
|
28
|
+
export const AuthProvider = props => {
|
|
29
|
+
const {
|
|
30
|
+
authConfig,
|
|
31
|
+
debug
|
|
32
|
+
} = props;
|
|
33
|
+
const authConfigValue = useMemo(() => ({
|
|
34
|
+
...defaultAuthConfig,
|
|
35
|
+
...authConfig,
|
|
36
|
+
debug: !!debug
|
|
37
|
+
}), []);
|
|
55
38
|
return /*#__PURE__*/React.createElement(AuthConfigContext.Provider, {
|
|
56
39
|
value: authConfigValue
|
|
57
40
|
}, /*#__PURE__*/React.createElement(KeycloakProvider, props));
|
|
58
|
-
}
|
|
41
|
+
};
|
|
59
42
|
export * from "./keycloakProvider";
|
|
60
43
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","useMemo","AuthConfigContext","defaultAuthConfig","KeycloakProvider","AuthProvider","props","authConfig","debug","authConfigValue"],"sources":["../../src/provider/index.tsx"],"sourcesContent":["/**\n * File: /auth/provider/index.tsx\n * Project: app\n * File Created: 08-11-2022 06:33:07\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:13\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { FC, useMemo } from \"react\";\nimport {\n AuthConfig,\n AuthConfigContext,\n defaultAuthConfig,\n} from \"../authConfig\";\nimport { KeycloakProvider, KeycloakProviderProps } from \"./keycloakProvider\";\n\nexport interface AuthProviderProps extends KeycloakProviderProps {\n authConfig?: Partial<AuthConfig>;\n}\n\nexport const AuthProvider: FC<AuthProviderProps> = (\n props: AuthProviderProps\n) => {\n const { authConfig, debug } = props;\n const authConfigValue = useMemo(\n () => ({\n ...defaultAuthConfig,\n ...authConfig,\n debug: !!debug,\n }),\n []\n );\n\n return (\n <AuthConfigContext.Provider value={authConfigValue}>\n <KeycloakProvider {...props} />\n </AuthConfigContext.Provider>\n );\n};\n\nexport * from \"./keycloakProvider\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useMemo","AuthConfigContext","defaultAuthConfig","KeycloakProvider","AuthProvider","props","authConfig","debug","authConfigValue"],"sources":["../../src/provider/index.tsx"],"sourcesContent":["/**\n * File: /auth/provider/index.tsx\n * Project: app\n * File Created: 08-11-2022 06:33:07\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:13\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { FC, useMemo } from \"react\";\nimport {\n AuthConfig,\n AuthConfigContext,\n defaultAuthConfig,\n} from \"../authConfig\";\nimport { KeycloakProvider, KeycloakProviderProps } from \"./keycloakProvider\";\n\nexport interface AuthProviderProps extends KeycloakProviderProps {\n authConfig?: Partial<AuthConfig>;\n}\n\nexport const AuthProvider: FC<AuthProviderProps> = (\n props: AuthProviderProps\n) => {\n const { authConfig, debug } = props;\n const authConfigValue = useMemo(\n () => ({\n ...defaultAuthConfig,\n ...authConfig,\n debug: !!debug,\n }),\n []\n );\n\n return (\n <AuthConfigContext.Provider value={authConfigValue}>\n <KeycloakProvider {...props} />\n </AuthConfigContext.Provider>\n );\n};\n\nexport * from \"./keycloakProvider\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAQC,OAAO,QAAQ,OAAO;AAC1C,SAEEC,iBAAiB,EACjBC,iBAAiB;AAEnB,SAASC,gBAAgB;AAMzB,OAAO,MAAMC,YAAmC,GAC9CC,KAAwB,IACrB;EACH,MAAM;IAAEC,UAAU;IAAEC;EAAM,CAAC,GAAGF,KAAK;EACnC,MAAMG,eAAe,GAAGR,OAAO,CAC7B,OAAO;IACL,GAAGE,iBAAiB;IACpB,GAAGI,UAAU;IACbC,KAAK,EAAE,CAAC,CAACA;EACX,CAAC,CAAC,EACF,EAAE,CACH;EAED,oBACE,oBAAC,iBAAiB,CAAC,QAAQ;IAAC,KAAK,EAAEC;EAAgB,gBACjD,oBAAC,gBAAgB,EAAKH,KAAK,CAAI,CACJ;AAEjC,CAAC;AAED"}
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
|
|
4
|
-
var _this = this;
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
import "core-js/modules/es.function.bind.js";
|
|
8
|
-
import "core-js/modules/es.date.to-string.js";
|
|
9
|
-
import "core-js/modules/es.object.to-string.js";
|
|
10
|
-
import "core-js/modules/es.regexp.to-string.js";
|
|
11
|
-
import "core-js/modules/es.array.for-each.js";
|
|
12
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
13
|
-
import "core-js/modules/es.object.keys.js";
|
|
14
|
-
import "core-js/modules/es.symbol.js";
|
|
15
|
-
import "core-js/modules/es.array.filter.js";
|
|
16
|
-
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
17
|
-
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
18
|
-
import "core-js/modules/es.object.define-properties.js";
|
|
19
|
-
import "core-js/modules/es.object.define-property.js";
|
|
20
1
|
/**
|
|
21
2
|
* File: /auth/provider/keycloakProvider.tsx
|
|
22
3
|
* Project: app
|
|
@@ -50,134 +31,108 @@ import React, { useMemo, useEffect, useState } from "react";
|
|
|
50
31
|
import { useAuthConfig } from "../hooks/useAuthConfig";
|
|
51
32
|
import { useAuthState } from "../state";
|
|
52
33
|
import { AfterAuth } from "./afterAuth";
|
|
53
|
-
|
|
54
|
-
export
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var authConfig = useAuthConfig();
|
|
77
|
-
var _useState = useState("token" in query && (((_query$token = query.token) === null || _query$token === void 0 ? void 0 : _query$token.toString()) || true) || auth.token || false),
|
|
78
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
79
|
-
token = _useState2[0],
|
|
80
|
-
setToken = _useState2[1];
|
|
81
|
-
var _useState3 = useState("refreshToken" in query && (((_query$refreshToken = query.refreshToken) === null || _query$refreshToken === void 0 ? void 0 : _query$refreshToken.toString()) || true) || auth.refreshToken || false),
|
|
82
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
83
|
-
refreshToken = _useState4[0],
|
|
84
|
-
setRefreshToken = _useState4[1];
|
|
85
|
-
useEffect(function () {
|
|
86
|
-
var _this3 = this,
|
|
87
|
-
_window2,
|
|
88
|
-
_window2$ReactNativeW,
|
|
89
|
-
_window3,
|
|
90
|
-
_window3$parent;
|
|
91
|
-
_newArrowCheck(this, _this2);
|
|
34
|
+
const logger = console;
|
|
35
|
+
export const KeycloakProvider = _ref => {
|
|
36
|
+
var _query$token, _query$refreshToken;
|
|
37
|
+
let {
|
|
38
|
+
children,
|
|
39
|
+
cookies,
|
|
40
|
+
debug,
|
|
41
|
+
keycloakConfig,
|
|
42
|
+
keycloakInitOptions,
|
|
43
|
+
loadingComponent
|
|
44
|
+
} = _ref;
|
|
45
|
+
const [auth] = useAuthState();
|
|
46
|
+
const LoadingComponent = loadingComponent || (() => /*#__PURE__*/React.createElement(React.Fragment, null, debug ? "authenticating" : null));
|
|
47
|
+
const {
|
|
48
|
+
query
|
|
49
|
+
} = MultiPlatform.isNext() ? useRouter() : {
|
|
50
|
+
query: {}
|
|
51
|
+
};
|
|
52
|
+
const authConfig = useAuthConfig();
|
|
53
|
+
const [token, setToken] = useState("token" in query && (((_query$token = query.token) === null || _query$token === void 0 ? void 0 : _query$token.toString()) || true) || auth.token || false);
|
|
54
|
+
const [refreshToken, setRefreshToken] = useState("refreshToken" in query && (((_query$refreshToken = query.refreshToken) === null || _query$refreshToken === void 0 ? void 0 : _query$refreshToken.toString()) || true) || auth.refreshToken || false);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
var _window2, _window2$ReactNativeW, _window3, _window3$parent;
|
|
92
57
|
if (token !== true && refreshToken !== true) return;
|
|
93
58
|
if (debug) logger.debug("post message", {
|
|
94
59
|
type: "LOADED"
|
|
95
60
|
});
|
|
96
|
-
(authConfig.messageHandlerKeys || []).forEach(
|
|
61
|
+
(authConfig.messageHandlerKeys || []).forEach(key => {
|
|
97
62
|
var _window, _window$webkit, _window$webkit$messag, _window$webkit$messag2;
|
|
98
|
-
_newArrowCheck(this, _this3);
|
|
99
63
|
(_window = window) === null || _window === void 0 ? void 0 : (_window$webkit = _window.webkit) === null || _window$webkit === void 0 ? void 0 : (_window$webkit$messag = _window$webkit.messageHandlers) === null || _window$webkit$messag === void 0 ? void 0 : (_window$webkit$messag2 = _window$webkit$messag[key]) === null || _window$webkit$messag2 === void 0 ? void 0 : _window$webkit$messag2.postMessage(JSON.stringify({
|
|
100
64
|
type: "LOADED"
|
|
101
65
|
}));
|
|
102
|
-
}
|
|
66
|
+
});
|
|
103
67
|
(_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$ReactNativeW = _window2.ReactNativeWebView) === null || _window2$ReactNativeW === void 0 ? void 0 : _window2$ReactNativeW.postMessage(JSON.stringify({
|
|
104
68
|
type: "LOADED"
|
|
105
69
|
}));
|
|
106
70
|
(_window3 = window) === null || _window3 === void 0 ? void 0 : (_window3$parent = _window3.parent) === null || _window3$parent === void 0 ? void 0 : _window3$parent.postMessage(JSON.stringify({
|
|
107
71
|
type: "LOADED"
|
|
108
72
|
}));
|
|
109
|
-
}
|
|
110
|
-
useEffect(
|
|
111
|
-
var _this4 = this;
|
|
112
|
-
_newArrowCheck(this, _this2);
|
|
73
|
+
}, []);
|
|
74
|
+
useEffect(() => {
|
|
113
75
|
if (token !== true) return;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var data = e === null || e === void 0 ? void 0 : e.data;
|
|
76
|
+
const messageCallback = e => {
|
|
77
|
+
let data = e === null || e === void 0 ? void 0 : e.data;
|
|
117
78
|
if (typeof data === "string") {
|
|
118
79
|
try {
|
|
119
80
|
data = JSON.parse(data);
|
|
120
81
|
} catch (err) {}
|
|
121
82
|
}
|
|
122
83
|
if (debug) logger.debug("received message", data);
|
|
123
|
-
|
|
84
|
+
const message = data;
|
|
124
85
|
if (!message.type) return;
|
|
125
86
|
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
126
87
|
if (debug) logger.debug("setting token", message.payload);
|
|
127
88
|
setToken(message.payload);
|
|
128
89
|
}
|
|
129
|
-
}
|
|
90
|
+
};
|
|
130
91
|
if (debug) logger.debug("listening for message", {
|
|
131
92
|
type: "TOKEN",
|
|
132
93
|
payload: "<some_token>"
|
|
133
94
|
});
|
|
134
95
|
window.addEventListener("message", messageCallback);
|
|
135
|
-
return
|
|
136
|
-
_newArrowCheck(this, _this4);
|
|
96
|
+
return () => {
|
|
137
97
|
window.removeEventListener("message", messageCallback);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
useEffect(
|
|
141
|
-
var _this5 = this;
|
|
142
|
-
_newArrowCheck(this, _this2);
|
|
98
|
+
};
|
|
99
|
+
}, []);
|
|
100
|
+
useEffect(() => {
|
|
143
101
|
if (refreshToken !== true) return;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var data = e === null || e === void 0 ? void 0 : e.data;
|
|
102
|
+
const messageCallback = e => {
|
|
103
|
+
let data = e === null || e === void 0 ? void 0 : e.data;
|
|
147
104
|
if (typeof data === "string") {
|
|
148
105
|
try {
|
|
149
106
|
data = JSON.parse(data);
|
|
150
107
|
} catch (err) {}
|
|
151
108
|
}
|
|
152
109
|
if (debug) logger.debug("received message", data);
|
|
153
|
-
|
|
110
|
+
const message = data;
|
|
154
111
|
if (!message.type) return;
|
|
155
112
|
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
156
113
|
if (debug) logger.debug("setting refresh token", message.payload);
|
|
157
114
|
setRefreshToken(message.payload);
|
|
158
115
|
}
|
|
159
|
-
}
|
|
116
|
+
};
|
|
160
117
|
if (debug) logger.debug("listening for message", {
|
|
161
118
|
type: "REFRESH_TOKEN",
|
|
162
119
|
payload: "<some_refresh_token>"
|
|
163
120
|
});
|
|
164
121
|
window.addEventListener("message", messageCallback);
|
|
165
|
-
return
|
|
166
|
-
_newArrowCheck(this, _this5);
|
|
122
|
+
return () => {
|
|
167
123
|
window.removeEventListener("message", messageCallback);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var initOptions = _objectSpread(_objectSpread({}, defaultKeycloakInitOptions), keycloakInitOptions);
|
|
124
|
+
};
|
|
125
|
+
}, []);
|
|
126
|
+
const keycloak = useMemo(() => typeof window !== "undefined" && new Keycloak({
|
|
127
|
+
url: keycloakConfig.baseUrl,
|
|
128
|
+
realm: keycloakConfig.realm,
|
|
129
|
+
clientId: keycloakConfig.clientId
|
|
130
|
+
}), []);
|
|
131
|
+
const initOptions = useMemo(() => {
|
|
132
|
+
const initOptions = {
|
|
133
|
+
...defaultKeycloakInitOptions,
|
|
134
|
+
...keycloakInitOptions
|
|
135
|
+
};
|
|
181
136
|
if (token && typeof token === "string") {
|
|
182
137
|
initOptions.token = token;
|
|
183
138
|
if (refreshToken && typeof refreshToken === "string") initOptions.refreshToken = refreshToken;
|
|
@@ -185,7 +140,7 @@ export var KeycloakProvider = function KeycloakProvider(_ref) {
|
|
|
185
140
|
initOptions.onLoad = undefined;
|
|
186
141
|
}
|
|
187
142
|
return initOptions;
|
|
188
|
-
}
|
|
143
|
+
}, [keycloakInitOptions, token, refreshToken]);
|
|
189
144
|
if (token === true || refreshToken === true) return /*#__PURE__*/React.createElement(LoadingComponent, null);
|
|
190
145
|
if (cookies && authConfig.ssr) {
|
|
191
146
|
return (
|
|
@@ -209,8 +164,8 @@ export var KeycloakProvider = function KeycloakProvider(_ref) {
|
|
|
209
164
|
authClient: keycloak,
|
|
210
165
|
LoadingComponent: /*#__PURE__*/React.createElement(LoadingComponent, null)
|
|
211
166
|
}, /*#__PURE__*/React.createElement(AfterAuth, null, children));
|
|
212
|
-
}
|
|
213
|
-
export
|
|
167
|
+
};
|
|
168
|
+
export const defaultKeycloakInitOptions = {
|
|
214
169
|
checkLoginIframe: true,
|
|
215
170
|
checkLoginIframeInterval: 5,
|
|
216
171
|
enableLogging: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keycloakProvider.js","names":["Keycloak","MultiPlatform","ReactKeycloakProvider","SSRKeycloakProvider","SSRCookies","useRouter","React","useMemo","useEffect","useState","useAuthConfig","useAuthState","AfterAuth","logger","console","KeycloakProvider","children","cookies","debug","keycloakConfig","keycloakInitOptions","loadingComponent","auth","LoadingComponent","isNext","query","authConfig","token","toString","setToken","refreshToken","setRefreshToken","type","messageHandlerKeys","forEach","key","window","webkit","messageHandlers","postMessage","JSON","stringify","ReactNativeWebView","parent","messageCallback","e","data","parse","err","message","toUpperCase","payload","addEventListener","removeEventListener","keycloak","url","baseUrl","realm","clientId","initOptions","defaultKeycloakInitOptions","checkLoginIframe","onLoad","undefined","ssr","checkLoginIframeInterval","enableLogging","pkceMethod"],"sources":["../../src/provider/keycloakProvider.tsx"],"sourcesContent":["/**\n * File: /auth/provider/keycloakProvider.tsx\n * Project: app\n * File Created: 08-11-2022 03:12:43\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:07:46\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Keycloak, { KeycloakInitOptions } from \"keycloak-js\";\nimport { MultiPlatform } from \"multiplatform.one\";\nimport { ReactKeycloakProvider } from \"@react-keycloak/web\";\nimport { SSRKeycloakProvider, SSRCookies } from \"@react-keycloak/ssr\";\nimport { useRouter } from \"next/router\";\nimport React, {\n FC,\n ReactNode,\n useMemo,\n useEffect,\n useState,\n ComponentType,\n} from \"react\";\nimport { useAuthConfig } from \"../hooks/useAuthConfig\";\nimport { useAuthState } from \"../state\";\nimport { AfterAuth } from \"./afterAuth\";\n\nexport interface KeycloakProviderProps {\n children: ReactNode;\n cookies?: unknown;\n debug?: boolean;\n disabled?: boolean;\n keycloakConfig: KeycloakConfig;\n keycloakInitOptions?: KeycloakInitOptions;\n loadingComponent?: ComponentType;\n}\n\nconst logger = console;\n\nexport const KeycloakProvider: FC<KeycloakProviderProps> = ({\n children,\n cookies,\n debug,\n keycloakConfig,\n keycloakInitOptions,\n loadingComponent,\n}: KeycloakProviderProps) => {\n const [auth] = useAuthState();\n const LoadingComponent =\n loadingComponent || (() => <>{debug ? \"authenticating\" : null}</>);\n const { query } = MultiPlatform.isNext() ? useRouter() : { query: {} };\n const authConfig = useAuthConfig();\n const [token, setToken] = useState<string | boolean>(\n (\"token\" in query && (query.token?.toString() || true)) ||\n auth.token ||\n false\n );\n const [refreshToken, setRefreshToken] = useState<string | boolean>(\n (\"refreshToken\" in query && (query.refreshToken?.toString() || true)) ||\n auth.refreshToken ||\n false\n );\n\n useEffect(() => {\n if (token !== true && refreshToken !== true) return;\n if (debug) logger.debug(\"post message\", { type: \"LOADED\" });\n (authConfig.messageHandlerKeys || []).forEach((key: string) => {\n window?.webkit?.messageHandlers?.[key]?.postMessage(\n JSON.stringify({ type: \"LOADED\" })\n );\n });\n window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: \"LOADED\" }));\n window?.parent?.postMessage(JSON.stringify({ type: \"LOADED\" }));\n }, []);\n\n useEffect(() => {\n if (token !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === \"string\") {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug(\"received message\", data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === \"TOKEN\" && message.payload) {\n if (debug) logger.debug(\"setting token\", message.payload);\n setToken(message.payload);\n }\n };\n if (debug)\n logger.debug(\"listening for message\", {\n type: \"TOKEN\",\n payload: \"<some_token>\",\n });\n window.addEventListener(\"message\", messageCallback);\n return () => {\n window.removeEventListener(\"message\", messageCallback);\n };\n }, []);\n\n useEffect(() => {\n if (refreshToken !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === \"string\") {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug(\"received message\", data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === \"REFRESH_TOKEN\" && message.payload) {\n if (debug) logger.debug(\"setting refresh token\", message.payload);\n setRefreshToken(message.payload);\n }\n };\n if (debug)\n logger.debug(\"listening for message\", {\n type: \"REFRESH_TOKEN\",\n payload: \"<some_refresh_token>\",\n });\n window.addEventListener(\"message\", messageCallback);\n return () => {\n window.removeEventListener(\"message\", messageCallback);\n };\n }, []);\n\n const keycloak = useMemo(\n () =>\n typeof window !== \"undefined\" &&\n new Keycloak({\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }),\n []\n );\n\n const initOptions = useMemo(() => {\n const initOptions = {\n ...defaultKeycloakInitOptions,\n ...keycloakInitOptions,\n };\n if (token && typeof token === \"string\") {\n initOptions.token = token;\n if (refreshToken && typeof refreshToken === \"string\")\n initOptions.refreshToken = refreshToken;\n initOptions.checkLoginIframe = false;\n initOptions.onLoad = undefined;\n }\n return initOptions;\n }, [keycloakInitOptions, token, refreshToken]);\n\n if (token === true || refreshToken === true) return <LoadingComponent />;\n if (cookies && authConfig.ssr) {\n return (\n // @ts-ignore\n <SSRKeycloakProvider\n initOptions={initOptions}\n keycloakConfig={{\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }}\n persistor={SSRCookies(cookies)}\n LoadingComponent={<LoadingComponent />}\n >\n <AfterAuth>{children}</AfterAuth>\n </SSRKeycloakProvider>\n );\n }\n if (!keycloak) return <>{children}</>;\n return (\n <ReactKeycloakProvider\n initOptions={initOptions}\n authClient={keycloak}\n LoadingComponent={<LoadingComponent />}\n >\n <AfterAuth>{children}</AfterAuth>\n </ReactKeycloakProvider>\n );\n};\n\nexport interface KeycloakConfig {\n clientId: string;\n realm: string;\n scheme?: string;\n baseUrl: string;\n}\n\nexport const defaultKeycloakInitOptions: KeycloakInitOptions = {\n checkLoginIframe: true,\n checkLoginIframeInterval: 5,\n enableLogging: false,\n onLoad: \"check-sso\",\n pkceMethod: \"S256\",\n};\n\nexport interface MessageSchema {\n type: string;\n payload?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,QAAQ,MAA+B,aAAa;AAC3D,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,qBAAqB,QAAQ,qBAAqB;AAC3D,SAASC,mBAAmB,EAAEC,UAAU,QAAQ,qBAAqB;AACrE,SAASC,SAAS,QAAQ,aAAa;AACvC,OAAOC,KAAK,IAGVC,OAAO,EACPC,SAAS,EACTC,QAAQ,QAEH,OAAO;AACd,SAASC,aAAa;AACtB,SAASC,YAAY;AACrB,SAASC,SAAS;AAYlB,IAAMC,MAAM,GAAGC,OAAO;AAEtB,OAAO,IAAMC,gBAA2C,GAAG,gCAO9B;EAAA;IAAA;IAAA;EAAA;EAAA,IAN3BC,QAAQ,QAARA,QAAQ;IACRC,OAAO,QAAPA,OAAO;IACPC,KAAK,QAALA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uC;QAC3B,CAAE;QACF,SAAS,EAAEtD,UAAU,CAACa,OAAO,CAAE;QAC/B,gBAAgB,eAAE,oBAAC,gBAAgB;MAAI,gBAEvC,oBAAC,SAAS,QAAED,QAAQ,CAAa;IACb;EAE1B;EACA,IAAI,CAACsC,QAAQ,EAAE,oBAAO,0CAAGtC,QAAQ,CAAI;EACrC,oBACE,oBAAC,qBAAqB;IACpB,WAAW,EAAE2C,WAAY;IACzB,UAAU,EAAEL,QAAS;IACrB,gBAAgB,eAAE,oBAAC,gBAAgB;EAAI,gBAEvC,oBAAC,SAAS,QAAEtC,QAAQ,CAAa,CACX;AAE5B,CAAC;AASD,OAAO,IAAM4C,0BAA+C,GAAG;EAC7DC,gBAAgB,EAAE,IAAI;EACtBI,wBAAwB,EAAE,CAAC;EAC3BC,aAAa,EAAE,KAAK;EACpBJ,MAAM,EAAE,WAAW;EACnBK,UAAU,EAAE;AACd,CAAC"}
|
|
1
|
+
{"version":3,"file":"keycloakProvider.js","names":["Keycloak","MultiPlatform","ReactKeycloakProvider","SSRKeycloakProvider","SSRCookies","useRouter","React","useMemo","useEffect","useState","useAuthConfig","useAuthState","AfterAuth","logger","console","KeycloakProvider","children","cookies","debug","keycloakConfig","keycloakInitOptions","loadingComponent","auth","LoadingComponent","query","isNext","authConfig","token","setToken","toString","refreshToken","setRefreshToken","type","messageHandlerKeys","forEach","key","window","webkit","messageHandlers","postMessage","JSON","stringify","ReactNativeWebView","parent","messageCallback","e","data","parse","err","message","toUpperCase","payload","addEventListener","removeEventListener","keycloak","url","baseUrl","realm","clientId","initOptions","defaultKeycloakInitOptions","checkLoginIframe","onLoad","undefined","ssr","checkLoginIframeInterval","enableLogging","pkceMethod"],"sources":["../../src/provider/keycloakProvider.tsx"],"sourcesContent":["/**\n * File: /auth/provider/keycloakProvider.tsx\n * Project: app\n * File Created: 08-11-2022 03:12:43\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:07:46\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Keycloak, { KeycloakInitOptions } from \"keycloak-js\";\nimport { MultiPlatform } from \"multiplatform.one\";\nimport { ReactKeycloakProvider } from \"@react-keycloak/web\";\nimport { SSRKeycloakProvider, SSRCookies } from \"@react-keycloak/ssr\";\nimport { useRouter } from \"next/router\";\nimport React, {\n FC,\n ReactNode,\n useMemo,\n useEffect,\n useState,\n ComponentType,\n} from \"react\";\nimport { useAuthConfig } from \"../hooks/useAuthConfig\";\nimport { useAuthState } from \"../state\";\nimport { AfterAuth } from \"./afterAuth\";\n\nexport interface KeycloakProviderProps {\n children: ReactNode;\n cookies?: unknown;\n debug?: boolean;\n disabled?: boolean;\n keycloakConfig: KeycloakConfig;\n keycloakInitOptions?: KeycloakInitOptions;\n loadingComponent?: ComponentType;\n}\n\nconst logger = console;\n\nexport const KeycloakProvider: FC<KeycloakProviderProps> = ({\n children,\n cookies,\n debug,\n keycloakConfig,\n keycloakInitOptions,\n loadingComponent,\n}: KeycloakProviderProps) => {\n const [auth] = useAuthState();\n const LoadingComponent =\n loadingComponent || (() => <>{debug ? \"authenticating\" : null}</>);\n const { query } = MultiPlatform.isNext() ? useRouter() : { query: {} };\n const authConfig = useAuthConfig();\n const [token, setToken] = useState<string | boolean>(\n (\"token\" in query && (query.token?.toString() || true)) ||\n auth.token ||\n false\n );\n const [refreshToken, setRefreshToken] = useState<string | boolean>(\n (\"refreshToken\" in query && (query.refreshToken?.toString() || true)) ||\n auth.refreshToken ||\n false\n );\n\n useEffect(() => {\n if (token !== true && refreshToken !== true) return;\n if (debug) logger.debug(\"post message\", { type: \"LOADED\" });\n (authConfig.messageHandlerKeys || []).forEach((key: string) => {\n window?.webkit?.messageHandlers?.[key]?.postMessage(\n JSON.stringify({ type: \"LOADED\" })\n );\n });\n window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: \"LOADED\" }));\n window?.parent?.postMessage(JSON.stringify({ type: \"LOADED\" }));\n }, []);\n\n useEffect(() => {\n if (token !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === \"string\") {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug(\"received message\", data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === \"TOKEN\" && message.payload) {\n if (debug) logger.debug(\"setting token\", message.payload);\n setToken(message.payload);\n }\n };\n if (debug)\n logger.debug(\"listening for message\", {\n type: \"TOKEN\",\n payload: \"<some_token>\",\n });\n window.addEventListener(\"message\", messageCallback);\n return () => {\n window.removeEventListener(\"message\", messageCallback);\n };\n }, []);\n\n useEffect(() => {\n if (refreshToken !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === \"string\") {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug(\"received message\", data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === \"REFRESH_TOKEN\" && message.payload) {\n if (debug) logger.debug(\"setting refresh token\", message.payload);\n setRefreshToken(message.payload);\n }\n };\n if (debug)\n logger.debug(\"listening for message\", {\n type: \"REFRESH_TOKEN\",\n payload: \"<some_refresh_token>\",\n });\n window.addEventListener(\"message\", messageCallback);\n return () => {\n window.removeEventListener(\"message\", messageCallback);\n };\n }, []);\n\n const keycloak = useMemo(\n () =>\n typeof window !== \"undefined\" &&\n new Keycloak({\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }),\n []\n );\n\n const initOptions = useMemo(() => {\n const initOptions = {\n ...defaultKeycloakInitOptions,\n ...keycloakInitOptions,\n };\n if (token && typeof token === \"string\") {\n initOptions.token = token;\n if (refreshToken && typeof refreshToken === \"string\")\n initOptions.refreshToken = refreshToken;\n initOptions.checkLoginIframe = false;\n initOptions.onLoad = undefined;\n }\n return initOptions;\n }, [keycloakInitOptions, token, refreshToken]);\n\n if (token === true || refreshToken === true) return <LoadingComponent />;\n if (cookies && authConfig.ssr) {\n return (\n // @ts-ignore\n <SSRKeycloakProvider\n initOptions={initOptions}\n keycloakConfig={{\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }}\n persistor={SSRCookies(cookies)}\n LoadingComponent={<LoadingComponent />}\n >\n <AfterAuth>{children}</AfterAuth>\n </SSRKeycloakProvider>\n );\n }\n if (!keycloak) return <>{children}</>;\n return (\n <ReactKeycloakProvider\n initOptions={initOptions}\n authClient={keycloak}\n LoadingComponent={<LoadingComponent />}\n >\n <AfterAuth>{children}</AfterAuth>\n </ReactKeycloakProvider>\n );\n};\n\nexport interface KeycloakConfig {\n clientId: string;\n realm: string;\n scheme?: string;\n baseUrl: string;\n}\n\nexport const defaultKeycloakInitOptions: KeycloakInitOptions = {\n checkLoginIframe: true,\n checkLoginIframeInterval: 5,\n enableLogging: false,\n onLoad: \"check-sso\",\n pkceMethod: \"S256\",\n};\n\nexport interface MessageSchema {\n type: string;\n payload?: string;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,QAAQ,MAA+B,aAAa;AAC3D,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,qBAAqB,QAAQ,qBAAqB;AAC3D,SAASC,mBAAmB,EAAEC,UAAU,QAAQ,qBAAqB;AACrE,SAASC,SAAS,QAAQ,aAAa;AACvC,OAAOC,KAAK,IAGVC,OAAO,EACP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ACsC,KAAK;UAC3BC,QAAQ,EAAEvC,cAAc,CAACuC;QAC3B,CAAE;QACF,SAAS,EAAEtD,UAAU,CAACa,OAAO,CAAE;QAC/B,gBAAgB,eAAE,oBAAC,gBAAgB;MAAI,gBAEvC,oBAAC,SAAS,QAAED,QAAQ,CAAa;IACb;EAE1B;EACA,IAAI,CAACsC,QAAQ,EAAE,oBAAO,0CAAGtC,QAAQ,CAAI;EACrC,oBACE,oBAAC,qBAAqB;IACpB,WAAW,EAAE2C,WAAY;IACzB,UAAU,EAAEL,QAAS;IACrB,gBAAgB,eAAE,oBAAC,gBAAgB;EAAI,gBAEvC,oBAAC,SAAS,QAAEtC,QAAQ,CAAa,CACX;AAE5B,CAAC;AASD,OAAO,MAAM4C,0BAA+C,GAAG;EAC7DC,gBAAgB,EAAE,IAAI;EACtBI,wBAAwB,EAAE,CAAC;EAC3BC,aAAa,EAAE,KAAK;EACpBJ,MAAM,EAAE,WAAW;EACnBK,UAAU,EAAE;AACd,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
|
|
2
|
-
var _this = this;
|
|
3
|
-
import "core-js/modules/es.function.bind.js";
|
|
4
1
|
/**
|
|
5
2
|
* File: /auth/provider/keycloakProvider.native.tsx
|
|
6
3
|
* Project: app
|
|
@@ -25,16 +22,20 @@ import "core-js/modules/es.function.bind.js";
|
|
|
25
22
|
* limitations under the License.
|
|
26
23
|
*/
|
|
27
24
|
|
|
28
|
-
import { KeycloakProvider as ExpoKeycloakProvider } from "expo-keycloak-auth";
|
|
29
25
|
import React from "react";
|
|
30
26
|
import { AfterAuth } from "./afterAuth";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
import { ExpoKeycloakProvider } from "../expo";
|
|
28
|
+
export const KeycloakProvider = _ref => {
|
|
29
|
+
let {
|
|
30
|
+
children,
|
|
31
|
+
keycloakConfig
|
|
32
|
+
} = _ref;
|
|
33
|
+
const clonedKeycloakConfig = {
|
|
34
|
+
...keycloakConfig,
|
|
35
|
+
url: keycloakConfig.baseUrl
|
|
36
|
+
};
|
|
36
37
|
// @ts-ignore
|
|
37
38
|
delete keycloakConfig.baseUrl;
|
|
38
|
-
return /*#__PURE__*/React.createElement(ExpoKeycloakProvider,
|
|
39
|
-
}
|
|
39
|
+
return /*#__PURE__*/React.createElement(ExpoKeycloakProvider, clonedKeycloakConfig, /*#__PURE__*/React.createElement(AfterAuth, null, children));
|
|
40
|
+
};
|
|
40
41
|
//# sourceMappingURL=keycloakProvider.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keycloakProvider.native.js","names":["
|
|
1
|
+
{"version":3,"file":"keycloakProvider.native.js","names":["React","AfterAuth","ExpoKeycloakProvider","KeycloakProvider","children","keycloakConfig","clonedKeycloakConfig","url","baseUrl"],"sources":["../../src/provider/keycloakProvider.native.tsx"],"sourcesContent":["/**\n * File: /auth/provider/keycloakProvider.native.tsx\n * Project: app\n * File Created: 08-11-2022 03:12:37\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 17:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { FC } from \"react\";\nimport type { KeycloakProviderProps } from \"./keycloakProvider\";\nimport { AfterAuth } from \"./afterAuth\";\nimport { ExpoKeycloakProvider } from \"../expo\";\nimport { KeycloakConfig } from \"keycloak-js\";\n\nexport const KeycloakProvider: FC<KeycloakProviderProps> = ({\n children,\n keycloakConfig,\n}: KeycloakProviderProps) => {\n const clonedKeycloakConfig = {\n ...(keycloakConfig as Omit<KeycloakConfig, \"baseUrl\">),\n url: keycloakConfig.baseUrl,\n };\n // @ts-ignore\n delete keycloakConfig.baseUrl;\n return (\n <ExpoKeycloakProvider {...clonedKeycloakConfig}>\n <AfterAuth>{children}</AfterAuth>\n </ExpoKeycloakProvider>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAc,OAAO;AAEjC,SAASC,SAAS;AAClB,SAASC,oBAAoB;AAG7B,OAAO,MAAMC,gBAA2C,GAAG,QAG9B;EAAA,IAH+B;IAC1DC,QAAQ;IACRC;EACqB,CAAC;EACtB,MAAMC,oBAAoB,GAAG;IAC3B,GAAID,cAAkD;IACtDE,GAAG,EAAEF,cAAc,CAACG;EACtB,CAAC;EACD;EACA,OAAOH,cAAc,CAACG,OAAO;EAC7B,oBACE,oBAAC,oBAAoB,EAAKF,oBAAoB,eAC5C,oBAAC,SAAS,QAAEF,QAAQ,CAAa,CACZ;AAE3B,CAAC"}
|
package/esm/state/index.js
CHANGED
|
@@ -27,9 +27,9 @@ import persist from "react-native-recoil-persist";
|
|
|
27
27
|
export function useAuthState() {
|
|
28
28
|
return useRecoilState(authState);
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export const authState = atom({
|
|
31
31
|
key: "auth",
|
|
32
|
-
|
|
32
|
+
default: {},
|
|
33
33
|
effects: [persist.persistAtom]
|
|
34
34
|
});
|
|
35
35
|
//# sourceMappingURL=index.js.map
|
package/esm/state/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["atom","useRecoilState","persist","useAuthState","authState","key","effects","persistAtom"],"sources":["../../src/state/index.ts"],"sourcesContent":["/**\n * File: /src/state/index.ts\n * Project: app\n * File Created: 22-11-2022 17:40:53\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 09:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { atom, useRecoilState } from \"recoil\";\nimport persist from \"react-native-recoil-persist\";\n\nexport function useAuthState() {\n return useRecoilState(authState);\n}\n\nexport const authState = atom<{ token?: string; refreshToken?: string }>({\n key: \"auth\",\n default: {},\n effects: [persist.persistAtom],\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,EAAEC,cAAc,QAAQ,QAAQ;AAC7C,OAAOC,OAAO,MAAM,6BAA6B;AAEjD,OAAO,SAASC,YAAY,GAAG;EAC7B,OAAOF,cAAc,CAACG,SAAS,CAAC;AAClC;AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","names":["atom","useRecoilState","persist","useAuthState","authState","key","default","effects","persistAtom"],"sources":["../../src/state/index.ts"],"sourcesContent":["/**\n * File: /src/state/index.ts\n * Project: app\n * File Created: 22-11-2022 17:40:53\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 09:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { atom, useRecoilState } from \"recoil\";\nimport persist from \"react-native-recoil-persist\";\n\nexport function useAuthState() {\n return useRecoilState(authState);\n}\n\nexport const authState = atom<{ token?: string; refreshToken?: string }>({\n key: \"auth\",\n default: {},\n effects: [persist.persistAtom],\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,EAAEC,cAAc,QAAQ,QAAQ;AAC7C,OAAOC,OAAO,MAAM,6BAA6B;AAEjD,OAAO,SAASC,YAAY,GAAG;EAC7B,OAAOF,cAAc,CAACG,SAAS,CAAC;AAClC;AAEA,OAAO,MAAMA,SAAS,GAAGJ,IAAI,CAA4C;EACvEK,GAAG,EAAE,MAAM;EACXC,OAAO,EAAE,CAAC,CAAC;EACXC,OAAO,EAAE,CAACL,OAAO,CAACM,WAAW;AAC/B,CAAC,CAAC"}
|
package/lib/Authenticated.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
require("core-js/modules/esnext.global-this.js");
|
|
2
|
-
require("core-js/modules/es.object.define-property.js");
|
|
3
1
|
(function (global, factory) {
|
|
4
2
|
if (typeof define === "function" && define.amd) {
|
|
5
|
-
define(["exports", "
|
|
3
|
+
define(["exports", "react", "./hooks"], factory);
|
|
6
4
|
} else if (typeof exports !== "undefined") {
|
|
7
|
-
factory(exports, require("
|
|
5
|
+
factory(exports, require("react"), require("./hooks"));
|
|
8
6
|
} else {
|
|
9
7
|
var mod = {
|
|
10
8
|
exports: {}
|
|
11
9
|
};
|
|
12
|
-
factory(mod.exports, global.
|
|
10
|
+
factory(mod.exports, global.react, global.hooks);
|
|
13
11
|
global.Authenticated = mod.exports;
|
|
14
12
|
}
|
|
15
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports,
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _hooks) {
|
|
16
14
|
"use strict";
|
|
17
15
|
|
|
18
16
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
@@ -21,32 +19,46 @@ require("core-js/modules/es.object.define-property.js");
|
|
|
21
19
|
});
|
|
22
20
|
_exports.Authenticated = void 0;
|
|
23
21
|
_exports.withAuthenticated = withAuthenticated;
|
|
24
|
-
_newArrowCheck2 = _interopRequireDefault(_newArrowCheck2);
|
|
25
22
|
_react = _interopRequireDefault(_react);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
/**
|
|
24
|
+
* File: /auth/Authenticated.tsx
|
|
25
|
+
* Project: app
|
|
26
|
+
* File Created: 08-11-2022 05:58:23
|
|
27
|
+
* Author: Clay Risser
|
|
28
|
+
* -----
|
|
29
|
+
* Last Modified: 22-11-2022 06:26:38
|
|
30
|
+
* Modified By: Clay Risser
|
|
31
|
+
* -----
|
|
32
|
+
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
33
|
+
*
|
|
34
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
35
|
+
* you may not use this file except in compliance with the License.
|
|
36
|
+
* You may obtain a copy of the License at
|
|
37
|
+
*
|
|
38
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
39
|
+
*
|
|
40
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
41
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
43
|
+
* See the License for the specific language governing permissions and
|
|
44
|
+
* limitations under the License.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
const Authenticated = props => {
|
|
48
|
+
const {
|
|
49
|
+
authenticated
|
|
50
|
+
} = (0, _hooks.useKeycloak)();
|
|
51
|
+
const login = (0, _hooks.useLogin)(props.loginRoute);
|
|
33
52
|
if (!props.disabled && !authenticated) {
|
|
34
53
|
if (authenticated === false) login();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}.bind(this);
|
|
39
|
-
return /*#__PURE__*/_react["default"].createElement(LoggedOutComponent, null);
|
|
54
|
+
const LoggedOutComponent = props.loggedOutComponent || (() => null);
|
|
55
|
+
return /*#__PURE__*/_react.default.createElement(LoggedOutComponent, null);
|
|
40
56
|
}
|
|
41
|
-
return /*#__PURE__*/_react
|
|
42
|
-
}
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, props.children);
|
|
58
|
+
};
|
|
43
59
|
_exports.Authenticated = Authenticated;
|
|
44
60
|
function withAuthenticated(Component) {
|
|
45
|
-
|
|
46
|
-
return function (props) {
|
|
47
|
-
(0, _newArrowCheck2["default"])(this, _this3);
|
|
48
|
-
return /*#__PURE__*/_react["default"].createElement(Authenticated, null, /*#__PURE__*/_react["default"].createElement(Component, props));
|
|
49
|
-
}.bind(this);
|
|
61
|
+
return props => /*#__PURE__*/_react.default.createElement(Authenticated, null, /*#__PURE__*/_react.default.createElement(Component, props));
|
|
50
62
|
}
|
|
51
63
|
});
|
|
52
64
|
//# sourceMappingURL=Authenticated.js.map
|
package/lib/Authenticated.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Authenticated.js","names":["Authenticated","props","
|
|
1
|
+
{"version":3,"file":"Authenticated.js","names":["Authenticated","props","authenticated","useKeycloak","login","useLogin","loginRoute","disabled","LoggedOutComponent","loggedOutComponent","children","withAuthenticated","Component"],"sources":["../src/Authenticated.tsx"],"sourcesContent":["/**\n * File: /auth/Authenticated.tsx\n * Project: app\n * File Created: 08-11-2022 05:58:23\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 06:26:38\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, FC, ReactNode } from \"react\";\nimport { useLogin, useKeycloak } from \"./hooks\";\n\nexport interface AuthenticatedProps {\n children: ReactNode;\n disabled?: boolean;\n loggedOutComponent?: ComponentType;\n loginRoute?: string;\n}\n\nexport const Authenticated: FC<AuthenticatedProps> = (\n props: AuthenticatedProps\n) => {\n const { authenticated } = useKeycloak();\n const login = useLogin(props.loginRoute);\n if (!props.disabled && !authenticated) {\n if (authenticated === false) login();\n const LoggedOutComponent = props.loggedOutComponent || (() => null);\n return <LoggedOutComponent />;\n }\n return <>{props.children}</>;\n};\n\nexport function withAuthenticated<P extends object>(\n Component: ComponentType<P>\n) {\n return (props: P) => (\n <Authenticated>\n <Component {...props} />\n </Authenticated>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAYO,MAAMA,aAAqC,GAChDC,KAAyB,IACtB;IACH,MAAM;MAAEC;IAAc,CAAC,GAAG,IAAAC,kBAAW,GAAE;IACvC,MAAMC,KAAK,GAAG,IAAAC,eAAQ,EAACJ,KAAK,CAACK,UAAU,CAAC;IACxC,IAAI,CAACL,KAAK,CAACM,QAAQ,IAAI,CAACL,aAAa,EAAE;MACrC,IAAIA,aAAa,KAAK,KAAK,EAAEE,KAAK,EAAE;MACpC,MAAMI,kBAAkB,GAAGP,KAAK,CAACQ,kBAAkB,KAAK,MAAM,IAAI,CAAC;MACnE,oBAAO,6BAAC,kBAAkB,OAAG;IAC/B;IACA,oBAAO,4DAAGR,KAAK,CAACS,QAAQ,CAAI;EAC9B,CAAC;EAAC;EAEK,SAASC,iBAAiB,CAC/BC,SAA2B,EAC3B;IACA,OAAQX,KAAQ,iBACd,6BAAC,aAAa,qBACZ,6BAAC,SAAS,EAAKA,KAAK,CAAI,CAE3B;EACH;AAAC"}
|
package/lib/authConfig.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require("core-js/modules/esnext.global-this.js");
|
|
2
|
-
require("core-js/modules/es.object.define-property.js");
|
|
3
1
|
(function (global, factory) {
|
|
4
2
|
if (typeof define === "function" && define.amd) {
|
|
5
3
|
define(["exports", "react"], factory);
|
|
@@ -43,11 +41,11 @@ require("core-js/modules/es.object.define-property.js");
|
|
|
43
41
|
* limitations under the License.
|
|
44
42
|
*/
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
const defaultAuthConfig = {
|
|
47
45
|
ssr: true
|
|
48
46
|
};
|
|
49
47
|
_exports.defaultAuthConfig = defaultAuthConfig;
|
|
50
|
-
|
|
48
|
+
const AuthConfigContext = /*#__PURE__*/(0, _react.createContext)(defaultAuthConfig);
|
|
51
49
|
_exports.AuthConfigContext = AuthConfigContext;
|
|
52
50
|
});
|
|
53
51
|
//# sourceMappingURL=authConfig.js.map
|
package/lib/authConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authConfig.js","names":["defaultAuthConfig","ssr","AuthConfigContext","createContext"],"sources":["../src/authConfig.ts"],"sourcesContent":["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from \"react\";\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authConfig.js","names":["defaultAuthConfig","ssr","AuthConfigContext","createContext"],"sources":["../src/authConfig.ts"],"sourcesContent":["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from \"react\";\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAIO,MAAMA,iBAA6B,GAAG;IAC3CC,GAAG,EAAE;EACP,CAAC;EAAC;EAEK,MAAMC,iBAAiB,gBAAG,IAAAC,oBAAa,EAAaH,iBAAiB,CAAC;EAAC;AAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/expo/ExpoKeycloakContext.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 26-11-2022 06:58:16
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 26-11-2022 08:38:25
|
|
8
|
+
* Modified By: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Risser Labs LLC (c) Copyright 2022
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
/// <reference types="react" />
|
|
25
|
+
import { AuthRequestPromptOptions, AuthSessionResult, TokenResponse } from "expo-auth-session";
|
|
26
|
+
export declare const ExpoKeycloakContext: import("react").Context<{
|
|
27
|
+
ready: boolean;
|
|
28
|
+
isLoggedIn?: boolean | undefined;
|
|
29
|
+
login: (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult | undefined>;
|
|
30
|
+
logout: () => undefined;
|
|
31
|
+
token: TokenResponse | null;
|
|
32
|
+
}>;
|