@multiplatform.one/keycloak 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/esm/expo/KeycloakContext.js +0 -28
- package/esm/expo/KeycloakContext.js.map +0 -1
- package/esm/expo/KeycloakProvider.js +0 -142
- package/esm/expo/KeycloakProvider.js.map +0 -1
- package/lib/expo/KeycloakContext.d.ts +0 -32
- package/lib/expo/KeycloakContext.js +0 -49
- package/lib/expo/KeycloakContext.js.map +0 -1
- package/lib/expo/KeycloakProvider.d.ts +0 -37
- package/lib/expo/KeycloakProvider.js +0 -138
- package/lib/expo/KeycloakProvider.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/keycloak",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "keycloak client for multiplatform.one ecosystem",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@babel/runtime": "^7.17.2",
|
|
50
|
+
"@react-native-async-storage/async-storage": "^1.17.11",
|
|
50
51
|
"@react-navigation/native": "^6.0.14",
|
|
51
52
|
"@risserlabs/solito": "^1.0.11",
|
|
52
53
|
"core-js": "^3.21.1",
|
|
@@ -70,6 +71,7 @@
|
|
|
70
71
|
"@babel/preset-react": "^7.18.6",
|
|
71
72
|
"@babel/preset-typescript": "^7.18.6",
|
|
72
73
|
"@babel/runtime": "^7.20.1",
|
|
74
|
+
"@react-native-async-storage/async-storage": "^1.17.11",
|
|
73
75
|
"@react-navigation/native": "^6.0.14",
|
|
74
76
|
"@risserlabs/solito": "^1.0.11",
|
|
75
77
|
"@types/color-string": "^1.5.2",
|
|
@@ -137,7 +139,6 @@
|
|
|
137
139
|
"dependencies": {
|
|
138
140
|
"@react-keycloak/ssr": "^3.3.0",
|
|
139
141
|
"@react-keycloak/web": "^3.4.0",
|
|
140
|
-
"@react-native-async-storage/async-storage": "^1.17.11",
|
|
141
142
|
"expo-auth-session": "^3.7.2"
|
|
142
143
|
}
|
|
143
144
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/expo/KeycloakContext.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:25:18
|
|
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
|
-
|
|
25
|
-
import { createContext } from "react";
|
|
26
|
-
import { KC_INITIAL_VALUE } from "./const";
|
|
27
|
-
export var KeycloakContext = /*#__PURE__*/createContext(KC_INITIAL_VALUE);
|
|
28
|
-
//# sourceMappingURL=KeycloakContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeycloakContext.js","names":["createContext","KC_INITIAL_VALUE","KeycloakContext"],"sources":["../../src/expo/KeycloakContext.ts"],"sourcesContent":["/**\n * File: /src/expo/KeycloakContext.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:25:18\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 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 {\n AuthRequestPromptOptions,\n AuthSessionResult,\n TokenResponse,\n} from \"expo-auth-session\";\nimport { createContext } from \"react\";\nimport { KC_INITIAL_VALUE } from \"./const\";\n\nexport const KeycloakContext = createContext<{\n ready: boolean;\n isLoggedIn?: boolean;\n login: (\n options?: AuthRequestPromptOptions\n ) => Promise<AuthSessionResult | undefined>;\n logout: () => undefined;\n token: TokenResponse | null;\n}>(KC_INITIAL_VALUE);\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;;AAOA,SAASA,aAAa,QAAQ,OAAO;AACrC,SAASC,gBAAgB;AAEzB,OAAO,IAAMC,eAAe,gBAAGF,aAAa,CAQzCC,gBAAgB,CAAC"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.object.keys.js";
|
|
2
|
-
import "core-js/modules/es.symbol.js";
|
|
3
|
-
import "core-js/modules/es.array.filter.js";
|
|
4
|
-
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
5
|
-
import "core-js/modules/es.array.for-each.js";
|
|
6
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
7
|
-
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
8
|
-
import "core-js/modules/es.object.define-properties.js";
|
|
9
|
-
import "core-js/modules/es.object.define-property.js";
|
|
10
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
11
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
12
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
13
|
-
import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
|
|
14
|
-
var _excluded = ["realm", "clientId", "url", "extraParams", "children"];
|
|
15
|
-
var _this = this;
|
|
16
|
-
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; }
|
|
17
|
-
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; }
|
|
18
|
-
import "core-js/modules/es.function.bind.js";
|
|
19
|
-
import "core-js/modules/es.array.concat.js";
|
|
20
|
-
import "core-js/modules/es.object.to-string.js";
|
|
21
|
-
import "core-js/modules/es.promise.js";
|
|
22
|
-
/**
|
|
23
|
-
* File: /src/expo/KeycloakProvider.ts
|
|
24
|
-
* Project: @multiplatform.one/keycloak
|
|
25
|
-
* File Created: 26-11-2022 06:58:16
|
|
26
|
-
* Author: Clay Risser
|
|
27
|
-
* -----
|
|
28
|
-
* Last Modified: 26-11-2022 08:06:40
|
|
29
|
-
* Modified By: Clay Risser
|
|
30
|
-
* -----
|
|
31
|
-
* Risser Labs LLC (c) Copyright 2022
|
|
32
|
-
*
|
|
33
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
34
|
-
* you may not use this file except in compliance with the License.
|
|
35
|
-
* You may obtain a copy of the License at
|
|
36
|
-
*
|
|
37
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
38
|
-
*
|
|
39
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
-
* See the License for the specific language governing permissions and
|
|
43
|
-
* limitations under the License.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
import React, { useCallback, useEffect } from "react";
|
|
47
|
-
import { Platform } from "react-native";
|
|
48
|
-
import * as AuthSession from "expo-auth-session";
|
|
49
|
-
import { useAuthRequest, useAutoDiscovery } from "expo-auth-session";
|
|
50
|
-
import { KeycloakContext } from "./KeycloakContext";
|
|
51
|
-
import { useTokenStorage } from "./useTokenStorage";
|
|
52
|
-
import { handleTokenExchange, getRealmURL } from "./helpers";
|
|
53
|
-
import { NATIVE_REDIRECT_PATH } from "./const";
|
|
54
|
-
export var KeycloakProvider = function KeycloakProvider(_ref) {
|
|
55
|
-
var _options$scheme,
|
|
56
|
-
_options$nativeRedire,
|
|
57
|
-
_this2 = this;
|
|
58
|
-
_newArrowCheck(this, _this);
|
|
59
|
-
var realm = _ref.realm,
|
|
60
|
-
clientId = _ref.clientId,
|
|
61
|
-
url = _ref.url,
|
|
62
|
-
extraParams = _ref.extraParams,
|
|
63
|
-
children = _ref.children,
|
|
64
|
-
options = _objectWithoutProperties(_ref, _excluded);
|
|
65
|
-
var discovery = useAutoDiscovery(getRealmURL({
|
|
66
|
-
realm: realm,
|
|
67
|
-
url: url
|
|
68
|
-
}));
|
|
69
|
-
var redirectUri = AuthSession.makeRedirectUri({
|
|
70
|
-
"native": "".concat((_options$scheme = options.scheme) !== null && _options$scheme !== void 0 ? _options$scheme : "exp", "://").concat((_options$nativeRedire = options.nativeRedirectPath) !== null && _options$nativeRedire !== void 0 ? _options$nativeRedire : NATIVE_REDIRECT_PATH),
|
|
71
|
-
useProxy: !options.scheme
|
|
72
|
-
});
|
|
73
|
-
var config = {
|
|
74
|
-
clientId: clientId,
|
|
75
|
-
extraParams: extraParams,
|
|
76
|
-
realm: realm,
|
|
77
|
-
redirectUri: redirectUri,
|
|
78
|
-
url: url
|
|
79
|
-
};
|
|
80
|
-
var _useAuthRequest = useAuthRequest(_objectSpread({
|
|
81
|
-
usePKCE: false
|
|
82
|
-
}, config), discovery),
|
|
83
|
-
_useAuthRequest2 = _slicedToArray(_useAuthRequest, 3),
|
|
84
|
-
request = _useAuthRequest2[0],
|
|
85
|
-
response = _useAuthRequest2[1],
|
|
86
|
-
promptAsync = _useAuthRequest2[2];
|
|
87
|
-
var _useTokenStorage = useTokenStorage(options, config, discovery),
|
|
88
|
-
_useTokenStorage2 = _slicedToArray(_useTokenStorage, 2),
|
|
89
|
-
currentToken = _useTokenStorage2[0],
|
|
90
|
-
updateToken = _useTokenStorage2[1];
|
|
91
|
-
var handleLogin = useCallback(function () {
|
|
92
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
93
|
-
return promptAsync(options);
|
|
94
|
-
}, [request]);
|
|
95
|
-
function handleLogout() {
|
|
96
|
-
if (!currentToken) throw new Error("Not logged in.");
|
|
97
|
-
try {
|
|
98
|
-
if (discovery !== null && discovery !== void 0 && discovery.revocationEndpoint) {
|
|
99
|
-
AuthSession.revokeAsync(_objectSpread({
|
|
100
|
-
token: currentToken === null || currentToken === void 0 ? void 0 : currentToken.accessToken
|
|
101
|
-
}, config), discovery);
|
|
102
|
-
}
|
|
103
|
-
if (discovery !== null && discovery !== void 0 && discovery.endSessionEndpoint) {
|
|
104
|
-
fetch("".concat(discovery.endSessionEndpoint), {
|
|
105
|
-
method: "POST",
|
|
106
|
-
headers: {
|
|
107
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
108
|
-
},
|
|
109
|
-
body: "client_id=".concat(clientId, "&refresh_token=").concat(currentToken.refreshToken)
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (Platform.OS === "ios") {
|
|
113
|
-
AuthSession.dismiss();
|
|
114
|
-
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.log(error);
|
|
117
|
-
}
|
|
118
|
-
updateToken(null);
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
useEffect(function () {
|
|
122
|
-
_newArrowCheck(this, _this2);
|
|
123
|
-
if (response) {
|
|
124
|
-
handleTokenExchange({
|
|
125
|
-
response: response,
|
|
126
|
-
discovery: discovery,
|
|
127
|
-
config: config
|
|
128
|
-
}).then(updateToken);
|
|
129
|
-
}
|
|
130
|
-
}.bind(this), [response]);
|
|
131
|
-
return /*#__PURE__*/React.createElement(KeycloakContext.Provider, {
|
|
132
|
-
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
133
|
-
value: {
|
|
134
|
-
isLoggedIn: currentToken === undefined ? undefined : !!currentToken,
|
|
135
|
-
login: handleLogin,
|
|
136
|
-
logout: handleLogout,
|
|
137
|
-
ready: discovery !== null && request !== null && currentToken !== undefined,
|
|
138
|
-
token: currentToken
|
|
139
|
-
}
|
|
140
|
-
}, children);
|
|
141
|
-
}.bind(this);
|
|
142
|
-
//# sourceMappingURL=KeycloakProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeycloakProvider.js","names":["React","useCallback","useEffect","Platform","AuthSession","useAuthRequest","useAutoDiscovery","KeycloakContext","useTokenStorage","handleTokenExchange","getRealmURL","NATIVE_REDIRECT_PATH","KeycloakProvider","realm","clientId","url","extraParams","children","options","discovery","redirectUri","makeRedirectUri","scheme","nativeRedirectPath","useProxy","config","usePKCE","request","response","promptAsync","currentToken","updateToken","handleLogin","handleLogout","Error","revocationEndpoint","revokeAsync","token","accessToken","endSessionEndpoint","fetch","method","headers","body","refreshToken","OS","dismiss","error","console","log","undefined","then","isLoggedIn","login","logout","ready"],"sources":["../../src/expo/KeycloakProvider.tsx"],"sourcesContent":["/**\n * File: /src/expo/KeycloakProvider.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:06:40\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 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, { ReactNode, useCallback, useEffect } from \"react\";\nimport { Platform } from \"react-native\";\nimport * as AuthSession from \"expo-auth-session\";\nimport {\n useAuthRequest,\n useAutoDiscovery,\n AuthRequestConfig,\n} from \"expo-auth-session\";\nimport { KeycloakContext } from \"./KeycloakContext\";\nimport { useTokenStorage } from \"./useTokenStorage\";\nimport { handleTokenExchange, getRealmURL } from \"./helpers\";\nimport { NATIVE_REDIRECT_PATH } from \"./const\";\n\nexport interface IKeycloakConfiguration extends Partial<AuthRequestConfig> {\n children: ReactNode;\n clientId: string;\n disableAutoRefresh?: boolean;\n nativeRedirectPath?: string;\n realm: string;\n refreshTimeBuffer?: number;\n scheme?: string;\n tokenStorageKey?: string;\n url: string;\n}\n\nexport const KeycloakProvider = ({\n realm,\n clientId,\n url,\n extraParams,\n children,\n ...options\n}: IKeycloakConfiguration) => {\n const discovery = useAutoDiscovery(getRealmURL({ realm, url }));\n const redirectUri = AuthSession.makeRedirectUri({\n native: `${options.scheme ?? \"exp\"}://${\n options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH\n }`,\n useProxy: !options.scheme,\n });\n const config = {\n clientId,\n extraParams,\n realm,\n redirectUri,\n url,\n };\n const [request, response, promptAsync] = useAuthRequest(\n { usePKCE: false, ...config },\n discovery\n );\n const [currentToken, updateToken] = useTokenStorage(\n options,\n config,\n discovery!\n );\n\n const handleLogin = useCallback(\n (options: AuthSession.AuthRequestPromptOptions = {}) =>\n promptAsync(options),\n [request]\n );\n\n function handleLogout() {\n if (!currentToken) throw new Error(\"Not logged in.\");\n try {\n if (discovery?.revocationEndpoint) {\n AuthSession.revokeAsync(\n { token: currentToken?.accessToken, ...config },\n discovery\n );\n }\n if (discovery?.endSessionEndpoint) {\n fetch(`${discovery.endSessionEndpoint}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`,\n });\n }\n if (Platform.OS === \"ios\") {\n AuthSession.dismiss();\n }\n } catch (error) {\n console.log(error);\n }\n updateToken(null);\n return undefined;\n }\n\n useEffect(() => {\n if (response) {\n handleTokenExchange({ response, discovery: discovery!, config }).then(\n updateToken\n );\n }\n }, [response]);\n\n return (\n <KeycloakContext.Provider\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n value={{\n isLoggedIn: currentToken === undefined ? undefined : !!currentToken,\n login: handleLogin,\n logout: handleLogout,\n ready:\n discovery !== null && request !== null && currentToken !== undefined,\n token: currentToken,\n }}\n >\n {children}\n </KeycloakContext.Provider>\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,IAAeC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAChE,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAO,KAAKC,WAAW,MAAM,mBAAmB;AAChD,SACEC,cAAc,EACdC,gBAAgB,QAEX,mBAAmB;AAC1B,SAASC,eAAe;AACxB,SAASC,eAAe;AACxB,SA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,KAAKoB,SAAS;MACtEb,KAAK,EAAEP;IACT;EAAE,GAEDb,QAAQ,CACgB;AAE/B,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/expo/KeycloakContext.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:25:18
|
|
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 KeycloakContext: 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
|
-
}>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require("core-js/modules/esnext.global-this.js");
|
|
2
|
-
require("core-js/modules/es.object.define-property.js");
|
|
3
|
-
(function (global, factory) {
|
|
4
|
-
if (typeof define === "function" && define.amd) {
|
|
5
|
-
define(["exports", "react", "./const"], factory);
|
|
6
|
-
} else if (typeof exports !== "undefined") {
|
|
7
|
-
factory(exports, require("react"), require("./const"));
|
|
8
|
-
} else {
|
|
9
|
-
var mod = {
|
|
10
|
-
exports: {}
|
|
11
|
-
};
|
|
12
|
-
factory(mod.exports, global.react, global._const);
|
|
13
|
-
global.KeycloakContext = mod.exports;
|
|
14
|
-
}
|
|
15
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _const) {
|
|
16
|
-
"use strict";
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(_exports, "__esModule", {
|
|
19
|
-
value: true
|
|
20
|
-
});
|
|
21
|
-
_exports.KeycloakContext = void 0;
|
|
22
|
-
/**
|
|
23
|
-
* File: /src/expo/KeycloakContext.ts
|
|
24
|
-
* Project: @multiplatform.one/keycloak
|
|
25
|
-
* File Created: 26-11-2022 06:58:16
|
|
26
|
-
* Author: Clay Risser
|
|
27
|
-
* -----
|
|
28
|
-
* Last Modified: 26-11-2022 08:25:18
|
|
29
|
-
* Modified By: Clay Risser
|
|
30
|
-
* -----
|
|
31
|
-
* Risser Labs LLC (c) Copyright 2022
|
|
32
|
-
*
|
|
33
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
34
|
-
* you may not use this file except in compliance with the License.
|
|
35
|
-
* You may obtain a copy of the License at
|
|
36
|
-
*
|
|
37
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
38
|
-
*
|
|
39
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
-
* See the License for the specific language governing permissions and
|
|
43
|
-
* limitations under the License.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
var KeycloakContext = /*#__PURE__*/(0, _react.createContext)(_const.KC_INITIAL_VALUE);
|
|
47
|
-
_exports.KeycloakContext = KeycloakContext;
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=KeycloakContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeycloakContext.js","names":["KeycloakContext","createContext","KC_INITIAL_VALUE"],"sources":["../../src/expo/KeycloakContext.ts"],"sourcesContent":["/**\n * File: /src/expo/KeycloakContext.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:25:18\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 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 {\n AuthRequestPromptOptions,\n AuthSessionResult,\n TokenResponse,\n} from \"expo-auth-session\";\nimport { createContext } from \"react\";\nimport { KC_INITIAL_VALUE } from \"./const\";\n\nexport const KeycloakContext = createContext<{\n ready: boolean;\n isLoggedIn?: boolean;\n login: (\n options?: AuthRequestPromptOptions\n ) => Promise<AuthSessionResult | undefined>;\n logout: () => undefined;\n token: TokenResponse | null;\n}>(KC_INITIAL_VALUE);\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;;EAUO,IAAMA,eAAe,gBAAG,IAAAC,oBAAa,EAQzCC,uBAAgB,CAAC;EAAC;AAAA"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/expo/KeycloakProvider.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:06:40
|
|
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
|
-
import { ReactNode } from "react";
|
|
25
|
-
import { AuthRequestConfig } from "expo-auth-session";
|
|
26
|
-
export interface IKeycloakConfiguration extends Partial<AuthRequestConfig> {
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
clientId: string;
|
|
29
|
-
disableAutoRefresh?: boolean;
|
|
30
|
-
nativeRedirectPath?: string;
|
|
31
|
-
realm: string;
|
|
32
|
-
refreshTimeBuffer?: number;
|
|
33
|
-
scheme?: string;
|
|
34
|
-
tokenStorageKey?: string;
|
|
35
|
-
url: string;
|
|
36
|
-
}
|
|
37
|
-
export declare const KeycloakProvider: ({ realm, clientId, url, extraParams, children, ...options }: IKeycloakConfiguration) => JSX.Element;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
2
|
-
require("core-js/modules/esnext.global-this.js");
|
|
3
|
-
require("core-js/modules/es.object.define-property.js");
|
|
4
|
-
require("core-js/modules/es.array.iterator.js");
|
|
5
|
-
require("core-js/modules/es.string.iterator.js");
|
|
6
|
-
require("core-js/modules/es.weak-map.js");
|
|
7
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
-
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
9
|
-
require("core-js/modules/es.object.keys.js");
|
|
10
|
-
require("core-js/modules/es.symbol.js");
|
|
11
|
-
require("core-js/modules/es.array.filter.js");
|
|
12
|
-
require("core-js/modules/es.array.for-each.js");
|
|
13
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
14
|
-
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
15
|
-
require("core-js/modules/es.object.define-properties.js");
|
|
16
|
-
(function (global, factory) {
|
|
17
|
-
if (typeof define === "function" && define.amd) {
|
|
18
|
-
define(["exports", "@babel/runtime/helpers/defineProperty", "@babel/runtime/helpers/slicedToArray", "@babel/runtime/helpers/objectWithoutProperties", "core-js/modules/es.function.bind.js", "core-js/modules/es.array.concat.js", "core-js/modules/es.object.to-string.js", "core-js/modules/es.promise.js", "@babel/runtime/helpers/newArrowCheck", "react", "react-native", "expo-auth-session", "./KeycloakContext", "./useTokenStorage", "./helpers", "./const"], factory);
|
|
19
|
-
} else if (typeof exports !== "undefined") {
|
|
20
|
-
factory(exports, require("@babel/runtime/helpers/defineProperty"), require("@babel/runtime/helpers/slicedToArray"), require("@babel/runtime/helpers/objectWithoutProperties"), require("core-js/modules/es.function.bind.js"), require("core-js/modules/es.array.concat.js"), require("core-js/modules/es.object.to-string.js"), require("core-js/modules/es.promise.js"), require("@babel/runtime/helpers/newArrowCheck"), require("react"), require("react-native"), require("expo-auth-session"), require("./KeycloakContext"), require("./useTokenStorage"), require("./helpers"), require("./const"));
|
|
21
|
-
} else {
|
|
22
|
-
var mod = {
|
|
23
|
-
exports: {}
|
|
24
|
-
};
|
|
25
|
-
factory(mod.exports, global.defineProperty, global.slicedToArray, global.objectWithoutProperties, global.esFunctionBind, global.esArrayConcat, global.esObjectToString, global.esPromise, global.newArrowCheck, global.react, global.reactNative, global.expoAuthSession, global.KeycloakContext, global.useTokenStorage, global.helpers, global._const);
|
|
26
|
-
global.KeycloakProvider = mod.exports;
|
|
27
|
-
}
|
|
28
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _defineProperty2, _slicedToArray2, _objectWithoutProperties2, _esFunctionBind, _esArrayConcat, _esObjectToString, _esPromise, _newArrowCheck2, _react, _reactNative, AuthSession, _KeycloakContext, _useTokenStorage3, _helpers, _const) {
|
|
29
|
-
"use strict";
|
|
30
|
-
|
|
31
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
32
|
-
Object.defineProperty(_exports, "__esModule", {
|
|
33
|
-
value: true
|
|
34
|
-
});
|
|
35
|
-
_exports.KeycloakProvider = void 0;
|
|
36
|
-
_defineProperty2 = _interopRequireDefault(_defineProperty2);
|
|
37
|
-
_slicedToArray2 = _interopRequireDefault(_slicedToArray2);
|
|
38
|
-
_objectWithoutProperties2 = _interopRequireDefault(_objectWithoutProperties2);
|
|
39
|
-
_newArrowCheck2 = _interopRequireDefault(_newArrowCheck2);
|
|
40
|
-
_react = _interopRequireWildcard(_react);
|
|
41
|
-
AuthSession = _interopRequireWildcard(AuthSession);
|
|
42
|
-
var _excluded = ["realm", "clientId", "url", "extraParams", "children"];
|
|
43
|
-
var _this = void 0;
|
|
44
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
45
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
|
-
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; }
|
|
47
|
-
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) { (0, _defineProperty2["default"])(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; }
|
|
48
|
-
var KeycloakProvider = function KeycloakProvider(_ref) {
|
|
49
|
-
var _options$scheme,
|
|
50
|
-
_options$nativeRedire,
|
|
51
|
-
_this2 = this;
|
|
52
|
-
(0, _newArrowCheck2["default"])(this, _this);
|
|
53
|
-
var realm = _ref.realm,
|
|
54
|
-
clientId = _ref.clientId,
|
|
55
|
-
url = _ref.url,
|
|
56
|
-
extraParams = _ref.extraParams,
|
|
57
|
-
children = _ref.children,
|
|
58
|
-
options = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
59
|
-
var discovery = (0, AuthSession.useAutoDiscovery)((0, _helpers.getRealmURL)({
|
|
60
|
-
realm: realm,
|
|
61
|
-
url: url
|
|
62
|
-
}));
|
|
63
|
-
var redirectUri = AuthSession.makeRedirectUri({
|
|
64
|
-
"native": "".concat((_options$scheme = options.scheme) !== null && _options$scheme !== void 0 ? _options$scheme : "exp", "://").concat((_options$nativeRedire = options.nativeRedirectPath) !== null && _options$nativeRedire !== void 0 ? _options$nativeRedire : _const.NATIVE_REDIRECT_PATH),
|
|
65
|
-
useProxy: !options.scheme
|
|
66
|
-
});
|
|
67
|
-
var config = {
|
|
68
|
-
clientId: clientId,
|
|
69
|
-
extraParams: extraParams,
|
|
70
|
-
realm: realm,
|
|
71
|
-
redirectUri: redirectUri,
|
|
72
|
-
url: url
|
|
73
|
-
};
|
|
74
|
-
var _useAuthRequest = (0, AuthSession.useAuthRequest)(_objectSpread({
|
|
75
|
-
usePKCE: false
|
|
76
|
-
}, config), discovery),
|
|
77
|
-
_useAuthRequest2 = (0, _slicedToArray2["default"])(_useAuthRequest, 3),
|
|
78
|
-
request = _useAuthRequest2[0],
|
|
79
|
-
response = _useAuthRequest2[1],
|
|
80
|
-
promptAsync = _useAuthRequest2[2];
|
|
81
|
-
var _useTokenStorage = (0, _useTokenStorage3.useTokenStorage)(options, config, discovery),
|
|
82
|
-
_useTokenStorage2 = (0, _slicedToArray2["default"])(_useTokenStorage, 2),
|
|
83
|
-
currentToken = _useTokenStorage2[0],
|
|
84
|
-
updateToken = _useTokenStorage2[1];
|
|
85
|
-
var handleLogin = (0, _react.useCallback)(function () {
|
|
86
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
87
|
-
return promptAsync(options);
|
|
88
|
-
}, [request]);
|
|
89
|
-
function handleLogout() {
|
|
90
|
-
if (!currentToken) throw new Error("Not logged in.");
|
|
91
|
-
try {
|
|
92
|
-
if (discovery !== null && discovery !== void 0 && discovery.revocationEndpoint) {
|
|
93
|
-
AuthSession.revokeAsync(_objectSpread({
|
|
94
|
-
token: currentToken === null || currentToken === void 0 ? void 0 : currentToken.accessToken
|
|
95
|
-
}, config), discovery);
|
|
96
|
-
}
|
|
97
|
-
if (discovery !== null && discovery !== void 0 && discovery.endSessionEndpoint) {
|
|
98
|
-
fetch("".concat(discovery.endSessionEndpoint), {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
102
|
-
},
|
|
103
|
-
body: "client_id=".concat(clientId, "&refresh_token=").concat(currentToken.refreshToken)
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
if (_reactNative.Platform.OS === "ios") {
|
|
107
|
-
AuthSession.dismiss();
|
|
108
|
-
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.log(error);
|
|
111
|
-
}
|
|
112
|
-
updateToken(null);
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
(0, _react.useEffect)(function () {
|
|
116
|
-
(0, _newArrowCheck2["default"])(this, _this2);
|
|
117
|
-
if (response) {
|
|
118
|
-
(0, _helpers.handleTokenExchange)({
|
|
119
|
-
response: response,
|
|
120
|
-
discovery: discovery,
|
|
121
|
-
config: config
|
|
122
|
-
}).then(updateToken);
|
|
123
|
-
}
|
|
124
|
-
}.bind(this), [response]);
|
|
125
|
-
return /*#__PURE__*/_react["default"].createElement(_KeycloakContext.KeycloakContext.Provider, {
|
|
126
|
-
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
127
|
-
value: {
|
|
128
|
-
isLoggedIn: currentToken === undefined ? undefined : !!currentToken,
|
|
129
|
-
login: handleLogin,
|
|
130
|
-
logout: handleLogout,
|
|
131
|
-
ready: discovery !== null && request !== null && currentToken !== undefined,
|
|
132
|
-
token: currentToken
|
|
133
|
-
}
|
|
134
|
-
}, children);
|
|
135
|
-
}.bind(void 0);
|
|
136
|
-
_exports.KeycloakProvider = KeycloakProvider;
|
|
137
|
-
});
|
|
138
|
-
//# sourceMappingURL=KeycloakProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeycloakProvider.js","names":["KeycloakProvider","realm","clientId","url","extraParams","children","options","discovery","useAutoDiscovery","getRealmURL","redirectUri","AuthSession","makeRedirectUri","scheme","nativeRedirectPath","NATIVE_REDIRECT_PATH","useProxy","config","useAuthRequest","usePKCE","request","response","promptAsync","useTokenStorage","currentToken","updateToken","handleLogin","useCallback","handleLogout","Error","revocationEndpoint","revokeAsync","token","accessToken","endSessionEndpoint","fetch","method","headers","body","refreshToken","Platform","OS","dismiss","error","console","log","undefined","useEffect","handleTokenExchange","then","isLoggedIn","login","logout","ready"],"sources":["../../src/expo/KeycloakProvider.tsx"],"sourcesContent":["/**\n * File: /src/expo/KeycloakProvider.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:06:40\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 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, { ReactNode, useCallback, useEffect } from \"react\";\nimport { Platform } from \"react-native\";\nimport * as AuthSession from \"expo-auth-session\";\nimport {\n useAuthRequest,\n useAutoDiscovery,\n AuthRequestConfig,\n} from \"expo-auth-session\";\nimport { KeycloakContext } from \"./KeycloakContext\";\nimport { useTokenStorage } from \"./useTokenStorage\";\nimport { handleTokenExchange, getRealmURL } from \"./helpers\";\nimport { NATIVE_REDIRECT_PATH } from \"./const\";\n\nexport interface IKeycloakConfiguration extends Partial<AuthRequestConfig> {\n children: ReactNode;\n clientId: string;\n disableAutoRefresh?: boolean;\n nativeRedirectPath?: string;\n realm: string;\n refreshTimeBuffer?: number;\n scheme?: string;\n tokenStorageKey?: string;\n url: string;\n}\n\nexport const KeycloakProvider = ({\n realm,\n clientId,\n url,\n extraParams,\n children,\n ...options\n}: IKeycloakConfiguration) => {\n const discovery = useAutoDiscovery(getRealmURL({ realm, url }));\n const redirectUri = AuthSession.makeRedirectUri({\n native: `${options.scheme ?? \"exp\"}://${\n options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH\n }`,\n useProxy: !options.scheme,\n });\n const config = {\n clientId,\n extraParams,\n realm,\n redirectUri,\n url,\n };\n const [request, response, promptAsync] = useAuthRequest(\n { usePKCE: false, ...config },\n discovery\n );\n const [currentToken, updateToken] = useTokenStorage(\n options,\n config,\n discovery!\n );\n\n const handleLogin = useCallback(\n (options: AuthSession.AuthRequestPromptOptions = {}) =>\n promptAsync(options),\n [request]\n );\n\n function handleLogout() {\n if (!currentToken) throw new Error(\"Not logged in.\");\n try {\n if (discovery?.revocationEndpoint) {\n AuthSession.revokeAsync(\n { token: currentToken?.accessToken, ...config },\n discovery\n );\n }\n if (discovery?.endSessionEndpoint) {\n fetch(`${discovery.endSessionEndpoint}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`,\n });\n }\n if (Platform.OS === \"ios\") {\n AuthSession.dismiss();\n }\n } catch (error) {\n console.log(error);\n }\n updateToken(null);\n return undefined;\n }\n\n useEffect(() => {\n if (response) {\n handleTokenExchange({ response, discovery: discovery!, config }).then(\n updateToken\n );\n }\n }, [response]);\n\n return (\n <KeycloakContext.Provider\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n value={{\n isLoggedIn: currentToken === undefined ? undefined : !!currentToken,\n login: handleLogin,\n logout: handleLogout,\n ready:\n discovery !== null && request !== null && currentToken !== undefined,\n token: currentToken,\n }}\n >\n {children}\n </KeycloakContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDO,IAAMA,gBAAgB,GAAG,gC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