@multiplatform.one/keycloak 0.0.7 → 0.0.8

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.
Files changed (61) hide show
  1. package/esm/hooks/useKeycloak/index.js +1 -1
  2. package/esm/hooks/useKeycloak/index.js.map +1 -1
  3. package/esm/hooks/useKeycloak/useKeycloak.native.js +2 -2
  4. package/esm/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
  5. package/esm/provider/keycloakProvider.native.js +1 -1
  6. package/esm/provider/keycloakProvider.native.js.map +1 -1
  7. package/lib/hooks/useKeycloak/index.d.ts +1 -1
  8. package/lib/hooks/useKeycloak/index.js.map +1 -1
  9. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +1 -1
  10. package/lib/hooks/useKeycloak/useKeycloak.native.js +6 -6
  11. package/lib/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
  12. package/lib/provider/keycloakProvider.native.js +5 -5
  13. package/lib/provider/keycloakProvider.native.js.map +1 -1
  14. package/lib/tsconfig.build.tsbuildinfo +1 -1
  15. package/package.json +9 -3
  16. package/src/{expo/index.ts → @types/expoKeycloakAuth.d.ts} +7 -6
  17. package/src/hooks/useKeycloak/index.ts +1 -1
  18. package/src/hooks/useKeycloak/useKeycloak.native.ts +2 -2
  19. package/src/provider/keycloakProvider.native.tsx +1 -1
  20. package/esm/expo/ExpoKeycloakContext.js +0 -28
  21. package/esm/expo/ExpoKeycloakContext.js.map +0 -1
  22. package/esm/expo/ExpoKeycloakProvider.js +0 -113
  23. package/esm/expo/ExpoKeycloakProvider.js.map +0 -1
  24. package/esm/expo/const.js +0 -42
  25. package/esm/expo/const.js.map +0 -1
  26. package/esm/expo/helpers.js +0 -56
  27. package/esm/expo/helpers.js.map +0 -1
  28. package/esm/expo/index.js +0 -28
  29. package/esm/expo/index.js.map +0 -1
  30. package/esm/expo/useExpoKeycloak.js +0 -44
  31. package/esm/expo/useExpoKeycloak.js.map +0 -1
  32. package/esm/expo/useTokenStorage.js +0 -153
  33. package/esm/expo/useTokenStorage.js.map +0 -1
  34. package/lib/expo/ExpoKeycloakContext.d.ts +0 -32
  35. package/lib/expo/ExpoKeycloakContext.js +0 -47
  36. package/lib/expo/ExpoKeycloakContext.js.map +0 -1
  37. package/lib/expo/ExpoKeycloakProvider.d.ts +0 -37
  38. package/lib/expo/ExpoKeycloakProvider.js +0 -130
  39. package/lib/expo/ExpoKeycloakProvider.js.map +0 -1
  40. package/lib/expo/const.d.ts +0 -33
  41. package/lib/expo/const.js +0 -66
  42. package/lib/expo/const.js.map +0 -1
  43. package/lib/expo/helpers.d.ts +0 -41
  44. package/lib/expo/helpers.js +0 -77
  45. package/lib/expo/helpers.js.map +0 -1
  46. package/lib/expo/index.d.ts +0 -26
  47. package/lib/expo/index.js +0 -50
  48. package/lib/expo/index.js.map +0 -1
  49. package/lib/expo/useExpoKeycloak.d.ts +0 -31
  50. package/lib/expo/useExpoKeycloak.js +0 -62
  51. package/lib/expo/useExpoKeycloak.js.map +0 -1
  52. package/lib/expo/useTokenStorage.d.ts +0 -36
  53. package/lib/expo/useTokenStorage.js +0 -166
  54. package/lib/expo/useTokenStorage.js.map +0 -1
  55. package/src/expo/ExpoKeycloakContext.ts +0 -41
  56. package/src/expo/ExpoKeycloakProvider.tsx +0 -139
  57. package/src/expo/NOTES +0 -1
  58. package/src/expo/const.ts +0 -42
  59. package/src/expo/helpers.ts +0 -74
  60. package/src/expo/useExpoKeycloak.ts +0 -44
  61. package/src/expo/useTokenStorage.ts +0 -168
