@multiplatform.one/keycloak 0.1.9 → 0.2.0
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/dist/esm/Authenticated.mjs +25 -0
- package/dist/esm/Authenticated.mjs.map +7 -0
- package/dist/esm/authConfig.mjs +10 -0
- package/dist/esm/authConfig.mjs.map +7 -0
- package/dist/esm/hooks/index.mjs +4 -0
- package/dist/esm/hooks/index.mjs.map +7 -0
- package/dist/esm/hooks/useAuthConfig.mjs +9 -0
- package/dist/esm/hooks/useAuthConfig.mjs.map +7 -0
- package/dist/esm/hooks/useCurrentRouteName/index.mjs +17 -0
- package/dist/esm/hooks/useCurrentRouteName/index.mjs.map +7 -0
- package/dist/esm/hooks/useCurrentRouteName/index.native.mjs +12 -0
- package/dist/esm/hooks/useCurrentRouteName/index.native.mjs.map +7 -0
- package/dist/esm/hooks/useKeycloak/index.mjs +2 -0
- package/dist/esm/hooks/useKeycloak/index.mjs.map +7 -0
- package/dist/esm/hooks/useKeycloak/useKeycloak.mjs +81 -0
- package/dist/esm/hooks/useKeycloak/useKeycloak.mjs.map +7 -0
- package/dist/esm/hooks/useKeycloak/useKeycloak.native.mjs +108 -0
- package/dist/esm/hooks/useKeycloak/useKeycloak.native.mjs.map +7 -0
- package/dist/esm/hooks/useLogin.mjs +35 -0
- package/dist/esm/hooks/useLogin.mjs.map +7 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/provider/afterAuth.mjs +29 -0
- package/dist/esm/provider/afterAuth.mjs.map +7 -0
- package/dist/esm/provider/index.mjs +73 -0
- package/dist/esm/provider/index.mjs.map +7 -0
- package/dist/esm/provider/keycloakProvider.mjs +275 -0
- package/dist/esm/provider/keycloakProvider.mjs.map +7 -0
- package/dist/esm/provider/keycloakProvider.native.mjs +69 -0
- package/dist/esm/provider/keycloakProvider.native.mjs.map +7 -0
- package/dist/esm/state/index.mjs +14 -0
- package/dist/esm/state/index.mjs.map +7 -0
- package/dist/esm/types.mjs +5 -0
- package/dist/esm/types.mjs.map +7 -0
- package/dist/jsx/Authenticated.mjs +20 -0
- package/dist/jsx/Authenticated.mjs.map +7 -0
- package/dist/jsx/authConfig.mjs +10 -0
- package/dist/jsx/authConfig.mjs.map +7 -0
- package/dist/jsx/hooks/index.mjs +4 -0
- package/dist/jsx/hooks/index.mjs.map +7 -0
- package/dist/jsx/hooks/useAuthConfig.mjs +9 -0
- package/dist/jsx/hooks/useAuthConfig.mjs.map +7 -0
- package/dist/jsx/hooks/useCurrentRouteName/index.mjs +17 -0
- package/dist/jsx/hooks/useCurrentRouteName/index.mjs.map +7 -0
- package/dist/jsx/hooks/useCurrentRouteName/index.native.mjs +12 -0
- package/dist/jsx/hooks/useCurrentRouteName/index.native.mjs.map +7 -0
- package/dist/jsx/hooks/useKeycloak/index.mjs +2 -0
- package/dist/jsx/hooks/useKeycloak/index.mjs.map +7 -0
- package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs +25 -0
- package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs.map +7 -0
- package/dist/jsx/hooks/useKeycloak/useKeycloak.native.mjs +58 -0
- package/dist/jsx/hooks/useKeycloak/useKeycloak.native.mjs.map +7 -0
- package/dist/jsx/hooks/useLogin.mjs +33 -0
- package/dist/jsx/hooks/useLogin.mjs.map +7 -0
- package/dist/jsx/index.mjs +5 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/dist/jsx/provider/afterAuth.mjs +28 -0
- package/dist/jsx/provider/afterAuth.mjs.map +7 -0
- package/dist/jsx/provider/index.mjs +20 -0
- package/dist/jsx/provider/index.mjs.map +7 -0
- package/dist/jsx/provider/keycloakProvider.mjs +158 -0
- package/dist/jsx/provider/keycloakProvider.mjs.map +7 -0
- package/dist/jsx/provider/keycloakProvider.native.mjs +14 -0
- package/dist/jsx/provider/keycloakProvider.native.mjs.map +7 -0
- package/dist/jsx/state/index.mjs +17 -0
- package/dist/jsx/state/index.mjs.map +7 -0
- package/dist/jsx/types.mjs +5 -0
- package/dist/jsx/types.mjs.map +7 -0
- package/{lib → dist/lib}/Authenticated.d.ts +1 -1
- package/dist/lib/Authenticated.js +60 -0
- package/dist/lib/Authenticated.js.map +7 -0
- package/dist/lib/authConfig.js +35 -0
- package/dist/lib/authConfig.js.map +7 -0
- package/{lib → dist/lib}/hooks/index.d.ts +3 -3
- package/dist/lib/hooks/index.js +21 -0
- package/dist/lib/hooks/index.js.map +7 -0
- package/dist/lib/hooks/useAuthConfig.js +33 -0
- package/dist/lib/hooks/useAuthConfig.js.map +7 -0
- package/{lib/hooks/useCurrentRouteName.d.ts → dist/lib/hooks/useCurrentRouteName/index.d.ts} +5 -5
- package/dist/lib/hooks/useCurrentRouteName/index.js +41 -0
- package/dist/lib/hooks/useCurrentRouteName/index.js.map +7 -0
- package/{esm/types.js → dist/lib/hooks/useCurrentRouteName/index.native.d.ts} +5 -7
- package/dist/lib/hooks/useCurrentRouteName/index.native.js +36 -0
- package/dist/lib/hooks/useCurrentRouteName/index.native.js.map +7 -0
- package/{lib → dist/lib}/hooks/useKeycloak/index.d.ts +2 -2
- package/dist/lib/hooks/useKeycloak/index.js +19 -0
- package/dist/lib/hooks/useKeycloak/index.js.map +7 -0
- package/{lib → dist/lib}/hooks/useKeycloak/useKeycloak.d.ts +2 -2
- package/dist/lib/hooks/useKeycloak/useKeycloak.js +63 -0
- package/dist/lib/hooks/useKeycloak/useKeycloak.js.map +7 -0
- package/{lib → dist/lib}/hooks/useKeycloak/useKeycloak.native.d.ts +4 -4
- package/dist/lib/hooks/useKeycloak/useKeycloak.native.js +93 -0
- package/dist/lib/hooks/useKeycloak/useKeycloak.native.js.map +7 -0
- package/{lib → dist/lib}/hooks/useLogin.d.ts +1 -1
- package/dist/lib/hooks/useLogin.js +57 -0
- package/dist/lib/hooks/useLogin.js.map +7 -0
- package/{lib → dist/lib}/index.d.ts +4 -4
- package/dist/lib/index.js +22 -0
- package/dist/lib/index.js.map +7 -0
- package/{lib → dist/lib}/provider/afterAuth.d.ts +1 -1
- package/dist/lib/provider/afterAuth.js +53 -0
- package/dist/lib/provider/afterAuth.js.map +7 -0
- package/{lib → dist/lib}/provider/index.d.ts +4 -4
- package/dist/lib/provider/index.js +61 -0
- package/dist/lib/provider/index.js.map +7 -0
- package/{lib → dist/lib}/provider/keycloakProvider.d.ts +2 -2
- package/dist/lib/provider/keycloakProvider.js +212 -0
- package/dist/lib/provider/keycloakProvider.js.map +7 -0
- package/{lib → dist/lib}/provider/keycloakProvider.native.d.ts +2 -2
- package/dist/lib/provider/keycloakProvider.native.js +55 -0
- package/dist/lib/provider/keycloakProvider.native.js.map +7 -0
- package/{esm/state/index.js → dist/lib/state/index.d.ts} +8 -13
- package/dist/lib/state/index.js +41 -0
- package/dist/lib/state/index.js.map +7 -0
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -0
- package/dist/lib/types.js +27 -0
- package/dist/lib/types.js.map +7 -0
- package/package.json +43 -62
- package/src/@types/coreJsPure.d.ts +2 -2
- package/src/@types/expoKeycloakAuth.d.ts +1 -1
- package/src/Authenticated.tsx +5 -8
- package/src/authConfig.ts +1 -1
- package/src/hooks/index.ts +3 -3
- package/src/hooks/useAuthConfig.ts +2 -2
- package/{esm/hooks/useCurrentRouteName.js → src/hooks/useCurrentRouteName/index.native.ts} +8 -13
- package/src/hooks/{useCurrentRouteName.ts → useCurrentRouteName/index.ts} +8 -8
- package/src/hooks/useKeycloak/index.ts +2 -6
- package/src/hooks/useKeycloak/useKeycloak.native.ts +18 -32
- package/src/hooks/useKeycloak/useKeycloak.ts +7 -7
- package/src/hooks/useLogin.ts +7 -7
- package/src/index.ts +4 -4
- package/src/provider/afterAuth.tsx +10 -11
- package/src/provider/index.tsx +9 -12
- package/src/provider/keycloakProvider.native.tsx +8 -10
- package/src/provider/keycloakProvider.tsx +44 -61
- package/src/state/index.ts +13 -10
- package/esm/Authenticated.js +0 -42
- package/esm/Authenticated.js.map +0 -1
- package/esm/authConfig.js +0 -30
- package/esm/authConfig.js.map +0 -1
- package/esm/hooks/index.js +0 -28
- package/esm/hooks/index.js.map +0 -1
- package/esm/hooks/useAuthConfig.js +0 -30
- package/esm/hooks/useAuthConfig.js.map +0 -1
- package/esm/hooks/useCurrentRouteName.js.map +0 -1
- package/esm/hooks/useKeycloak/index.js +0 -27
- package/esm/hooks/useKeycloak/index.js.map +0 -1
- package/esm/hooks/useKeycloak/useKeycloak.js +0 -55
- package/esm/hooks/useKeycloak/useKeycloak.js.map +0 -1
- package/esm/hooks/useKeycloak/useKeycloak.native.js +0 -91
- package/esm/hooks/useKeycloak/useKeycloak.native.js.map +0 -1
- package/esm/hooks/useLogin.js +0 -50
- package/esm/hooks/useLogin.js.map +0 -1
- package/esm/index.js +0 -29
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -1
- package/esm/provider/afterAuth.js +0 -58
- package/esm/provider/afterAuth.js.map +0 -1
- package/esm/provider/index.js +0 -43
- package/esm/provider/index.js.map +0 -1
- package/esm/provider/keycloakProvider.js +0 -175
- package/esm/provider/keycloakProvider.js.map +0 -1
- package/esm/provider/keycloakProvider.native.js +0 -41
- package/esm/provider/keycloakProvider.native.js.map +0 -1
- package/esm/state/index.js.map +0 -1
- package/esm/types.js.map +0 -1
- package/lib/Authenticated.js +0 -64
- package/lib/Authenticated.js.map +0 -1
- package/lib/authConfig.js +0 -51
- package/lib/authConfig.js.map +0 -1
- package/lib/hooks/index.js +0 -50
- package/lib/hooks/index.js.map +0 -1
- package/lib/hooks/useAuthConfig.js +0 -48
- package/lib/hooks/useAuthConfig.js.map +0 -1
- package/lib/hooks/useCurrentRouteName.js +0 -54
- package/lib/hooks/useCurrentRouteName.js.map +0 -1
- package/lib/hooks/useKeycloak/index.js +0 -30
- package/lib/hooks/useKeycloak/index.js.map +0 -1
- package/lib/hooks/useKeycloak/useKeycloak.js +0 -71
- package/lib/hooks/useKeycloak/useKeycloak.js.map +0 -1
- package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -112
- package/lib/hooks/useKeycloak/useKeycloak.native.js.map +0 -1
- package/lib/hooks/useLogin.js +0 -65
- package/lib/hooks/useLogin.js.map +0 -1
- package/lib/index.js +0 -60
- package/lib/index.js.map +0 -1
- package/lib/package.json +0 -1
- package/lib/provider/afterAuth.js +0 -78
- package/lib/provider/afterAuth.js.map +0 -1
- package/lib/provider/index.js +0 -77
- package/lib/provider/index.js.map +0 -1
- package/lib/provider/keycloakProvider.js +0 -193
- package/lib/provider/keycloakProvider.js.map +0 -1
- package/lib/provider/keycloakProvider.native.js +0 -61
- package/lib/provider/keycloakProvider.native.js.map +0 -1
- package/lib/state/index.d.ts +0 -34
- package/lib/state/index.js +0 -55
- package/lib/state/index.js.map +0 -1
- package/lib/tsconfig.build.tsbuildinfo +0 -1
- package/lib/types.js +0 -46
- package/lib/types.js.map +0 -1
- /package/{lib → dist/lib}/authConfig.d.ts +0 -0
- /package/{lib → dist/lib}/hooks/useAuthConfig.d.ts +0 -0
- /package/{lib → dist/lib}/types.d.ts +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useKeycloak/useKeycloak.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useKeycloak/useKeycloak.ts\n * Project: app\n * File Created: 08-11-2022 06:04:59\n * Author: Clay Risser\n * -----\n * Last Modified: 24-02-2023 06:22:07\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 type Keycloak from 'keycloak-js';\nimport type { IKeycloak } from './index';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { useAuthConfig } from '../useAuthConfig';\nimport { useKeycloak as useReactKeycloak } from '@react-keycloak/web';\nimport { useKeycloak as useSsrKeycloak } from '@react-keycloak/ssr';\n\nexport function useKeycloak() {\n const authConfig = useAuthConfig();\n if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;\n if (MultiPlatform.isNext && authConfig.ssr) {\n const { keycloak: ssrKeycloak, initialized } = useSsrKeycloak();\n const keycloak = { ...ssrKeycloak } as Keycloak;\n if (!initialized) keycloak.authenticated = undefined;\n return keycloak as IKeycloak;\n }\n const { keycloak: reactKeycloak, initialized } = useReactKeycloak();\n const keycloak = { ...reactKeycloak } as Keycloak;\n if (!initialized) keycloak.authenticated = undefined;\n return keycloak as IKeycloak;\n}\n"],
|
|
5
|
+
"mappings": "AA0BA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,eAAe,wBAAwB;AAChD,SAAS,eAAe,sBAAsB;AAEvC,SAAS,cAAc;AAC5B,QAAM,aAAa,cAAc;AACjC,MAAI,cAAc;AAAa,WAAO,EAAE,eAAe,KAAK;AAC5D,MAAI,cAAc,UAAU,WAAW,KAAK;AAC1C,UAAM,EAAE,UAAU,aAAa,aAAAA,aAAY,IAAI,eAAe;AAC9D,UAAMC,YAAW,EAAE,GAAG,YAAY;AAClC,QAAI,CAACD;AAAa,MAAAC,UAAS,gBAAgB;AAC3C,WAAOA;AAAA,EACT;AACA,QAAM,EAAE,UAAU,eAAe,YAAY,IAAI,iBAAiB;AAClE,QAAM,WAAW,EAAE,GAAG,cAAc;AACpC,MAAI,CAAC;AAAa,aAAS,gBAAgB;AAC3C,SAAO;AACT;",
|
|
6
|
+
"names": ["initialized", "keycloak"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import atob from "core-js-pure/stable/atob";
|
|
2
|
+
import escape from "core-js-pure/stable/escape";
|
|
3
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
4
|
+
import { useKeycloak as useExpoKeycloak } from "expo-keycloak-auth";
|
|
5
|
+
function useKeycloak() {
|
|
6
|
+
if (MultiPlatform.isStorybook)
|
|
7
|
+
return { authenticated: true };
|
|
8
|
+
const { ready, login, isLoggedIn, token, logout, refreshToken } = useExpoKeycloak();
|
|
9
|
+
const keycloak = new ExpoKeycloak(ready, isLoggedIn, login, logout, token || void 0, refreshToken || void 0);
|
|
10
|
+
return keycloak;
|
|
11
|
+
}
|
|
12
|
+
class ExpoKeycloak {
|
|
13
|
+
constructor(ready, isLoggedIn, login, logout, token, refreshToken) {
|
|
14
|
+
this.logout = logout;
|
|
15
|
+
this.token = token;
|
|
16
|
+
this.refreshToken = refreshToken;
|
|
17
|
+
if (ready)
|
|
18
|
+
this.authenticated = isLoggedIn;
|
|
19
|
+
if (this.authenticated) {
|
|
20
|
+
if (this.token)
|
|
21
|
+
this.tokenParsed = decodeToken(this.token);
|
|
22
|
+
if (this.refreshToken) {
|
|
23
|
+
this.refreshTokenParsed = decodeToken(this.refreshToken);
|
|
24
|
+
}
|
|
25
|
+
if (this.tokenParsed) {
|
|
26
|
+
this.subject = this.tokenParsed.sub;
|
|
27
|
+
this.realmAccess = this.tokenParsed.realm_access;
|
|
28
|
+
this.resourceAccess = this.tokenParsed.resource_access;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
this.login = () => login();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function decodeToken(str) {
|
|
35
|
+
str = str.split(".")[1];
|
|
36
|
+
str = str.replace(/-/g, "+");
|
|
37
|
+
str = str.replace(/_/g, "/");
|
|
38
|
+
switch (str.length % 4) {
|
|
39
|
+
case 0:
|
|
40
|
+
break;
|
|
41
|
+
case 2:
|
|
42
|
+
str += "==";
|
|
43
|
+
break;
|
|
44
|
+
case 3:
|
|
45
|
+
str += "=";
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
throw "Invalid token";
|
|
49
|
+
}
|
|
50
|
+
str = decodeURIComponent(escape(atob(str)));
|
|
51
|
+
str = JSON.parse(str);
|
|
52
|
+
return str;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
ExpoKeycloak,
|
|
56
|
+
useKeycloak
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=useKeycloak.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useKeycloak/useKeycloak.native.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useKeycloak/useKeycloak.native.ts\n * Project: app\n * File Created: 08-11-2022 14:10:25\n * Author: Clay Risser\n * -----\n * Last Modified: 24-02-2023 06:29:25\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 atob from 'core-js-pure/stable/atob';\nimport escape from 'core-js-pure/stable/escape';\nimport type { AuthRequestPromptOptions, AuthSessionResult } from 'expo-auth-session';\nimport type { IKeycloak } from './index';\nimport type { KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed } from 'keycloak-js';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { useKeycloak as useExpoKeycloak } from 'expo-keycloak-auth';\n\nexport function useKeycloak() {\n if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;\n const { ready, login, isLoggedIn, token, logout, refreshToken } = useExpoKeycloak();\n const keycloak = new ExpoKeycloak(ready, isLoggedIn, login, logout, token || undefined, refreshToken || undefined);\n return keycloak as IKeycloak;\n}\n\nexport class ExpoKeycloak implements IKeycloak {\n authenticated?: boolean;\n\n tokenParsed?: KeycloakTokenParsed;\n\n refreshTokenParsed?: KeycloakTokenParsed;\n\n subject?: string;\n\n realmAccess?: KeycloakRoles;\n\n resourceAccess?: KeycloakResourceAccess;\n\n login: () => Promise<unknown> | unknown;\n\n constructor(\n ready: boolean,\n isLoggedIn: boolean | undefined,\n login: (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult | undefined>,\n public logout: () => unknown,\n public token?: string,\n public refreshToken?: string,\n ) {\n if (ready) this.authenticated = isLoggedIn;\n if (this.authenticated) {\n if (this.token) this.tokenParsed = decodeToken(this.token);\n if (this.refreshToken) {\n this.refreshTokenParsed = decodeToken(this.refreshToken);\n }\n if (this.tokenParsed) {\n this.subject = this.tokenParsed.sub;\n this.realmAccess = this.tokenParsed.realm_access;\n this.resourceAccess = this.tokenParsed.resource_access;\n }\n }\n this.login = () => login();\n }\n}\n\nfunction decodeToken(str: string) {\n str = str.split('.')[1];\n str = str.replace(/-/g, '+');\n str = str.replace(/_/g, '/');\n switch (str.length % 4) {\n case 0:\n break;\n case 2:\n str += '==';\n break;\n case 3:\n str += '=';\n break;\n default:\n throw 'Invalid token';\n }\n str = decodeURIComponent(escape(atob(str)));\n str = JSON.parse(str);\n return str as unknown as KeycloakTokenParsed;\n}\n"],
|
|
5
|
+
"mappings": "AAwBA,OAAO,UAAU;AACjB,OAAO,YAAY;AAInB,SAAS,qBAAqB;AAC9B,SAAS,eAAe,uBAAuB;AAExC,SAAS,cAAc;AAC5B,MAAI,cAAc;AAAa,WAAO,EAAE,eAAe,KAAK;AAC5D,QAAM,EAAE,OAAO,OAAO,YAAY,OAAO,QAAQ,aAAa,IAAI,gBAAgB;AAClF,QAAM,WAAW,IAAI,aAAa,OAAO,YAAY,OAAO,QAAQ,SAAS,QAAW,gBAAgB,MAAS;AACjH,SAAO;AACT;AAEO,MAAM,aAAkC;AAAA,EAe7C,YACE,OACA,YACA,OACO,QACA,OACA,cACP;AAHO;AACA;AACA;AAEP,QAAI;AAAO,WAAK,gBAAgB;AAChC,QAAI,KAAK,eAAe;AACtB,UAAI,KAAK;AAAO,aAAK,cAAc,YAAY,KAAK,KAAK;AACzD,UAAI,KAAK,cAAc;AACrB,aAAK,qBAAqB,YAAY,KAAK,YAAY;AAAA,MACzD;AACA,UAAI,KAAK,aAAa;AACpB,aAAK,UAAU,KAAK,YAAY;AAChC,aAAK,cAAc,KAAK,YAAY;AACpC,aAAK,iBAAiB,KAAK,YAAY;AAAA,MACzC;AAAA,IACF;AACA,SAAK,QAAQ,MAAM,MAAM;AAAA,EAC3B;AACF;AAEA,SAAS,YAAY,KAAa;AAChC,QAAM,IAAI,MAAM,GAAG,EAAE,CAAC;AACtB,QAAM,IAAI,QAAQ,MAAM,GAAG;AAC3B,QAAM,IAAI,QAAQ,MAAM,GAAG;AAC3B,UAAQ,IAAI,SAAS,GAAG;AAAA,IACtB,KAAK;AACH;AAAA,IACF,KAAK;AACH,aAAO;AACP;AAAA,IACF,KAAK;AACH,aAAO;AACP;AAAA,IACF;AACE,YAAM;AAAA,EACV;AACA,QAAM,mBAAmB,OAAO,KAAK,GAAG,CAAC,CAAC;AAC1C,QAAM,KAAK,MAAM,GAAG;AACpB,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
2
|
+
import { useAuthConfig } from "./useAuthConfig";
|
|
3
|
+
import { useCurrentRouteName } from "./useCurrentRouteName";
|
|
4
|
+
import { useKeycloak } from "./useKeycloak/useKeycloak";
|
|
5
|
+
import { useRouter } from "solito/router";
|
|
6
|
+
function useLogin(loginRoute) {
|
|
7
|
+
if (MultiPlatform.isStorybook)
|
|
8
|
+
return () => null;
|
|
9
|
+
const keycloak = useKeycloak();
|
|
10
|
+
const authConfig = useAuthConfig();
|
|
11
|
+
const currentRouteName = useCurrentRouteName();
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
return () => {
|
|
14
|
+
if (!loginRoute)
|
|
15
|
+
loginRoute = authConfig.loginRoute;
|
|
16
|
+
if (!loginRoute) {
|
|
17
|
+
keycloak.login();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const url = new URL(`x://${loginRoute}`);
|
|
21
|
+
const searchParams = new URLSearchParams(url.search);
|
|
22
|
+
if (currentRouteName)
|
|
23
|
+
searchParams.append("backTo", currentRouteName);
|
|
24
|
+
let query = searchParams.toString();
|
|
25
|
+
if (query.length)
|
|
26
|
+
query = `?${query}`;
|
|
27
|
+
router.push(`${url.pathname.substring(2)}${query}`);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
useLogin
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=useLogin.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useLogin.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useLogin.ts\n * Project: app\n * File Created: 08-11-2022 08:49:14\n * Author: Clay Risser\n * -----\n * Last Modified: 24-02-2023 06:22:27\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 { MultiPlatform } from 'multiplatform.one';\nimport { useAuthConfig } from './useAuthConfig';\nimport { useCurrentRouteName } from './useCurrentRouteName';\nimport { useKeycloak } from './useKeycloak/useKeycloak';\nimport { useRouter } from 'solito/router';\n\nexport function useLogin(loginRoute?: string) {\n if (MultiPlatform.isStorybook) return () => null;\n const keycloak = useKeycloak();\n const authConfig = useAuthConfig();\n const currentRouteName = useCurrentRouteName();\n const router = useRouter();\n return () => {\n if (!loginRoute) loginRoute = authConfig.loginRoute;\n if (!loginRoute) {\n keycloak.login();\n return;\n }\n const url = new URL(`x://${loginRoute}`);\n const searchParams = new URLSearchParams(url.search);\n if (currentRouteName) searchParams.append('backTo', currentRouteName);\n let query = searchParams.toString();\n if (query.length) query = `?${query}`;\n router.push(`${url.pathname.substring(2)}${query}`);\n };\n}\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAEnB,SAAS,SAAS,YAAqB;AAC5C,MAAI,cAAc;AAAa,WAAO,MAAM;AAC5C,QAAM,WAAW,YAAY;AAC7B,QAAM,aAAa,cAAc;AACjC,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,SAAS,UAAU;AACzB,SAAO,MAAM;AACX,QAAI,CAAC;AAAY,mBAAa,WAAW;AACzC,QAAI,CAAC,YAAY;AACf,eAAS,MAAM;AACf;AAAA,IACF;AACA,UAAM,MAAM,IAAI,IAAI,OAAO,YAAY;AACvC,UAAM,eAAe,IAAI,gBAAgB,IAAI,MAAM;AACnD,QAAI;AAAkB,mBAAa,OAAO,UAAU,gBAAgB;AACpE,QAAI,QAAQ,aAAa,SAAS;AAClC,QAAI,MAAM;AAAQ,cAAQ,IAAI;AAC9B,WAAO,KAAK,GAAG,IAAI,SAAS,UAAU,CAAC,IAAI,OAAO;AAAA,EACpD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/index.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 25-11-2022 09:51:55\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 09:52:06\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 './Authenticated';\nexport * from './authConfig';\nexport * from './hooks';\nexport * from './provider';\n"],
|
|
5
|
+
"mappings": "AAwBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useAuthConfig } from "../hooks/useAuthConfig";
|
|
3
|
+
import { useAuthState } from "../state";
|
|
4
|
+
import { useKeycloak } from "../hooks";
|
|
5
|
+
const logger = console;
|
|
6
|
+
const AfterAuth = ({ children }) => {
|
|
7
|
+
const authConfig = useAuthConfig();
|
|
8
|
+
const { token, refreshToken, authenticated } = useKeycloak();
|
|
9
|
+
const authState = useAuthState();
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!authenticated)
|
|
12
|
+
return;
|
|
13
|
+
if (token) {
|
|
14
|
+
authState.setToken(token);
|
|
15
|
+
if (refreshToken)
|
|
16
|
+
authState.setRefreshToken(refreshToken);
|
|
17
|
+
}
|
|
18
|
+
}, [token, refreshToken]);
|
|
19
|
+
if (authConfig.debug) {
|
|
20
|
+
logger.debug("authenticated", authenticated);
|
|
21
|
+
logger.debug("token", token);
|
|
22
|
+
}
|
|
23
|
+
return <>{children}</>;
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
AfterAuth
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=afterAuth.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/provider/afterAuth.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/provider/afterAuth.tsx\n * Project: app\n * File Created: 22-11-2022 17:49:58\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:39\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport type { FC, ReactNode } from 'react';\nimport { useAuthConfig } from '../hooks/useAuthConfig';\nimport { useAuthState } from '../state';\nimport { useKeycloak } from '../hooks';\n\nexport interface AfterAuthProps {\n children: ReactNode;\n}\n\nconst logger = console;\n\nexport const AfterAuth: FC<AfterAuthProps> = ({ children }: AfterAuthProps) => {\n const authConfig = useAuthConfig();\n const { token, refreshToken, authenticated } = useKeycloak();\n const authState = useAuthState();\n\n useEffect(() => {\n if (!authenticated) return;\n if (token) {\n authState.setToken(token);\n if (refreshToken) authState.setRefreshToken(refreshToken);\n }\n }, [token, refreshToken]);\n\n if (authConfig.debug) {\n logger.debug('authenticated', authenticated);\n logger.debug('token', token);\n }\n return <>{children}</>;\n};\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAgB,iBAAiB;AAEjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAM5B,MAAM,SAAS;AAER,MAAM,YAAgC,CAAC,EAAE,SAAS,MAAsB;AAC7E,QAAM,aAAa,cAAc;AACjC,QAAM,EAAE,OAAO,cAAc,cAAc,IAAI,YAAY;AAC3D,QAAM,YAAY,aAAa;AAE/B,YAAU,MAAM;AACd,QAAI,CAAC;AAAe;AACpB,QAAI,OAAO;AACT,gBAAU,SAAS,KAAK;AACxB,UAAI;AAAc,kBAAU,gBAAgB,YAAY;AAAA,IAC1D;AAAA,EACF,GAAG,CAAC,OAAO,YAAY,CAAC;AAExB,MAAI,WAAW,OAAO;AACpB,WAAO,MAAM,iBAAiB,aAAa;AAC3C,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B;AACA,SAAO,GAAG,SAAS;AACrB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { AuthConfigContext, defaultAuthConfig } from "../authConfig";
|
|
3
|
+
import { KeycloakProvider } from "./keycloakProvider";
|
|
4
|
+
const AuthProvider = (props) => {
|
|
5
|
+
const { authConfig, debug } = props;
|
|
6
|
+
const authConfigValue = useMemo(
|
|
7
|
+
() => ({
|
|
8
|
+
...defaultAuthConfig,
|
|
9
|
+
...authConfig,
|
|
10
|
+
debug: !!debug
|
|
11
|
+
}),
|
|
12
|
+
[]
|
|
13
|
+
);
|
|
14
|
+
return <AuthConfigContext.Provider value={authConfigValue}><KeycloakProvider {...props} /></AuthConfigContext.Provider>;
|
|
15
|
+
};
|
|
16
|
+
export * from "./keycloakProvider";
|
|
17
|
+
export {
|
|
18
|
+
AuthProvider
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/provider/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/provider/index.tsx\n * Project: app\n * File Created: 08-11-2022 06:33:07\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:13\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useMemo } from 'react';\nimport type { AuthConfig } from '../authConfig';\nimport type { FC } from 'react';\nimport type { KeycloakProviderProps } from './keycloakProvider';\nimport { AuthConfigContext, defaultAuthConfig } from '../authConfig';\nimport { KeycloakProvider } from './keycloakProvider';\n\nexport interface AuthProviderProps extends KeycloakProviderProps {\n authConfig?: Partial<AuthConfig>;\n}\n\nexport const AuthProvider: FC<AuthProviderProps> = (props: AuthProviderProps) => {\n const { authConfig, debug } = props;\n const authConfigValue = useMemo(\n () => ({\n ...defaultAuthConfig,\n ...authConfig,\n debug: !!debug,\n }),\n [],\n );\n\n return (\n <AuthConfigContext.Provider value={authConfigValue}>\n <KeycloakProvider {...props} />\n </AuthConfigContext.Provider>\n );\n};\n\nexport * from './keycloakProvider';\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAgB,eAAe;AAI/B,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,wBAAwB;AAM1B,MAAM,eAAsC,CAAC,UAA6B;AAC/E,QAAM,EAAE,YAAY,MAAM,IAAI;AAC9B,QAAM,kBAAkB;AAAA,IACtB,OAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG;AAAA,MACH,OAAO,CAAC,CAAC;AAAA,IACX;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SACE,CAAC,kBAAkB,SAAS,OAAO,iBACjC,CAAC,qBAAqB,OAAO,EAC/B,EAFC,kBAAkB;AAIvB;AAEA,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import Keycloak from "keycloak-js";
|
|
2
|
+
import { useMemo, useEffect, useState } from "react";
|
|
3
|
+
import { AfterAuth } from "./afterAuth";
|
|
4
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
5
|
+
import { ReactKeycloakProvider } from "@react-keycloak/web";
|
|
6
|
+
import { SSRKeycloakProvider, SSRCookies } from "@react-keycloak/ssr";
|
|
7
|
+
import { useAuthConfig } from "../hooks/useAuthConfig";
|
|
8
|
+
import { useAuthState } from "../state";
|
|
9
|
+
import { useRouter } from "next/router";
|
|
10
|
+
const logger = console;
|
|
11
|
+
const KeycloakProvider = ({
|
|
12
|
+
children,
|
|
13
|
+
cookies,
|
|
14
|
+
debug,
|
|
15
|
+
keycloakConfig,
|
|
16
|
+
keycloakInitOptions,
|
|
17
|
+
loadingComponent
|
|
18
|
+
}) => {
|
|
19
|
+
const authState = useAuthState();
|
|
20
|
+
const LoadingComponent = loadingComponent || (() => <>{debug ? "authenticating" : null}</>);
|
|
21
|
+
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
22
|
+
const authConfig = useAuthConfig();
|
|
23
|
+
const [token, setToken] = useState(
|
|
24
|
+
"token" in query && (query.token?.toString() || true) || authState.token || false
|
|
25
|
+
);
|
|
26
|
+
const [refreshToken, setRefreshToken] = useState(
|
|
27
|
+
"refreshToken" in query && (query.refreshToken?.toString() || true) || authState.refreshToken || false
|
|
28
|
+
);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (token !== true && refreshToken !== true)
|
|
31
|
+
return;
|
|
32
|
+
if (debug)
|
|
33
|
+
logger.debug("post message", { type: "LOADED" });
|
|
34
|
+
(authConfig.messageHandlerKeys || []).forEach((key) => {
|
|
35
|
+
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
36
|
+
});
|
|
37
|
+
window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
38
|
+
window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (token !== true)
|
|
42
|
+
return;
|
|
43
|
+
const messageCallback = (e) => {
|
|
44
|
+
let data = e?.data;
|
|
45
|
+
if (typeof data === "string") {
|
|
46
|
+
try {
|
|
47
|
+
data = JSON.parse(data);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (debug)
|
|
52
|
+
logger.debug("received message", data);
|
|
53
|
+
const message = data;
|
|
54
|
+
if (!message.type)
|
|
55
|
+
return;
|
|
56
|
+
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
57
|
+
if (debug)
|
|
58
|
+
logger.debug("setting token", message.payload);
|
|
59
|
+
setToken(message.payload);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
if (debug)
|
|
63
|
+
logger.debug("listening for message", {
|
|
64
|
+
type: "TOKEN",
|
|
65
|
+
payload: "<some_token>"
|
|
66
|
+
});
|
|
67
|
+
window.addEventListener("message", messageCallback);
|
|
68
|
+
return () => {
|
|
69
|
+
window.removeEventListener("message", messageCallback);
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (refreshToken !== true)
|
|
74
|
+
return;
|
|
75
|
+
const messageCallback = (e) => {
|
|
76
|
+
let data = e?.data;
|
|
77
|
+
if (typeof data === "string") {
|
|
78
|
+
try {
|
|
79
|
+
data = JSON.parse(data);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (debug)
|
|
84
|
+
logger.debug("received message", data);
|
|
85
|
+
const message = data;
|
|
86
|
+
if (!message.type)
|
|
87
|
+
return;
|
|
88
|
+
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
89
|
+
if (debug)
|
|
90
|
+
logger.debug("setting refresh token", message.payload);
|
|
91
|
+
setRefreshToken(message.payload);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (debug)
|
|
95
|
+
logger.debug("listening for message", {
|
|
96
|
+
type: "REFRESH_TOKEN",
|
|
97
|
+
payload: "<some_refresh_token>"
|
|
98
|
+
});
|
|
99
|
+
window.addEventListener("message", messageCallback);
|
|
100
|
+
return () => {
|
|
101
|
+
window.removeEventListener("message", messageCallback);
|
|
102
|
+
};
|
|
103
|
+
}, []);
|
|
104
|
+
const keycloak = useMemo(
|
|
105
|
+
() => typeof window !== "undefined" && new Keycloak({
|
|
106
|
+
url: keycloakConfig.baseUrl,
|
|
107
|
+
realm: keycloakConfig.realm,
|
|
108
|
+
clientId: keycloakConfig.clientId
|
|
109
|
+
}),
|
|
110
|
+
[]
|
|
111
|
+
);
|
|
112
|
+
const initOptions = useMemo(() => {
|
|
113
|
+
const initOptions2 = {
|
|
114
|
+
...defaultKeycloakInitOptions,
|
|
115
|
+
...keycloakInitOptions
|
|
116
|
+
};
|
|
117
|
+
if (token && typeof token === "string") {
|
|
118
|
+
initOptions2.token = token;
|
|
119
|
+
if (refreshToken && typeof refreshToken === "string")
|
|
120
|
+
initOptions2.refreshToken = refreshToken;
|
|
121
|
+
initOptions2.checkLoginIframe = false;
|
|
122
|
+
initOptions2.onLoad = void 0;
|
|
123
|
+
}
|
|
124
|
+
return initOptions2;
|
|
125
|
+
}, [keycloakInitOptions, token, refreshToken]);
|
|
126
|
+
if (token === true || refreshToken === true)
|
|
127
|
+
return <LoadingComponent />;
|
|
128
|
+
if (cookies && authConfig.ssr) {
|
|
129
|
+
return (
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
<SSRKeycloakProvider
|
|
132
|
+
initOptions={initOptions}
|
|
133
|
+
keycloakConfig={{
|
|
134
|
+
url: keycloakConfig.baseUrl,
|
|
135
|
+
realm: keycloakConfig.realm,
|
|
136
|
+
clientId: keycloakConfig.clientId
|
|
137
|
+
}}
|
|
138
|
+
persistor={SSRCookies(cookies)}
|
|
139
|
+
LoadingComponent={<LoadingComponent />}
|
|
140
|
+
><AfterAuth>{children}</AfterAuth></SSRKeycloakProvider>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (!keycloak)
|
|
144
|
+
return <>{children}</>;
|
|
145
|
+
return <ReactKeycloakProvider initOptions={initOptions} authClient={keycloak} LoadingComponent={<LoadingComponent />}><AfterAuth>{children}</AfterAuth></ReactKeycloakProvider>;
|
|
146
|
+
};
|
|
147
|
+
const defaultKeycloakInitOptions = {
|
|
148
|
+
checkLoginIframe: true,
|
|
149
|
+
checkLoginIframeInterval: 5,
|
|
150
|
+
enableLogging: false,
|
|
151
|
+
onLoad: "check-sso",
|
|
152
|
+
pkceMethod: "S256"
|
|
153
|
+
};
|
|
154
|
+
export {
|
|
155
|
+
KeycloakProvider,
|
|
156
|
+
defaultKeycloakInitOptions
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=keycloakProvider.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/provider/keycloakProvider.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/provider/keycloakProvider.tsx\n * Project: app\n * File Created: 08-11-2022 03:12:43\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:07:46\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Keycloak from 'keycloak-js';\nimport React, { useMemo, useEffect, useState } from 'react';\nimport type { FC, ReactNode, ComponentType } from 'react';\nimport type { KeycloakInitOptions } from 'keycloak-js';\nimport { AfterAuth } from './afterAuth';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { ReactKeycloakProvider } from '@react-keycloak/web';\nimport { SSRKeycloakProvider, SSRCookies } from '@react-keycloak/ssr';\nimport { useAuthConfig } from '../hooks/useAuthConfig';\nimport { useAuthState } from '../state';\nimport { useRouter } from 'next/router';\n\nexport interface KeycloakProviderProps {\n children: ReactNode;\n cookies?: unknown;\n debug?: boolean;\n disabled?: boolean;\n keycloakConfig: KeycloakConfig;\n keycloakInitOptions?: KeycloakInitOptions;\n loadingComponent?: ComponentType;\n}\n\nconst logger = console;\n\nexport const KeycloakProvider: FC<KeycloakProviderProps> = ({\n children,\n cookies,\n debug,\n keycloakConfig,\n keycloakInitOptions,\n loadingComponent,\n}: KeycloakProviderProps) => {\n const authState = useAuthState();\n const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);\n const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };\n const authConfig = useAuthConfig();\n const [token, setToken] = useState<string | boolean>(\n ('token' in query && (query.token?.toString() || true)) || authState.token || false,\n );\n const [refreshToken, setRefreshToken] = useState<string | boolean>(\n ('refreshToken' in query && (query.refreshToken?.toString() || true)) || authState.refreshToken || false,\n );\n\n useEffect(() => {\n if (token !== true && refreshToken !== true) return;\n if (debug) logger.debug('post message', { type: 'LOADED' });\n (authConfig.messageHandlerKeys || []).forEach((key: string) => {\n window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: 'LOADED' }));\n });\n window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: 'LOADED' }));\n window?.parent?.postMessage(JSON.stringify({ type: 'LOADED' }));\n }, []);\n\n useEffect(() => {\n if (token !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === 'string') {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug('received message', data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === 'TOKEN' && message.payload) {\n if (debug) logger.debug('setting token', message.payload);\n setToken(message.payload);\n }\n };\n if (debug)\n logger.debug('listening for message', {\n type: 'TOKEN',\n payload: '<some_token>',\n });\n window.addEventListener('message', messageCallback);\n return () => {\n window.removeEventListener('message', messageCallback);\n };\n }, []);\n\n useEffect(() => {\n if (refreshToken !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data;\n if (typeof data === 'string') {\n try {\n data = JSON.parse(data);\n } catch (err) {}\n }\n if (debug) logger.debug('received message', data);\n const message: MessageSchema = data;\n if (!message.type) return;\n if (message.type.toUpperCase() === 'REFRESH_TOKEN' && message.payload) {\n if (debug) logger.debug('setting refresh token', message.payload);\n setRefreshToken(message.payload);\n }\n };\n if (debug)\n logger.debug('listening for message', {\n type: 'REFRESH_TOKEN',\n payload: '<some_refresh_token>',\n });\n window.addEventListener('message', messageCallback);\n return () => {\n window.removeEventListener('message', messageCallback);\n };\n }, []);\n\n const keycloak = useMemo(\n () =>\n typeof window !== 'undefined' &&\n new Keycloak({\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }),\n [],\n );\n\n const initOptions = useMemo(() => {\n const initOptions = {\n ...defaultKeycloakInitOptions,\n ...keycloakInitOptions,\n };\n if (token && typeof token === 'string') {\n initOptions.token = token;\n if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;\n initOptions.checkLoginIframe = false;\n initOptions.onLoad = undefined;\n }\n return initOptions;\n }, [keycloakInitOptions, token, refreshToken]);\n\n if (token === true || refreshToken === true) return <LoadingComponent />;\n if (cookies && authConfig.ssr) {\n return (\n // @ts-ignore\n <SSRKeycloakProvider\n initOptions={initOptions}\n keycloakConfig={{\n url: keycloakConfig.baseUrl,\n realm: keycloakConfig.realm,\n clientId: keycloakConfig.clientId,\n }}\n persistor={SSRCookies(cookies)}\n LoadingComponent={<LoadingComponent />}\n >\n <AfterAuth>{children}</AfterAuth>\n </SSRKeycloakProvider>\n );\n }\n if (!keycloak) return <>{children}</>;\n return (\n <ReactKeycloakProvider initOptions={initOptions} authClient={keycloak} LoadingComponent={<LoadingComponent />}>\n <AfterAuth>{children}</AfterAuth>\n </ReactKeycloakProvider>\n );\n};\n\nexport interface KeycloakConfig {\n clientId: string;\n realm: string;\n scheme?: string;\n baseUrl: string;\n}\n\nexport const defaultKeycloakInitOptions: KeycloakInitOptions = {\n checkLoginIframe: true,\n checkLoginIframeInterval: 5,\n enableLogging: false,\n onLoad: 'check-sso',\n pkceMethod: 'S256',\n};\n\nexport interface MessageSchema {\n type: string;\n payload?: string;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["initOptions"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AfterAuth } from "./afterAuth";
|
|
2
|
+
import { KeycloakProvider as ExpoKeycloakProvider } from "expo-keycloak-auth";
|
|
3
|
+
const KeycloakProvider = ({ children, keycloakConfig }) => {
|
|
4
|
+
const clonedKeycloakConfig = {
|
|
5
|
+
...keycloakConfig,
|
|
6
|
+
url: keycloakConfig.baseUrl
|
|
7
|
+
};
|
|
8
|
+
delete keycloakConfig.baseUrl;
|
|
9
|
+
return <ExpoKeycloakProvider {...clonedKeycloakConfig}><AfterAuth>{children}</AfterAuth></ExpoKeycloakProvider>;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
KeycloakProvider
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=keycloakProvider.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/provider/keycloakProvider.native.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/provider/keycloakProvider.native.tsx\n * Project: app\n * File Created: 08-11-2022 03:12:37\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 17:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport type { FC } from 'react';\nimport type { KeycloakConfig } from 'keycloak-js';\nimport type { KeycloakProviderProps } from './keycloakProvider';\nimport { AfterAuth } from './afterAuth';\nimport { KeycloakProvider as ExpoKeycloakProvider } from 'expo-keycloak-auth';\n\nexport const KeycloakProvider: FC<KeycloakProviderProps> = ({ children, keycloakConfig }: KeycloakProviderProps) => {\n const clonedKeycloakConfig = {\n ...(keycloakConfig as Omit<KeycloakConfig, 'baseUrl'>),\n url: keycloakConfig.baseUrl,\n };\n // @ts-ignore\n delete keycloakConfig.baseUrl;\n return (\n <ExpoKeycloakProvider {...clonedKeycloakConfig}>\n <AfterAuth>{children}</AfterAuth>\n </ExpoKeycloakProvider>\n );\n};\n"],
|
|
5
|
+
"mappings": "AA4BA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB,4BAA4B;AAElD,MAAM,mBAA8C,CAAC,EAAE,UAAU,eAAe,MAA6B;AAClH,QAAM,uBAAuB;AAAA,IAC3B,GAAI;AAAA,IACJ,KAAK,eAAe;AAAA,EACtB;AAEA,SAAO,eAAe;AACtB,SACE,CAAC,yBAAyB,sBACxB,CAAC,WAAW,SAAS,EAApB,UACH,EAFC;AAIL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStateStore } from "multiplatform.one/zustand";
|
|
2
|
+
const { useStore } = createStateStore(
|
|
3
|
+
"auth",
|
|
4
|
+
{
|
|
5
|
+
token: "",
|
|
6
|
+
refreshToken: ""
|
|
7
|
+
},
|
|
8
|
+
void 0,
|
|
9
|
+
{ persist: true }
|
|
10
|
+
);
|
|
11
|
+
function useAuthState() {
|
|
12
|
+
return useStore();
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
useAuthState
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/state/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/state/index.ts\n * Project: app\n * File Created: 22-11-2022 17:40:53\n * Author: Clay Risser\n * -----\n * Last Modified: 24-02-2023 06:26:51\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 { createStateStore } from 'multiplatform.one/zustand';\n\nconst { useStore } = createStateStore(\n 'auth',\n {\n token: '',\n refreshToken: '',\n },\n undefined,\n { persist: true },\n);\n\nexport function useAuthState() {\n return useStore();\n}\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAS,wBAAwB;AAEjC,MAAM,EAAE,SAAS,IAAI;AAAA,EACnB;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAAA,EACA;AAAA,EACA,EAAE,SAAS,KAAK;AAClB;AAEO,SAAS,eAAe;AAC7B,SAAO,SAAS;AAClB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/types.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 25-11-2022 10:27:53\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:28: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\ndeclare global {\n interface Window {\n ReactNativeWebView: {\n postMessage: (body: string) => unknown;\n };\n webkit: {\n messageHandlers: {\n [key: string]: {\n postMessage: (body: string) => unknown;\n };\n };\n };\n }\n}\n\nexport default null;\n"],
|
|
5
|
+
"mappings": "AAuCA,IAAO,gBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* See the License for the specific language governing permissions and
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
|
-
import { ComponentType, FC, ReactNode } from
|
|
24
|
+
import type { ComponentType, FC, ReactNode } from 'react';
|
|
25
25
|
export interface AuthenticatedProps {
|
|
26
26
|
children: ReactNode;
|
|
27
27
|
disabled?: boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var Authenticated_exports = {};
|
|
34
|
+
__export(Authenticated_exports, {
|
|
35
|
+
Authenticated: () => Authenticated,
|
|
36
|
+
withAuthenticated: () => withAuthenticated
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(Authenticated_exports);
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var import_hooks = require("./hooks");
|
|
41
|
+
const Authenticated = (props) => {
|
|
42
|
+
const { authenticated } = (0, import_hooks.useKeycloak)();
|
|
43
|
+
const login = (0, import_hooks.useLogin)(props.loginRoute);
|
|
44
|
+
if (!props.disabled && !authenticated) {
|
|
45
|
+
if (authenticated === false)
|
|
46
|
+
login();
|
|
47
|
+
const LoggedOutComponent = props.loggedOutComponent || (() => null);
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoggedOutComponent, {});
|
|
49
|
+
}
|
|
50
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children });
|
|
51
|
+
};
|
|
52
|
+
function withAuthenticated(Component) {
|
|
53
|
+
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Authenticated, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, __spreadValues({}, props)) });
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
Authenticated,
|
|
58
|
+
withAuthenticated
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=Authenticated.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Authenticated.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/Authenticated.tsx\n * Project: app\n * File Created: 08-11-2022 05:58:23\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 06:26:38\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport type { ComponentType, FC, ReactNode } from 'react';\nimport { useLogin, useKeycloak } from './hooks';\n\nexport interface AuthenticatedProps {\n children: ReactNode;\n disabled?: boolean;\n loggedOutComponent?: ComponentType;\n loginRoute?: string;\n}\n\nexport const Authenticated: FC<AuthenticatedProps> = (props: AuthenticatedProps) => {\n const { authenticated } = useKeycloak();\n const login = useLogin(props.loginRoute);\n if (!props.disabled && !authenticated) {\n if (authenticated === false) login();\n const LoggedOutComponent = props.loggedOutComponent || (() => null);\n return <LoggedOutComponent />;\n }\n return <>{props.children}</>;\n};\n\nexport function withAuthenticated<P extends object>(Component: ComponentType<P>) {\n return (props: P) => (\n <Authenticated>\n <Component {...props} />\n </Authenticated>\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCW;AAfX,mBAAsC;AAS/B,MAAM,gBAAwC,CAAC,UAA8B;AAClF,QAAM,EAAE,cAAc,QAAI,0BAAY;AACtC,QAAM,YAAQ,uBAAS,MAAM,UAAU;AACvC,MAAI,CAAC,MAAM,YAAY,CAAC,eAAe;AACrC,QAAI,kBAAkB;AAAO,YAAM;AACnC,UAAM,qBAAqB,MAAM,uBAAuB,MAAM;AAC9D,WAAO,4CAAC,sBAAmB;AAAA,EAC7B;AACA,SAAO,2EAAG,gBAAM,UAAS;AAC3B;AAEO,SAAS,kBAAoC,WAA6B;AAC/E,SAAO,CAAC,UACN,4CAAC,iBACC,sDAAC,8BAAc,MAAO,GACxB;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var authConfig_exports = {};
|
|
20
|
+
__export(authConfig_exports, {
|
|
21
|
+
AuthConfigContext: () => AuthConfigContext,
|
|
22
|
+
defaultAuthConfig: () => defaultAuthConfig
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(authConfig_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
const defaultAuthConfig = {
|
|
27
|
+
ssr: true
|
|
28
|
+
};
|
|
29
|
+
const AuthConfigContext = (0, import_react.createContext)(defaultAuthConfig);
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
AuthConfigContext,
|
|
33
|
+
defaultAuthConfig
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=authConfig.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/authConfig.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from 'react';\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,mBAA8B;AAEvB,MAAM,oBAAgC;AAAA,EAC3C,KAAK;AACP;AAEO,MAAM,wBAAoB,4BAA0B,iBAAiB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
* See the License for the specific language governing permissions and
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
|
-
export * from
|
|
25
|
-
export * from
|
|
26
|
-
export * from
|
|
24
|
+
export * from './useCurrentRouteName';
|
|
25
|
+
export * from './useKeycloak';
|
|
26
|
+
export * from './useLogin';
|