@multiplatform.one/keycloak 0.0.2 → 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 +39 -24
- 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 +6 -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 +12 -4
- package/lib/hooks/useKeycloak/useKeycloak.native.js +40 -28
- 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 +3 -2
- 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 +10 -4
- package/src/hooks/useKeycloak/useKeycloak.native.ts +48 -11
- package/src/provider/keycloakProvider.native.tsx +8 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/expo/helpers.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:11:15
|
|
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 { AccessTokenRequestConfig, DiscoveryDocument, AuthSessionResult } from "expo-auth-session";
|
|
25
|
+
export declare function getRealmURL(config: RealmURLConfig): string;
|
|
26
|
+
export declare function getCurrentTimeInSeconds(): number;
|
|
27
|
+
export declare function handleTokenExchange({ response, discovery, config, }: TokenExchange): Promise<import("expo-auth-session").TokenResponse | null>;
|
|
28
|
+
export interface TokenExchange {
|
|
29
|
+
response: AuthSessionResult;
|
|
30
|
+
discovery: Pick<DiscoveryDocument, "tokenEndpoint">;
|
|
31
|
+
config: Omit<AccessTokenRequestConfig, "code"> & {
|
|
32
|
+
code?: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface TokenExchangeDiscovery {
|
|
36
|
+
tokenEndpoint?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface RealmURLConfig {
|
|
39
|
+
realm: string;
|
|
40
|
+
url: string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "expo-auth-session"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("expo-auth-session"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.expoAuthSession);
|
|
11
|
+
global.helpers = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expoAuthSession) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.getCurrentTimeInSeconds = getCurrentTimeInSeconds;
|
|
20
|
+
_exports.getRealmURL = getRealmURL;
|
|
21
|
+
_exports.handleTokenExchange = handleTokenExchange;
|
|
22
|
+
/**
|
|
23
|
+
* File: /src/expo/helpers.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:11:15
|
|
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
|
+
function getRealmURL(config) {
|
|
47
|
+
const {
|
|
48
|
+
url,
|
|
49
|
+
realm
|
|
50
|
+
} = config;
|
|
51
|
+
const slash = url.endsWith("/") ? "" : "/";
|
|
52
|
+
return `${url + slash}realms/${encodeURIComponent(realm)}`;
|
|
53
|
+
}
|
|
54
|
+
function getCurrentTimeInSeconds() {
|
|
55
|
+
return Math.floor(Date.now() / 1000);
|
|
56
|
+
}
|
|
57
|
+
async function handleTokenExchange(_ref) {
|
|
58
|
+
let {
|
|
59
|
+
response,
|
|
60
|
+
discovery,
|
|
61
|
+
config
|
|
62
|
+
} = _ref;
|
|
63
|
+
try {
|
|
64
|
+
if ((response === null || response === void 0 ? void 0 : response.type) === "success" && !!(discovery !== null && discovery !== void 0 && discovery.tokenEndpoint)) {
|
|
65
|
+
return (0, _expoAuthSession.exchangeCodeAsync)({
|
|
66
|
+
code: response.params.code,
|
|
67
|
+
...config
|
|
68
|
+
}, discovery);
|
|
69
|
+
}
|
|
70
|
+
if ((response === null || response === void 0 ? void 0 : response.type) === "error") return null;
|
|
71
|
+
return null;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["getRealmURL","config","url","realm","slash","endsWith","encodeURIComponent","getCurrentTimeInSeconds","Math","floor","Date","now","handleTokenExchange","response","discovery","type","tokenEndpoint","exchangeCodeAsync","code","params","error"],"sources":["../../src/expo/helpers.ts"],"sourcesContent":["/**\n * File: /src/expo/helpers.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:11:15\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 AccessTokenRequestConfig,\n exchangeCodeAsync,\n DiscoveryDocument,\n AuthSessionResult,\n} from \"expo-auth-session\";\n\nexport function getRealmURL(config: RealmURLConfig) {\n const { url, realm } = config;\n const slash = url.endsWith(\"/\") ? \"\" : \"/\";\n return `${url + slash}realms/${encodeURIComponent(realm)}`;\n}\n\nexport function getCurrentTimeInSeconds() {\n return Math.floor(Date.now() / 1000);\n}\n\nexport async function handleTokenExchange({\n response,\n discovery,\n config,\n}: TokenExchange) {\n try {\n if (response?.type === \"success\" && !!discovery?.tokenEndpoint) {\n return exchangeCodeAsync(\n { code: response.params.code, ...config },\n discovery\n );\n }\n if (response?.type === \"error\") return null;\n return null;\n } catch (error) {\n return null;\n }\n}\n\nexport interface TokenExchange {\n response: AuthSessionResult;\n discovery: Pick<DiscoveryDocument, \"tokenEndpoint\">;\n config: Omit<AccessTokenRequestConfig, \"code\"> & { code?: string };\n}\n\nexport interface TokenExchangeDiscovery {\n tokenEndpoint?: string;\n}\n\nexport interface RealmURLConfig {\n realm: string;\n url: string;\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;;EASO,SAASA,WAAW,CAACC,MAAsB,EAAE;IAClD,MAAM;MAAEC,GAAG;MAAEC;IAAM,CAAC,GAAGF,MAAM;IAC7B,MAAMG,KAAK,GAAGF,GAAG,CAACG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG;IAC1C,OAAQ,GAAEH,GAAG,GAAGE,KAAM,UAASE,kBAAkB,CAACH,KAAK,CAAE,EAAC;EAC5D;EAEO,SAASI,uBAAuB,GAAG;IACxC,OAAOC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,GAAG,EAAE,GAAG,IAAI,CAAC;EACtC;EAEO,eAAeC,mBAAmB,OAIvB;IAAA,IAJwB;MACxCC,QAAQ;MACRC,SAAS;MACTb;IACa,CAAC;IACd,IAAI;MACF,IAAI,CAAAY,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,SAAS,IAAI,CAAC,EAACD,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEE,aAAa,GAAE;QAC9D,OAAO,IAAAC,kCAAiB,EACtB;UAAEC,IAAI,EAAEL,QAAQ,CAACM,MAAM,CAACD,IAAI;UAAE,GAAGjB;QAAO,CAAC,EACzCa,SAAS,CACV;MACH;MACA,IAAI,CAAAD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,OAAO,EAAE,OAAO,IAAI;MAC3C,OAAO,IAAI;IACb,CAAC,CAAC,OAAOK,KAAK,EAAE;MACd,OAAO,IAAI;IACb;EACF;AAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/expo/index.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:41
|
|
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
|
+
export * from "./ExpoKeycloakProvider";
|
|
25
|
+
export * from "./useExpoKeycloak";
|
|
26
|
+
export * from "./const";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./ExpoKeycloakProvider", "./useExpoKeycloak", "./const"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./ExpoKeycloakProvider"), require("./useExpoKeycloak"), require("./const"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.ExpoKeycloakProvider, global.useExpoKeycloak, global._const);
|
|
11
|
+
global.index = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _ExpoKeycloakProvider, _useExpoKeycloak, _const) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
Object.keys(_ExpoKeycloakProvider).forEach(function (key) {
|
|
20
|
+
if (key === "default" || key === "__esModule") return;
|
|
21
|
+
if (key in _exports && _exports[key] === _ExpoKeycloakProvider[key]) return;
|
|
22
|
+
Object.defineProperty(_exports, key, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _ExpoKeycloakProvider[key];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(_useExpoKeycloak).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in _exports && _exports[key] === _useExpoKeycloak[key]) return;
|
|
32
|
+
Object.defineProperty(_exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _useExpoKeycloak[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
Object.keys(_const).forEach(function (key) {
|
|
40
|
+
if (key === "default" || key === "__esModule") return;
|
|
41
|
+
if (key in _exports && _exports[key] === _const[key]) return;
|
|
42
|
+
Object.defineProperty(_exports, key, {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _const[key];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/expo/index.ts"],"sourcesContent":["/**\n * File: /src/expo/index.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:38:41\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\nexport * from \"./ExpoKeycloakProvider\";\nexport * from \"./useExpoKeycloak\";\nexport * from \"./const\";\n"],"mappings":";;;;;;;;;;;;;;;;;;EAwBA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;EACA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;EACA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;AAAwB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/expo/useExpoKeycloak.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:57
|
|
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
|
+
export declare function useExpoKeycloak(): {
|
|
25
|
+
isLoggedIn: boolean | undefined;
|
|
26
|
+
login: (options?: import("expo-auth-session").AuthRequestPromptOptions | undefined) => Promise<import("expo-auth-session").AuthSessionResult | undefined>;
|
|
27
|
+
logout: () => undefined;
|
|
28
|
+
ready: boolean;
|
|
29
|
+
token: string | null;
|
|
30
|
+
refreshToken: string | null;
|
|
31
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "react", "./ExpoKeycloakContext"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("react"), require("./ExpoKeycloakContext"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.react, global.ExpoKeycloakContext);
|
|
11
|
+
global.useExpoKeycloak = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _ExpoKeycloakContext) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.useExpoKeycloak = useExpoKeycloak;
|
|
20
|
+
/**
|
|
21
|
+
* File: /src/expo/useExpoKeycloak.ts
|
|
22
|
+
* Project: @multiplatform.one/keycloak
|
|
23
|
+
* File Created: 26-11-2022 06:58:16
|
|
24
|
+
* Author: Clay Risser
|
|
25
|
+
* -----
|
|
26
|
+
* Last Modified: 26-11-2022 08:38:57
|
|
27
|
+
* Modified By: Clay Risser
|
|
28
|
+
* -----
|
|
29
|
+
* Risser Labs LLC (c) Copyright 2022
|
|
30
|
+
*
|
|
31
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
+
* you may not use this file except in compliance with the License.
|
|
33
|
+
* You may obtain a copy of the License at
|
|
34
|
+
*
|
|
35
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
+
*
|
|
37
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
38
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
+
* See the License for the specific language governing permissions and
|
|
41
|
+
* limitations under the License.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
function useExpoKeycloak() {
|
|
45
|
+
const {
|
|
46
|
+
isLoggedIn,
|
|
47
|
+
login,
|
|
48
|
+
logout,
|
|
49
|
+
ready = false,
|
|
50
|
+
token = null
|
|
51
|
+
} = (0, _react.useContext)(_ExpoKeycloakContext.ExpoKeycloakContext);
|
|
52
|
+
return {
|
|
53
|
+
isLoggedIn,
|
|
54
|
+
login,
|
|
55
|
+
logout,
|
|
56
|
+
ready,
|
|
57
|
+
token: (token === null || token === void 0 ? void 0 : token.accessToken) ?? null,
|
|
58
|
+
refreshToken: (token === null || token === void 0 ? void 0 : token.refreshToken) ?? null
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=useExpoKeycloak.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExpoKeycloak.js","names":["useExpoKeycloak","isLoggedIn","login","logout","ready","token","useContext","ExpoKeycloakContext","accessToken","refreshToken"],"sources":["../../src/expo/useExpoKeycloak.ts"],"sourcesContent":["/**\n * File: /src/expo/useExpoKeycloak.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:38:57\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 { useContext } from \"react\";\nimport { ExpoKeycloakContext } from \"./ExpoKeycloakContext\";\n\nexport function useExpoKeycloak() {\n const {\n isLoggedIn,\n login,\n logout,\n ready = false,\n token = null,\n } = useContext(ExpoKeycloakContext);\n return {\n isLoggedIn,\n login,\n logout,\n ready,\n token: token?.accessToken ?? null,\n refreshToken: token?.refreshToken ?? null,\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;;EAKO,SAASA,eAAe,GAAG;IAChC,MAAM;MACJC,UAAU;MACVC,KAAK;MACLC,MAAM;MACNC,KAAK,GAAG,KAAK;MACbC,KAAK,GAAG;IACV,CAAC,GAAG,IAAAC,iBAAU,EAACC,wCAAmB,CAAC;IACnC,OAAO;MACLN,UAAU;MACVC,KAAK;MACLC,MAAM;MACNC,KAAK;MACLC,KAAK,EAAE,CAAAA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEG,WAAW,KAAI,IAAI;MACjCC,YAAY,EAAE,CAAAJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEI,YAAY,KAAI;IACvC,CAAC;EACH;AAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/expo/useTokenStorage.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:08:00
|
|
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 { DiscoveryDocument } from "expo-auth-session";
|
|
25
|
+
import { TokenResponse } from "expo-auth-session";
|
|
26
|
+
export declare function useTokenStorage({ disableAutoRefresh, refreshTimeBuffer, tokenStorageKey, }: {
|
|
27
|
+
disableAutoRefresh?: boolean | undefined;
|
|
28
|
+
refreshTimeBuffer?: number | undefined;
|
|
29
|
+
tokenStorageKey?: string | undefined;
|
|
30
|
+
}, config: {
|
|
31
|
+
clientId: string;
|
|
32
|
+
extraParams?: Record<string, string>;
|
|
33
|
+
realm: string;
|
|
34
|
+
redirectUri: string;
|
|
35
|
+
url: string;
|
|
36
|
+
}, discovery: DiscoveryDocument): [TokenResponse | null, (token: TokenResponse | null) => Promise<void>];
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "react-native", "expo-auth-session", "./const", "./helpers", "@react-native-async-storage/async-storage", "react"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("react-native"), require("expo-auth-session"), require("./const"), require("./helpers"), require("@react-native-async-storage/async-storage"), require("react"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.reactNative, global.expoAuthSession, global._const, global.helpers, global.asyncStorage, global.react);
|
|
11
|
+
global.useTokenStorage = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _reactNative, _expoAuthSession, _const, _helpers, _asyncStorage, _react) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.useTokenStorage = useTokenStorage;
|
|
20
|
+
/**
|
|
21
|
+
* File: /src/expo/useTokenStorage.ts
|
|
22
|
+
* Project: @multiplatform.one/keycloak
|
|
23
|
+
* File Created: 26-11-2022 06:58:16
|
|
24
|
+
* Author: Clay Risser
|
|
25
|
+
* -----
|
|
26
|
+
* Last Modified: 26-11-2022 08:08:00
|
|
27
|
+
* Modified By: Clay Risser
|
|
28
|
+
* -----
|
|
29
|
+
* Risser Labs LLC (c) Copyright 2022
|
|
30
|
+
*
|
|
31
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
+
* you may not use this file except in compliance with the License.
|
|
33
|
+
* You may obtain a copy of the License at
|
|
34
|
+
*
|
|
35
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
+
*
|
|
37
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
38
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
+
* See the License for the specific language governing permissions and
|
|
41
|
+
* limitations under the License.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const logger = console;
|
|
45
|
+
function useTokenStorage(_ref, config, discovery) {
|
|
46
|
+
let {
|
|
47
|
+
disableAutoRefresh = false,
|
|
48
|
+
refreshTimeBuffer = _const.REFRESH_TIME_BUFFER,
|
|
49
|
+
tokenStorageKey = _const.TOKEN_STORAGE_KEY
|
|
50
|
+
} = _ref;
|
|
51
|
+
const [token, setToken] = (0, _react.useState)();
|
|
52
|
+
const {
|
|
53
|
+
getItem,
|
|
54
|
+
setItem,
|
|
55
|
+
removeItem
|
|
56
|
+
} = (0, _asyncStorage.useAsyncStorage)(tokenStorageKey);
|
|
57
|
+
const refreshHandler = (0, _react.useRef)(null);
|
|
58
|
+
const appState = (0, _react.useRef)(_reactNative.AppState.currentState);
|
|
59
|
+
const refreshTime = (0, _react.useRef)(null);
|
|
60
|
+
const tokenData = (0, _react.useRef)(null);
|
|
61
|
+
async function updateAndSaveToken(newToken) {
|
|
62
|
+
try {
|
|
63
|
+
setToken(newToken);
|
|
64
|
+
if (newToken !== null) {
|
|
65
|
+
const stringifiedValue = JSON.stringify(newToken);
|
|
66
|
+
await setItem(stringifiedValue);
|
|
67
|
+
} else {
|
|
68
|
+
await removeItem();
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
logger.error(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function handleTokenRefresh(token) {
|
|
75
|
+
try {
|
|
76
|
+
const tokenResponse = await (0, _expoAuthSession.refreshAsync)({
|
|
77
|
+
refreshToken: token === null || token === void 0 ? void 0 : token.refreshToken,
|
|
78
|
+
...config
|
|
79
|
+
}, discovery);
|
|
80
|
+
updateAndSaveToken(tokenResponse);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
updateAndSaveToken(null);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
(0, _react.useEffect)(() => {
|
|
86
|
+
function handleAppState(nextAppState) {
|
|
87
|
+
if (appState.current.match(/inactive|background/) && nextAppState === "active") {
|
|
88
|
+
if (refreshHandler.current !== null) {
|
|
89
|
+
clearTimeout(refreshHandler.current);
|
|
90
|
+
const now = (0, _helpers.getCurrentTimeInSeconds)();
|
|
91
|
+
if (Number(refreshTime.current) <= now) {
|
|
92
|
+
setToken(null);
|
|
93
|
+
} else {
|
|
94
|
+
const timeout = 1000 * (Number(refreshTime.current) - now);
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
refreshHandler.current = setTimeout(() => {
|
|
97
|
+
handleTokenRefresh(tokenData.current);
|
|
98
|
+
}, timeout);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
appState.current = nextAppState;
|
|
103
|
+
}
|
|
104
|
+
const subscription = _reactNative.AppState.addEventListener("change", handleAppState);
|
|
105
|
+
return () => {
|
|
106
|
+
if (subscription) {
|
|
107
|
+
subscription.remove();
|
|
108
|
+
} else {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
_reactNative.AppState.removeEventListener("change", handleAppState);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
(0, _react.useEffect)(() => {
|
|
115
|
+
async function getTokenFromStorage() {
|
|
116
|
+
try {
|
|
117
|
+
const tokenFromStorage = await getItem();
|
|
118
|
+
if (!tokenFromStorage) throw new Error("No token in storage");
|
|
119
|
+
const token = JSON.parse(tokenFromStorage);
|
|
120
|
+
if (!_expoAuthSession.TokenResponse.isTokenFresh(token, -refreshTimeBuffer)) {
|
|
121
|
+
handleTokenRefresh(token);
|
|
122
|
+
} else {
|
|
123
|
+
setToken(token);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
setToken(null);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (discovery) getTokenFromStorage();
|
|
130
|
+
}, [discovery]);
|
|
131
|
+
(0, _react.useEffect)(() => {
|
|
132
|
+
// trigger every token update
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
tokenData.current = token || null;
|
|
135
|
+
if (token !== undefined && !disableAutoRefresh) {
|
|
136
|
+
if (refreshHandler.current !== null) {
|
|
137
|
+
clearTimeout(refreshHandler.current);
|
|
138
|
+
}
|
|
139
|
+
if (token !== null && token !== void 0 && token.expiresIn) {
|
|
140
|
+
const now = (0, _helpers.getCurrentTimeInSeconds)();
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
refreshTime.current = token.issuedAt + token.expiresIn - refreshTimeBuffer;
|
|
143
|
+
const timeout = 1000 * (refreshTime.current - now);
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
refreshHandler.current = setTimeout(() => {
|
|
146
|
+
handleTokenRefresh(token);
|
|
147
|
+
}, timeout);
|
|
148
|
+
}
|
|
149
|
+
if (token === null && tokenData.current !== null) {
|
|
150
|
+
var _tokenData$current;
|
|
151
|
+
(0, _expoAuthSession.revokeAsync)({
|
|
152
|
+
token: (_tokenData$current = tokenData.current) === null || _tokenData$current === void 0 ? void 0 : _tokenData$current.accessToken,
|
|
153
|
+
...config
|
|
154
|
+
}, discovery);
|
|
155
|
+
_reactNative.Platform.OS === "ios" && (0, _expoAuthSession.dismiss)();
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
refreshTime.current = null;
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
tokenData.current = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}, [token]);
|
|
163
|
+
return [token || null, updateAndSaveToken];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=useTokenStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTokenStorage.js","names":["logger","console","useTokenStorage","config","discovery","disableAutoRefresh","refreshTimeBuffer","REFRESH_TIME_BUFFER","tokenStorageKey","TOKEN_STORAGE_KEY","token","setToken","useState","getItem","setItem","removeItem","useAsyncStorage","refreshHandler","useRef","appState","AppState","currentState","refreshTime","tokenData","updateAndSaveToken","newToken","stringifiedValue","JSON","stringify","error","handleTokenRefresh","tokenResponse","refreshAsync","refreshToken","err","useEffect","handleAppState","nextAppState","current","match","clearTimeout","now","getCurrentTimeInSeconds","Number","timeout","setTimeout","subscription","addEventListener","remove","removeEventListener","getTokenFromStorage","tokenFromStorage","Error","parse","TokenResponse","isTokenFresh","undefined","expiresIn","issuedAt","revokeAsync","accessToken","Platform","OS","dismiss"],"sources":["../../src/expo/useTokenStorage.ts"],"sourcesContent":["/**\n * File: /src/expo/useTokenStorage.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:08:00\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 { AppState, AppStateStatus, Platform } from \"react-native\";\nimport { DiscoveryDocument, refreshAsync } from \"expo-auth-session\";\nimport { REFRESH_TIME_BUFFER, TOKEN_STORAGE_KEY } from \"./const\";\nimport { dismiss, revokeAsync, TokenResponse } from \"expo-auth-session\";\nimport { getCurrentTimeInSeconds } from \"./helpers\";\nimport { useAsyncStorage } from \"@react-native-async-storage/async-storage\";\nimport { useEffect, useRef, useState } from \"react\";\n\nconst logger = console;\n\nexport function useTokenStorage(\n {\n disableAutoRefresh = false,\n refreshTimeBuffer = REFRESH_TIME_BUFFER,\n tokenStorageKey = TOKEN_STORAGE_KEY,\n },\n config: {\n clientId: string;\n extraParams?: Record<string, string>;\n realm: string;\n redirectUri: string;\n url: string;\n },\n discovery: DiscoveryDocument\n): [TokenResponse | null, (token: TokenResponse | null) => Promise<void>] {\n const [token, setToken] = useState<TokenResponse | null>();\n const { getItem, setItem, removeItem } = useAsyncStorage(tokenStorageKey);\n const refreshHandler = useRef<NodeJS.Timeout>(null);\n const appState = useRef(AppState.currentState);\n const refreshTime = useRef<number>(null);\n const tokenData = useRef<TokenResponse>(null);\n\n async function updateAndSaveToken(newToken: TokenResponse | null) {\n try {\n setToken(newToken);\n if (newToken !== null) {\n const stringifiedValue = JSON.stringify(newToken);\n await setItem(stringifiedValue);\n } else {\n await removeItem();\n }\n } catch (error) {\n logger.error(error);\n }\n }\n\n async function handleTokenRefresh(token: TokenResponse | null) {\n try {\n const tokenResponse = await refreshAsync(\n { refreshToken: token?.refreshToken, ...config },\n discovery\n );\n updateAndSaveToken(tokenResponse);\n } catch (err) {\n updateAndSaveToken(null);\n }\n }\n\n useEffect(() => {\n function handleAppState(nextAppState: AppStateStatus) {\n if (\n appState.current.match(/inactive|background/) &&\n nextAppState === \"active\"\n ) {\n if (refreshHandler.current !== null) {\n clearTimeout(refreshHandler.current);\n const now = getCurrentTimeInSeconds();\n if (Number(refreshTime.current) <= now) {\n setToken(null);\n } else {\n const timeout = 1000 * (Number(refreshTime.current) - now);\n // @ts-ignore\n refreshHandler.current = setTimeout(() => {\n handleTokenRefresh(tokenData.current);\n }, timeout);\n }\n }\n }\n appState.current = nextAppState;\n }\n const subscription = AppState.addEventListener(\"change\", handleAppState);\n return () => {\n if (subscription) {\n subscription.remove();\n } else {\n // @ts-ignore\n AppState.removeEventListener(\"change\", handleAppState);\n }\n };\n }, []);\n\n useEffect(() => {\n async function getTokenFromStorage() {\n try {\n const tokenFromStorage = await getItem();\n if (!tokenFromStorage) throw new Error(\"No token in storage\");\n const token = JSON.parse(tokenFromStorage);\n if (!TokenResponse.isTokenFresh(token, -refreshTimeBuffer)) {\n handleTokenRefresh(token);\n } else {\n setToken(token);\n }\n } catch (error) {\n setToken(null);\n }\n }\n if (discovery) getTokenFromStorage();\n }, [discovery]);\n\n useEffect(() => {\n // trigger every token update\n // @ts-ignore\n tokenData.current = token || null;\n if (token !== undefined && !disableAutoRefresh) {\n if (refreshHandler.current !== null) {\n clearTimeout(refreshHandler.current);\n }\n if (token?.expiresIn) {\n const now = getCurrentTimeInSeconds();\n // @ts-ignore\n refreshTime.current =\n token.issuedAt + token.expiresIn - refreshTimeBuffer;\n const timeout = 1000 * (refreshTime.current - now);\n // @ts-ignore\n refreshHandler.current = setTimeout(() => {\n handleTokenRefresh(token);\n }, timeout);\n }\n if (token === null && tokenData.current !== null) {\n revokeAsync(\n { token: tokenData.current?.accessToken, ...config },\n discovery\n );\n Platform.OS === \"ios\" && dismiss();\n // @ts-ignore\n refreshTime.current = null;\n // @ts-ignore\n tokenData.current = null;\n }\n }\n }, [token]);\n\n return [token || null, updateAndSaveToken];\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;;EAUA,MAAMA,MAAM,GAAGC,OAA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,EACT;YAAEjD,KAAK,wBAAEa,SAAS,CAACe,OAAO,uDAAjB,mBAAmBsB,WAAW;YAAE,GAAGzD;UAAO,CAAC,EACpDC,SAAS,CACV;UACDyD,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,IAAAC,wBAAO,GAAE;UAClC;UACAzC,WAAW,CAACgB,OAAO,GAAG,IAAI;UAC1B;UACAf,SAAS,CAACe,OAAO,GAAG,IAAI;QAC1B;MACF;IACF,CAAC,EAAE,CAAC5B,KAAK,CAAC,CAAC;IAEX,OAAO,CAACA,KAAK,IAAI,IAAI,EAAEc,kBAAkB,CAAC;EAC5C;AAAC"}
|
package/lib/hooks/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
require("core-js/modules/esnext.global-this.js");
|
|
2
|
-
require("core-js/modules/es.object.define-property.js");
|
|
3
|
-
require("core-js/modules/es.array.for-each.js");
|
|
4
|
-
require("core-js/modules/es.object.to-string.js");
|
|
5
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
-
require("core-js/modules/es.object.keys.js");
|
|
7
1
|
(function (global, factory) {
|
|
8
2
|
if (typeof define === "function" && define.amd) {
|
|
9
3
|
define(["exports", "./useCurrentRouteName", "./useKeycloak", "./useLogin"], factory);
|
|
@@ -27,7 +21,7 @@ require("core-js/modules/es.object.keys.js");
|
|
|
27
21
|
if (key in _exports && _exports[key] === _useCurrentRouteName[key]) return;
|
|
28
22
|
Object.defineProperty(_exports, key, {
|
|
29
23
|
enumerable: true,
|
|
30
|
-
get: function
|
|
24
|
+
get: function () {
|
|
31
25
|
return _useCurrentRouteName[key];
|
|
32
26
|
}
|
|
33
27
|
});
|
|
@@ -37,7 +31,7 @@ require("core-js/modules/es.object.keys.js");
|
|
|
37
31
|
if (key in _exports && _exports[key] === _useKeycloak[key]) return;
|
|
38
32
|
Object.defineProperty(_exports, key, {
|
|
39
33
|
enumerable: true,
|
|
40
|
-
get: function
|
|
34
|
+
get: function () {
|
|
41
35
|
return _useKeycloak[key];
|
|
42
36
|
}
|
|
43
37
|
});
|
|
@@ -47,7 +41,7 @@ require("core-js/modules/es.object.keys.js");
|
|
|
47
41
|
if (key in _exports && _exports[key] === _useLogin[key]) return;
|
|
48
42
|
Object.defineProperty(_exports, key, {
|
|
49
43
|
enumerable: true,
|
|
50
|
-
get: function
|
|
44
|
+
get: function () {
|
|
51
45
|
return _useLogin[key];
|
|
52
46
|
}
|
|
53
47
|
});
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/hooks/index.ts"],"sourcesContent":["/**\n * File: /src/hooks/index.ts\n * Project: app\n * File Created: 08-11-2022 06:34:56\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\nexport * from \"./useCurrentRouteName\";\nexport * from \"./useKeycloak\";\nexport * from \"./useLogin\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/hooks/index.ts"],"sourcesContent":["/**\n * File: /src/hooks/index.ts\n * Project: app\n * File Created: 08-11-2022 06:34:56\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\nexport * from \"./useCurrentRouteName\";\nexport * from \"./useKeycloak\";\nexport * from \"./useLogin\";\n"],"mappings":";;;;;;;;;;;;;;;;;;EAwBA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;EACA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;EACA;IAAA;IAAA;IAAA;MAAA;MAAA;QAAA;MAAA;IAAA;EAAA;AAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthConfig.js","names":["useAuthConfig","useContext","AuthConfigContext"],"sources":["../../src/hooks/useAuthConfig.ts"],"sourcesContent":["/**\n * File: /src/hooks/useAuthConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:20:41\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 { useContext } from \"react\";\nimport { AuthConfigContext } from \"../authConfig\";\n\nexport function useAuthConfig() {\n return useContext(AuthConfigContext);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAuthConfig.js","names":["useAuthConfig","useContext","AuthConfigContext"],"sources":["../../src/hooks/useAuthConfig.ts"],"sourcesContent":["/**\n * File: /src/hooks/useAuthConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:20:41\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 { useContext } from \"react\";\nimport { AuthConfigContext } from \"../authConfig\";\n\nexport function useAuthConfig() {\n return useContext(AuthConfigContext);\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;;EAKO,SAASA,aAAa,GAAG;IAC9B,OAAO,IAAAC,iBAAU,EAACC,6BAAiB,CAAC;EACtC;AAAC"}
|
|
@@ -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", "multiplatform.one", "@react-navigation/native", "next/router"], factory);
|
|
6
4
|
} else if (typeof exports !== "undefined") {
|
|
7
|
-
factory(exports, require("
|
|
5
|
+
factory(exports, require("multiplatform.one"), require("@react-navigation/native"), require("next/router"));
|
|
8
6
|
} else {
|
|
9
7
|
var mod = {
|
|
10
8
|
exports: {}
|
|
11
9
|
};
|
|
12
|
-
factory(mod.exports, global.
|
|
10
|
+
factory(mod.exports, global.multiplatform, global.native, global.router);
|
|
13
11
|
global.useCurrentRouteName = 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, _multiplatform, _native, _router) {
|
|
16
14
|
"use strict";
|
|
17
15
|
|
|
18
16
|
Object.defineProperty(_exports, "__esModule", {
|
|
@@ -46,10 +44,10 @@ require("core-js/modules/es.object.define-property.js");
|
|
|
46
44
|
function useCurrentRouteName() {
|
|
47
45
|
if (_multiplatform.MultiPlatform.isStorybook()) return null;
|
|
48
46
|
if (_multiplatform.MultiPlatform.isNext()) {
|
|
49
|
-
|
|
47
|
+
const router = (0, _router.useRouter)();
|
|
50
48
|
return router.route;
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
const route = (0, _native.useRoute)();
|
|
53
51
|
return route.name;
|
|
54
52
|
}
|
|
55
53
|
});
|