@@ -1,113 +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
-
25
- import React, { useCallback, useEffect } from "react";
26
- import { Platform } from "react-native";
27
- import * as AuthSession from "expo-auth-session";
28
- import { useAuthRequest, useAutoDiscovery } from "expo-auth-session";
29
- import { ExpoKeycloakContext } from "./ExpoKeycloakContext";
30
- import { useTokenStorage } from "./useTokenStorage";
31
- import { handleTokenExchange, getRealmURL } from "./helpers";
32
- import { NATIVE_REDIRECT_PATH } from "./const";
33
- export const ExpoKeycloakProvider = _ref => {
34
- let {
35
- realm,
36
- clientId,
37
- url,
38
- extraParams,
39
- children,
40
- ...options
41
- } = _ref;
42
- const discovery = useAutoDiscovery(getRealmURL({
43
- realm,
44
- url
45
- }));
46
- const redirectUri = AuthSession.makeRedirectUri({
47
- native: `${options.scheme ?? "exp"}://${options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH}`,
48
- useProxy: !options.scheme
49
- });
50
- const config = {
51
- clientId,
52
- extraParams,
53
- realm,
54
- redirectUri,
55
- url
56
- };
57
- const [request, response, promptAsync] = useAuthRequest({
58
- usePKCE: false,
59
- ...config
60
- }, discovery);
61
- const [currentToken, updateToken] = useTokenStorage(options, config, discovery);
62
- const handleLogin = useCallback(function () {
63
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
- return promptAsync(options);
65
- }, [request]);
66
- function handleLogout() {
67
- if (!currentToken) throw new Error("Not logged in.");
68
- try {
69
- if (discovery !== null && discovery !== void 0 && discovery.revocationEndpoint) {
70
- AuthSession.revokeAsync({
71
- token: currentToken === null || currentToken === void 0 ? void 0 : currentToken.accessToken,
72
- ...config
73
- }, discovery);
74
- }
75
- if (discovery !== null && discovery !== void 0 && discovery.endSessionEndpoint) {
76
- fetch(`${discovery.endSessionEndpoint}`, {
77
- method: "POST",
78
- headers: {
79
- "Content-Type": "application/x-www-form-urlencoded"
80
- },
81
- body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`
82
- });
83
- }
84
- if (Platform.OS === "ios") {
85
- AuthSession.dismiss();
86
- }
87
- } catch (error) {
88
- console.log(error);
89
- }
90
- updateToken(null);
91
- return undefined;
92
- }
93
- useEffect(() => {
94
- if (response) {
95
- handleTokenExchange({
96
- response,
97
- discovery: discovery,
98
- config
99
- }).then(updateToken);
100
- }
101
- }, [response]);
102
- return /*#__PURE__*/React.createElement(ExpoKeycloakContext.Provider, {
103
- // eslint-disable-next-line react/jsx-no-constructed-context-values
104
- value: {
105
- isLoggedIn: currentToken === undefined ? undefined : !!currentToken,
106
- login: handleLogin,
107
- logout: handleLogout,
108
- ready: discovery !== null && request !== null && currentToken !== undefined,
109
- token: currentToken
110
- }
111
- }, children);
112
- };
113
- //# sourceMappingURL=ExpoKeycloakProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoKeycloakProvider.js","names":["React","useCallback","useEffect","Platform","AuthSession","useAuthRequest","useAutoDiscovery","ExpoKeycloakContext","useTokenStorage","handleTokenExchange","getRealmURL","NATIVE_REDIRECT_PATH","ExpoKeycloakProvider","realm","clientId","url","extraParams","children","options","discovery","redirectUri","makeRedirectUri","native","scheme","nativeRedirectPath","useProxy","config","request","response","promptAsync","usePKCE","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/ExpoKeycloakProvider.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 { ExpoKeycloakContext } from \"./ExpoKeycloakContext\";\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 ExpoKeycloakProvider = ({\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 <ExpoKeycloakContext.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 </ExpoKeycloakContext.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,mBAAmB;AAC5B,SAASC,eAAe;AACxB,SAASC,mBAAmB,EAAEC,WAAW;AACzC,SAASC,oBAAoB;AAc7B,OAAO,MAAMC,oBAAoB,GAAG,QAON;EAAA,IAPO;IACnCC,KAAK;IACLC,QAAQ;IACRC,GAAG;IACHC,WAAW;IACXC,QAAQ;IACR,GAAGC;EACmB,CAAC;EACvB,MAAMC,SAA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AAE;UACvCE,MAAM,EAAE,MAAM;UACdC,OAAO,EAAE;YACP,cAAc,EAAE;UAClB,CAAC;UACDC,IAAI,EAAG,aAAY9B,QAAS,kBAAiBiB,YAAY,CAACc,YAAa;QACzE,CAAC,CAAC;MACJ;MACA,IAAI1C,QAAQ,CAAC2C,EAAE,KAAK,KAAK,EAAE;QACzB1C,WAAW,CAAC2C,OAAO,EAAE;MACvB;IACF,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACC,GAAG,CAACF,KAAK,CAAC;IACpB;IACAhB,WAAW,CAAC,IAAI,CAAC;IACjB,OAAOmB,SAAS;EAClB;EAEAjD,SAAS,CAAC,MAAM;IACd,IAAI0B,QAAQ,EAAE;MACZnB,mBAAmB,CAAC;QAAEmB,QAAQ;QAAET,SAAS,EAAEA,SAAU;QAAEO;MAAO,CAAC,CAAC,CAAC0B,IAAI,CACnEpB,WAAW,CACZ;IACH;EACF,CAAC,EAAE,CAACJ,QAAQ,CAAC,CAAC;EAEd,oBACE,oBAAC,mBAAmB,CAAC,QAAQ;IAC3B;IACA,KAAK,EAAE;MACLyB,UAAU,EAAEtB,YAAY,KAAKoB,SAAS,GAAGA,SAAS,GAAG,CAAC,CAACpB,YAAY;MACnEuB,KAAK,EAAErB,WAAW;MAClBsB,MAAM,EAAErB,YAAY;MACpBsB,KAAK,EACHrC,SAAS,KAAK,IAAI,IAAIQ,OAAO,KAAK,IAAI,IAAII,YAAY,KAAKoB,SAAS;MACtEb,KAAK,EAAEP;IACT;EAAE,GAEDd,QAAQ,CACoB;AAEnC,CAAC"}
package/esm/expo/const.js DELETED
@@ -1,42 +0,0 @@
1
- /**
2
- * File: /src/expo/const.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:17:10
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
- const logger = console;
26
- export const KC_INITIAL_VALUE = {
27
- ready: false,
28
- isLoggedIn: false,
29
- login: async () => {
30
- logger.error("kc not initialized");
31
- return undefined;
32
- },
33
- logout: () => {
34
- logger.error("not logged in");
35
- return undefined;
36
- },
37
- token: null
38
- };
39
- export const NATIVE_REDIRECT_PATH = "auth/redirect";
40
- export const TOKEN_STORAGE_KEY = "keycloak_token";
41
- export const REFRESH_TIME_BUFFER = 20;
42
- //# sourceMappingURL=const.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"const.js","names":["logger","console","KC_INITIAL_VALUE","ready","isLoggedIn","login","error","undefined","logout","token","NATIVE_REDIRECT_PATH","TOKEN_STORAGE_KEY","REFRESH_TIME_BUFFER"],"sources":["../../src/expo/const.ts"],"sourcesContent":["/**\n * File: /src/expo/const.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:17:10\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\nconst logger = console;\n\nexport const KC_INITIAL_VALUE = {\n ready: false,\n isLoggedIn: false,\n login: async () => {\n logger.error(\"kc not initialized\");\n return undefined;\n },\n logout: () => {\n logger.error(\"not logged in\");\n return undefined;\n },\n token: null,\n};\nexport const NATIVE_REDIRECT_PATH = \"auth/redirect\";\nexport const TOKEN_STORAGE_KEY = \"keycloak_token\";\nexport const REFRESH_TIME_BUFFER = 20;\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,MAAMA,MAAM,GAAGC,OAAO;AAEtB,OAAO,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,KAAK;EACZC,UAAU,EAAE,KAAK;EACjBC,KAAK,EAAE,YAAY;IACjBL,MAAM,CAACM,KAAK,CAAC,oBAAoB,CAAC;IAClC,OAAOC,SAAS;EAClB,CAAC;EACDC,MAAM,EAAE,MAAM;IACZR,MAAM,CAACM,KAAK,CAAC,eAAe,CAAC;IAC7B,OAAOC,SAAS;EAClB,CAAC;EACDE,KAAK,EAAE;AACT,CAAC;AACD,OAAO,MAAMC,oBAAoB,GAAG,eAAe;AACnD,OAAO,MAAMC,iBAAiB,GAAG,gBAAgB;AACjD,OAAO,MAAMC,mBAAmB,GAAG,EAAE"}
@@ -1,56 +0,0 @@
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
-
25
- import { exchangeCodeAsync } from "expo-auth-session";
26
- export function getRealmURL(config) {
27
- const {
28
- url,
29
- realm
30
- } = config;
31
- const slash = url.endsWith("/") ? "" : "/";
32
- return `${url + slash}realms/${encodeURIComponent(realm)}`;
33
- }
34
- export function getCurrentTimeInSeconds() {
35
- return Math.floor(Date.now() / 1000);
36
- }
37
- export async function handleTokenExchange(_ref) {
38
- let {
39
- response,
40
- discovery,
41
- config
42
- } = _ref;
43
- try {
44
- if ((response === null || response === void 0 ? void 0 : response.type) === "success" && !!(discovery !== null && discovery !== void 0 && discovery.tokenEndpoint)) {
45
- return exchangeCodeAsync({
46
- code: response.params.code,
47
- ...config
48
- }, discovery);
49
- }
50
- if ((response === null || response === void 0 ? void 0 : response.type) === "error") return null;
51
- return null;
52
- } catch (error) {
53
- return null;
54
- }
55
- }
56
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","names":["exchangeCodeAsync","getRealmURL","config","url","realm","slash","endsWith","encodeURIComponent","getCurrentTimeInSeconds","Math","floor","Date","now","handleTokenExchange","response","discovery","type","tokenEndpoint","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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEEA,iBAAiB,QAGZ,mBAAmB;AAE1B,OAAO,SAASC,WAAW,CAACC,MAAsB,EAAE;EAClD,MAAM;IAAEC,GAAG;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAC7B,MAAMG,KAAK,GAAGF,GAAG,CAACG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG;EAC1C,OAAQ,GAAEH,GAAG,GAAGE,KAAM,UAASE,kBAAkB,CAACH,KAAK,CAAE,EAAC;AAC5D;AAEA,OAAO,SAASI,uBAAuB,GAAG;EACxC,OAAOC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,GAAG,EAAE,GAAG,IAAI,CAAC;AACtC;AAEA,OAAO,eAAeC,mBAAmB,OAIvB;EAAA,IAJwB;IACxCC,QAAQ;IACRC,SAAS;IACTb;EACa,CAAC;EACd,IAAI;IACF,IAAI,CAAAY,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,SAAS,IAAI,CAAC,EAACD,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEE,aAAa,GAAE;MAC9D,OAAOjB,iBAAiB,CACtB;QAAEkB,IAAI,EAAEJ,QAAQ,CAACK,MAAM,CAACD,IAAI;QAAE,GAAGhB;MAAO,CAAC,EACzCa,SAAS,CACV;IACH;IACA,IAAI,CAAAD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,OAAO,EAAE,OAAO,IAAI;IAC3C,OAAO,IAAI;EACb,CAAC,CAAC,OAAOI,KAAK,EAAE;IACd,OAAO,IAAI;EACb;AACF"}
package/esm/expo/index.js DELETED
@@ -1,28 +0,0 @@
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
-
25
- export * from "./ExpoKeycloakProvider";
26
- export * from "./useExpoKeycloak";
27
- export * from "./const";
28
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA"}
@@ -1,44 +0,0 @@
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
-
25
- import { useContext } from "react";
26
- import { ExpoKeycloakContext } from "./ExpoKeycloakContext";
27
- export function useExpoKeycloak() {
28
- const {
29
- isLoggedIn,
30
- login,
31
- logout,
32
- ready = false,
33
- token = null
34
- } = useContext(ExpoKeycloakContext);
35
- return {
36
- isLoggedIn,
37
- login,
38
- logout,
39
- ready,
40
- token: (token === null || token === void 0 ? void 0 : token.accessToken) ?? null,
41
- refreshToken: (token === null || token === void 0 ? void 0 : token.refreshToken) ?? null
42
- };
43
- }
44
- //# sourceMappingURL=useExpoKeycloak.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useExpoKeycloak.js","names":["useContext","ExpoKeycloakContext","useExpoKeycloak","isLoggedIn","login","logout","ready","token","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":"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,UAAU,QAAQ,OAAO;AAClC,SAASC,mBAAmB;AAE5B,OAAO,SAASC,eAAe,GAAG;EAChC,MAAM;IACJC,UAAU;IACVC,KAAK;IACLC,MAAM;IACNC,KAAK,GAAG,KAAK;IACbC,KAAK,GAAG;EACV,CAAC,GAAGP,UAAU,CAACC,mBAAmB,CAAC;EACnC,OAAO;IACLE,UAAU;IACVC,KAAK;IACLC,MAAM;IACNC,KAAK;IACLC,KAAK,EAAE,CAAAA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,WAAW,KAAI,IAAI;IACjCC,YAAY,EAAE,CAAAF,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,YAAY,KAAI;EACvC,CAAC;AACH"}
@@ -1,153 +0,0 @@
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
-
25
- import { AppState, Platform } from "react-native";
26
- import { refreshAsync } from "expo-auth-session";
27
- import { REFRESH_TIME_BUFFER, TOKEN_STORAGE_KEY } from "./const";
28
- import { dismiss, revokeAsync, TokenResponse } from "expo-auth-session";
29
- import { getCurrentTimeInSeconds } from "./helpers";
30
- import { useAsyncStorage } from "@react-native-async-storage/async-storage";
31
- import { useEffect, useRef, useState } from "react";
32
- const logger = console;
33
- export function useTokenStorage(_ref, config, discovery) {
34
- let {
35
- disableAutoRefresh = false,
36
- refreshTimeBuffer = REFRESH_TIME_BUFFER,
37
- tokenStorageKey = TOKEN_STORAGE_KEY
38
- } = _ref;
39
- const [token, setToken] = useState();
40
- const {
41
- getItem,
42
- setItem,
43
- removeItem
44
- } = useAsyncStorage(tokenStorageKey);
45
- const refreshHandler = useRef(null);
46
- const appState = useRef(AppState.currentState);
47
- const refreshTime = useRef(null);
48
- const tokenData = useRef(null);
49
- async function updateAndSaveToken(newToken) {
50
- try {
51
- setToken(newToken);
52
- if (newToken !== null) {
53
- const stringifiedValue = JSON.stringify(newToken);
54
- await setItem(stringifiedValue);
55
- } else {
56
- await removeItem();
57
- }
58
- } catch (error) {
59
- logger.error(error);
60
- }
61
- }
62
- async function handleTokenRefresh(token) {
63
- try {
64
- const tokenResponse = await refreshAsync({
65
- refreshToken: token === null || token === void 0 ? void 0 : token.refreshToken,
66
- ...config
67
- }, discovery);
68
- updateAndSaveToken(tokenResponse);
69
- } catch (err) {
70
- updateAndSaveToken(null);
71
- }
72
- }
73
- useEffect(() => {
74
- function handleAppState(nextAppState) {
75
- if (appState.current.match(/inactive|background/) && nextAppState === "active") {
76
- if (refreshHandler.current !== null) {
77
- clearTimeout(refreshHandler.current);
78
- const now = getCurrentTimeInSeconds();
79
- if (Number(refreshTime.current) <= now) {
80
- setToken(null);
81
- } else {
82
- const timeout = 1000 * (Number(refreshTime.current) - now);
83
- // @ts-ignore
84
- refreshHandler.current = setTimeout(() => {
85
- handleTokenRefresh(tokenData.current);
86
- }, timeout);
87
- }
88
- }
89
- }
90
- appState.current = nextAppState;
91
- }
92
- const subscription = AppState.addEventListener("change", handleAppState);
93
- return () => {
94
- if (subscription) {
95
- subscription.remove();
96
- } else {
97
- // @ts-ignore
98
- AppState.removeEventListener("change", handleAppState);
99
- }
100
- };
101
- }, []);
102
- useEffect(() => {
103
- async function getTokenFromStorage() {
104
- try {
105
- const tokenFromStorage = await getItem();
106
- if (!tokenFromStorage) throw new Error("No token in storage");
107
- const token = JSON.parse(tokenFromStorage);
108
- if (!TokenResponse.isTokenFresh(token, -refreshTimeBuffer)) {
109
- handleTokenRefresh(token);
110
- } else {
111
- setToken(token);
112
- }
113
- } catch (error) {
114
- setToken(null);
115
- }
116
- }
117
- if (discovery) getTokenFromStorage();
118
- }, [discovery]);
119
- useEffect(() => {
120
- // trigger every token update
121
- // @ts-ignore
122
- tokenData.current = token || null;
123
- if (token !== undefined && !disableAutoRefresh) {
124
- if (refreshHandler.current !== null) {
125
- clearTimeout(refreshHandler.current);
126
- }
127
- if (token !== null && token !== void 0 && token.expiresIn) {
128
- const now = getCurrentTimeInSeconds();
129
- // @ts-ignore
130
- refreshTime.current = token.issuedAt + token.expiresIn - refreshTimeBuffer;
131
- const timeout = 1000 * (refreshTime.current - now);
132
- // @ts-ignore
133
- refreshHandler.current = setTimeout(() => {
134
- handleTokenRefresh(token);
135
- }, timeout);
136
- }
137
- if (token === null && tokenData.current !== null) {
138
- var _tokenData$current;
139
- revokeAsync({
140
- token: (_tokenData$current = tokenData.current) === null || _tokenData$current === void 0 ? void 0 : _tokenData$current.accessToken,
141
- ...config
142
- }, discovery);
143
- Platform.OS === "ios" && dismiss();
144
- // @ts-ignore
145
- refreshTime.current = null;
146
- // @ts-ignore
147
- tokenData.current = null;
148
- }
149
- }
150
- }, [token]);
151
- return [token || null, updateAndSaveToken];
152
- }
153
- //# sourceMappingURL=useTokenStorage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTokenStorage.js","names":["AppState","Platform","refreshAsync","REFRESH_TIME_BUFFER","TOKEN_STORAGE_KEY","dismiss","revokeAsync","TokenResponse","getCurrentTimeInSeconds","useAsyncStorage","useEffect","useRef","useState","logger","console","useTokenStorage","config","discovery","disableAutoRefresh","refreshTimeBuffer","tokenStorageKey","token","setToken","getItem","setItem","removeItem","refreshHandler","appState","currentState","refreshTime","tokenData","updateAndSaveToken","newToken","stringifiedValue","JSON","stringify","error","handleTokenRefresh","tokenResponse","refreshToken","err","handleAppState","nextAppState","current","match","clearTimeout","now","Number","timeout","setTimeout","subscription","addEventListener","remove","removeEventListener","getTokenFromStorage","tokenFromStorage","Error","parse","isTokenFresh","undefined","expiresIn","issuedAt","accessToken","OS"],"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":"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,QAAQ,EAAkBC,QAAQ,QAAQ,cAAc;AACjE,SAA4BC,YAAY,QAAQ,mBAAmB;AACnE,SAASC,mBAAmB,EAAEC,iBAAiB;AAC/C,SAASC,OAAO,EAAEC,WAAW,EAAEC,aAAa,QAAQ,mBAAmB;AACvE,SAASC,uBAAuB;AAChC,SAASC,eAAe,QAAQ,2CAA2C;AAC3E,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,MAAMC,MAAM,GAAGC,OAAO;AAEtB,OAAO,SAASC,eAAe,OAM7BC,MAMC,EACDC,SAA4B,EAC4C;EAAA,IAbxE;IACEC,kBAAkB,GAAG,KAAK;IAC1BC,iBAAiB,GAAGhB,mBAAmB;IACvCiB,eAAe,GAAGhB;EACpB,CAAC;EAUD,MAAM,CAACiB,KAAK,EAAEC,QAAQ,CAAC,GAAGV,QAAQ,EAAwB;EAC1D,MAAM;IAAEW,OAAO;IAAEC,OAAO;IAAEC;EAAW,CAAC,GAAGhB,eAAe,CAACW,eAAe,CAAC;EACzE,MAAMM,cAAc,GAAGf,MAAM,CAAiB,IAAI,CAAC;EACnD,MAAMgB,QAAQ,GAAGhB,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AAM;IACd;IACA;IACAoB,SAAS,CAACa,OAAO,GAAGtB,KAAK,IAAI,IAAI;IACjC,IAAIA,KAAK,KAAKsC,SAAS,IAAI,CAACzC,kBAAkB,EAAE;MAC9C,IAAIQ,cAAc,CAACiB,OAAO,KAAK,IAAI,EAAE;QACnCE,YAAY,CAACnB,cAAc,CAACiB,OAAO,CAAC;MACtC;MACA,IAAItB,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEuC,SAAS,EAAE;QACpB,MAAMd,GAAG,GAAGtC,uBAAuB,EAAE;QACrC;QACAqB,WAAW,CAACc,OAAO,GACjBtB,KAAK,CAACwC,QAAQ,GAAGxC,KAAK,CAACuC,SAAS,GAAGzC,iBAAiB;QACtD,MAAM6B,OAAO,GAAG,IAAI,IAAInB,WAAW,CAACc,OAAO,GAAGG,GAAG,CAAC;QAClD;QACApB,cAAc,CAACiB,OAAO,GAAGM,UAAU,CAAC,MAAM;UACxCZ,kBAAkB,CAAChB,KAAK,CAAC;QAC3B,CAAC,EAAE2B,OAAO,CAAC;MACb;MACA,IAAI3B,KAAK,KAAK,IAAI,IAAIS,SAAS,CAACa,OAAO,KAAK,IAAI,EAAE;QAAA;QAChDrC,WAAW,CACT;UAAEe,KAAK,wBAAES,SAAS,CAACa,OAAO,uDAAjB,mBAAmBmB,WAAW;UAAE,GAAG9C;QAAO,CAAC,EACpDC,SAAS,CACV;QACDhB,QAAQ,CAAC8D,EAAE,KAAK,KAAK,IAAI1D,OAAO,EAAE;QAClC;QACAwB,WAAW,CAACc,OAAO,GAAG,IAAI;QAC1B;QACAb,SAAS,CAACa,OAAO,GAAG,IAAI;MAC1B;IACF;EACF,CAAC,EAAE,CAACtB,KAAK,CAAC,CAAC;EAEX,OAAO,CAACA,KAAK,IAAI,IAAI,EAAEU,kBAAkB,CAAC;AAC5C"}
@@ -1,32 +0,0 @@
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
- }>;
@@ -1,47 +0,0 @@
1
- (function (global, factory) {
2
- if (typeof define === "function" && define.amd) {
3
- define(["exports", "react", "./const"], factory);
4
- } else if (typeof exports !== "undefined") {
5
- factory(exports, require("react"), require("./const"));
6
- } else {
7
- var mod = {
8
- exports: {}
9
- };
10
- factory(mod.exports, global.react, global._const);
11
- global.ExpoKeycloakContext = mod.exports;
12
- }
13
- })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _const) {
14
- "use strict";
15
-
16
- Object.defineProperty(_exports, "__esModule", {
17
- value: true
18
- });
19
- _exports.ExpoKeycloakContext = void 0;
20
- /**
21
- * File: /src/expo/ExpoKeycloakContext.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:25
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 ExpoKeycloakContext = /*#__PURE__*/(0, _react.createContext)(_const.KC_INITIAL_VALUE);
45
- _exports.ExpoKeycloakContext = ExpoKeycloakContext;
46
- });
47
- //# sourceMappingURL=ExpoKeycloakContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoKeycloakContext.js","names":["ExpoKeycloakContext","createContext","KC_INITIAL_VALUE"],"sources":["../../src/expo/ExpoKeycloakContext.ts"],"sourcesContent":["/**\n * File: /src/expo/ExpoKeycloakContext.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:25\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 ExpoKeycloakContext = 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,MAAMA,mBAAmB,gBAAG,IAAAC,oBAAa,EAQ7CC,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 ExpoKeycloakProvider: ({ realm, clientId, url, extraParams, children, ...options }: IKeycloakConfiguration) => JSX.Element;