@multiplatform.one/keycloak 0.1.10 → 0.2.1
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 +273 -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 +27 -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 +11 -4
- package/dist/lib/hooks/useKeycloak/index.js +23 -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 +29 -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 +62 -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 +25 -0
- package/dist/lib/types.js.map +7 -0
- package/package.json +44 -63
- 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 +12 -8
- 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
|
@@ -22,22 +22,17 @@
|
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import Keycloak
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
ComponentType,
|
|
37
|
-
} from "react";
|
|
38
|
-
import { useAuthConfig } from "../hooks/useAuthConfig";
|
|
39
|
-
import { useAuthState } from "../state";
|
|
40
|
-
import { AfterAuth } from "./afterAuth";
|
|
25
|
+
import Keycloak from 'keycloak-js';
|
|
26
|
+
import React, { useMemo, useEffect, useState } from 'react';
|
|
27
|
+
import type { FC, ReactNode, ComponentType } from 'react';
|
|
28
|
+
import type { KeycloakInitOptions } from 'keycloak-js';
|
|
29
|
+
import { AfterAuth } from './afterAuth';
|
|
30
|
+
import { MultiPlatform } from 'multiplatform.one';
|
|
31
|
+
import { ReactKeycloakProvider } from '@react-keycloak/web';
|
|
32
|
+
import { SSRKeycloakProvider, SSRCookies } from '@react-keycloak/ssr';
|
|
33
|
+
import { useAuthConfig } from '../hooks/useAuthConfig';
|
|
34
|
+
import { useAuthState } from '../state';
|
|
35
|
+
import { useRouter } from 'next/router';
|
|
41
36
|
|
|
42
37
|
export interface KeycloakProviderProps {
|
|
43
38
|
children: ReactNode;
|
|
@@ -59,59 +54,52 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
|
|
|
59
54
|
keycloakInitOptions,
|
|
60
55
|
loadingComponent,
|
|
61
56
|
}: KeycloakProviderProps) => {
|
|
62
|
-
const
|
|
63
|
-
const LoadingComponent =
|
|
64
|
-
loadingComponent || (() => <>{debug ? "authenticating" : null}</>);
|
|
57
|
+
const authState = useAuthState();
|
|
58
|
+
const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);
|
|
65
59
|
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
66
60
|
const authConfig = useAuthConfig();
|
|
67
61
|
const [token, setToken] = useState<string | boolean>(
|
|
68
|
-
(
|
|
69
|
-
auth.token ||
|
|
70
|
-
false
|
|
62
|
+
('token' in query && (query.token?.toString() || true)) || authState.token || false,
|
|
71
63
|
);
|
|
72
64
|
const [refreshToken, setRefreshToken] = useState<string | boolean>(
|
|
73
|
-
(
|
|
74
|
-
auth.refreshToken ||
|
|
75
|
-
false
|
|
65
|
+
('refreshToken' in query && (query.refreshToken?.toString() || true)) || authState.refreshToken || false,
|
|
76
66
|
);
|
|
77
67
|
|
|
78
68
|
useEffect(() => {
|
|
79
69
|
if (token !== true && refreshToken !== true) return;
|
|
80
|
-
if (debug) logger.debug(
|
|
70
|
+
if (debug) logger.debug('post message', { type: 'LOADED' });
|
|
81
71
|
(authConfig.messageHandlerKeys || []).forEach((key: string) => {
|
|
82
|
-
window?.webkit?.messageHandlers?.[key]?.postMessage(
|
|
83
|
-
JSON.stringify({ type: "LOADED" })
|
|
84
|
-
);
|
|
72
|
+
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: 'LOADED' }));
|
|
85
73
|
});
|
|
86
|
-
window?.ReactNativeWebView?.postMessage(JSON.stringify({ type:
|
|
87
|
-
window?.parent?.postMessage(JSON.stringify({ type:
|
|
74
|
+
window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: 'LOADED' }));
|
|
75
|
+
window?.parent?.postMessage(JSON.stringify({ type: 'LOADED' }));
|
|
88
76
|
}, []);
|
|
89
77
|
|
|
90
78
|
useEffect(() => {
|
|
91
79
|
if (token !== true) return;
|
|
92
80
|
const messageCallback = (e: MessageEvent<any>) => {
|
|
93
81
|
let data = e?.data;
|
|
94
|
-
if (typeof data ===
|
|
82
|
+
if (typeof data === 'string') {
|
|
95
83
|
try {
|
|
96
84
|
data = JSON.parse(data);
|
|
97
85
|
} catch (err) {}
|
|
98
86
|
}
|
|
99
|
-
if (debug) logger.debug(
|
|
87
|
+
if (debug) logger.debug('received message', data);
|
|
100
88
|
const message: MessageSchema = data;
|
|
101
89
|
if (!message.type) return;
|
|
102
|
-
if (message.type.toUpperCase() ===
|
|
103
|
-
if (debug) logger.debug(
|
|
90
|
+
if (message.type.toUpperCase() === 'TOKEN' && message.payload) {
|
|
91
|
+
if (debug) logger.debug('setting token', message.payload);
|
|
104
92
|
setToken(message.payload);
|
|
105
93
|
}
|
|
106
94
|
};
|
|
107
95
|
if (debug)
|
|
108
|
-
logger.debug(
|
|
109
|
-
type:
|
|
110
|
-
payload:
|
|
96
|
+
logger.debug('listening for message', {
|
|
97
|
+
type: 'TOKEN',
|
|
98
|
+
payload: '<some_token>',
|
|
111
99
|
});
|
|
112
|
-
window.addEventListener(
|
|
100
|
+
window.addEventListener('message', messageCallback);
|
|
113
101
|
return () => {
|
|
114
|
-
window.removeEventListener(
|
|
102
|
+
window.removeEventListener('message', messageCallback);
|
|
115
103
|
};
|
|
116
104
|
}, []);
|
|
117
105
|
|
|
@@ -119,39 +107,39 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
|
|
|
119
107
|
if (refreshToken !== true) return;
|
|
120
108
|
const messageCallback = (e: MessageEvent<any>) => {
|
|
121
109
|
let data = e?.data;
|
|
122
|
-
if (typeof data ===
|
|
110
|
+
if (typeof data === 'string') {
|
|
123
111
|
try {
|
|
124
112
|
data = JSON.parse(data);
|
|
125
113
|
} catch (err) {}
|
|
126
114
|
}
|
|
127
|
-
if (debug) logger.debug(
|
|
115
|
+
if (debug) logger.debug('received message', data);
|
|
128
116
|
const message: MessageSchema = data;
|
|
129
117
|
if (!message.type) return;
|
|
130
|
-
if (message.type.toUpperCase() ===
|
|
131
|
-
if (debug) logger.debug(
|
|
118
|
+
if (message.type.toUpperCase() === 'REFRESH_TOKEN' && message.payload) {
|
|
119
|
+
if (debug) logger.debug('setting refresh token', message.payload);
|
|
132
120
|
setRefreshToken(message.payload);
|
|
133
121
|
}
|
|
134
122
|
};
|
|
135
123
|
if (debug)
|
|
136
|
-
logger.debug(
|
|
137
|
-
type:
|
|
138
|
-
payload:
|
|
124
|
+
logger.debug('listening for message', {
|
|
125
|
+
type: 'REFRESH_TOKEN',
|
|
126
|
+
payload: '<some_refresh_token>',
|
|
139
127
|
});
|
|
140
|
-
window.addEventListener(
|
|
128
|
+
window.addEventListener('message', messageCallback);
|
|
141
129
|
return () => {
|
|
142
|
-
window.removeEventListener(
|
|
130
|
+
window.removeEventListener('message', messageCallback);
|
|
143
131
|
};
|
|
144
132
|
}, []);
|
|
145
133
|
|
|
146
134
|
const keycloak = useMemo(
|
|
147
135
|
() =>
|
|
148
|
-
typeof window !==
|
|
136
|
+
typeof window !== 'undefined' &&
|
|
149
137
|
new Keycloak({
|
|
150
138
|
url: keycloakConfig.baseUrl,
|
|
151
139
|
realm: keycloakConfig.realm,
|
|
152
140
|
clientId: keycloakConfig.clientId,
|
|
153
141
|
}),
|
|
154
|
-
[]
|
|
142
|
+
[],
|
|
155
143
|
);
|
|
156
144
|
|
|
157
145
|
const initOptions = useMemo(() => {
|
|
@@ -159,10 +147,9 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
|
|
|
159
147
|
...defaultKeycloakInitOptions,
|
|
160
148
|
...keycloakInitOptions,
|
|
161
149
|
};
|
|
162
|
-
if (token && typeof token ===
|
|
150
|
+
if (token && typeof token === 'string') {
|
|
163
151
|
initOptions.token = token;
|
|
164
|
-
if (refreshToken && typeof refreshToken ===
|
|
165
|
-
initOptions.refreshToken = refreshToken;
|
|
152
|
+
if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;
|
|
166
153
|
initOptions.checkLoginIframe = false;
|
|
167
154
|
initOptions.onLoad = undefined;
|
|
168
155
|
}
|
|
@@ -189,11 +176,7 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
|
|
|
189
176
|
}
|
|
190
177
|
if (!keycloak) return <>{children}</>;
|
|
191
178
|
return (
|
|
192
|
-
<ReactKeycloakProvider
|
|
193
|
-
initOptions={initOptions}
|
|
194
|
-
authClient={keycloak}
|
|
195
|
-
LoadingComponent={<LoadingComponent />}
|
|
196
|
-
>
|
|
179
|
+
<ReactKeycloakProvider initOptions={initOptions} authClient={keycloak} LoadingComponent={<LoadingComponent />}>
|
|
197
180
|
<AfterAuth>{children}</AfterAuth>
|
|
198
181
|
</ReactKeycloakProvider>
|
|
199
182
|
);
|
|
@@ -210,8 +193,8 @@ export const defaultKeycloakInitOptions: KeycloakInitOptions = {
|
|
|
210
193
|
checkLoginIframe: true,
|
|
211
194
|
checkLoginIframeInterval: 5,
|
|
212
195
|
enableLogging: false,
|
|
213
|
-
onLoad:
|
|
214
|
-
pkceMethod:
|
|
196
|
+
onLoad: 'check-sso',
|
|
197
|
+
pkceMethod: 'S256',
|
|
215
198
|
};
|
|
216
199
|
|
|
217
200
|
export interface MessageSchema {
|
package/src/state/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* File Created: 22-11-2022 17:40:53
|
|
5
5
|
* Author: Clay Risser
|
|
6
6
|
* -----
|
|
7
|
-
* Last Modified:
|
|
7
|
+
* Last Modified: 24-02-2023 06:26:51
|
|
8
8
|
* Modified By: Clay Risser
|
|
9
9
|
* -----
|
|
10
10
|
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
@@ -22,15 +22,18 @@
|
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import {
|
|
26
|
-
|
|
25
|
+
import { createStateStore } from 'multiplatform.one/zustand';
|
|
26
|
+
|
|
27
|
+
const { useStore } = createStateStore(
|
|
28
|
+
'auth',
|
|
29
|
+
{
|
|
30
|
+
token: '',
|
|
31
|
+
refreshToken: '',
|
|
32
|
+
},
|
|
33
|
+
undefined,
|
|
34
|
+
{ persist: true },
|
|
35
|
+
);
|
|
27
36
|
|
|
28
37
|
export function useAuthState() {
|
|
29
|
-
return
|
|
38
|
+
return useStore();
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
export const authState = atom<{ token?: string; refreshToken?: string }>({
|
|
33
|
-
key: "auth",
|
|
34
|
-
default: {},
|
|
35
|
-
effects: [persistAtom],
|
|
36
|
-
});
|
package/esm/Authenticated.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /auth/Authenticated.tsx
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 05:58:23
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 22-11-2022 06:26:38
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 from "react";
|
|
26
|
-
import { useLogin, useKeycloak } from "./hooks";
|
|
27
|
-
export const Authenticated = props => {
|
|
28
|
-
const {
|
|
29
|
-
authenticated
|
|
30
|
-
} = useKeycloak();
|
|
31
|
-
const login = useLogin(props.loginRoute);
|
|
32
|
-
if (!props.disabled && !authenticated) {
|
|
33
|
-
if (authenticated === false) login();
|
|
34
|
-
const LoggedOutComponent = props.loggedOutComponent || (() => null);
|
|
35
|
-
return /*#__PURE__*/React.createElement(LoggedOutComponent, null);
|
|
36
|
-
}
|
|
37
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
|
|
38
|
-
};
|
|
39
|
-
export function withAuthenticated(Component) {
|
|
40
|
-
return props => /*#__PURE__*/React.createElement(Authenticated, null, /*#__PURE__*/React.createElement(Component, props));
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=Authenticated.js.map
|
package/esm/Authenticated.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Authenticated.js","names":["React","useLogin","useKeycloak","Authenticated","props","authenticated","login","loginRoute","disabled","LoggedOutComponent","loggedOutComponent","children","withAuthenticated","Component"],"sources":["../src/Authenticated.tsx"],"sourcesContent":["/**\n * File: /auth/Authenticated.tsx\n * Project: app\n * File Created: 08-11-2022 05:58:23\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 06:26:38\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, FC, ReactNode } from \"react\";\nimport { useLogin, useKeycloak } from \"./hooks\";\n\nexport interface AuthenticatedProps {\n children: ReactNode;\n disabled?: boolean;\n loggedOutComponent?: ComponentType;\n loginRoute?: string;\n}\n\nexport const Authenticated: FC<AuthenticatedProps> = (\n props: AuthenticatedProps\n) => {\n const { authenticated } = useKeycloak();\n const login = useLogin(props.loginRoute);\n if (!props.disabled && !authenticated) {\n if (authenticated === false) login();\n const LoggedOutComponent = props.loggedOutComponent || (() => null);\n return <LoggedOutComponent />;\n }\n return <>{props.children}</>;\n};\n\nexport function withAuthenticated<P extends object>(\n Component: ComponentType<P>\n) {\n return (props: P) => (\n <Authenticated>\n <Component {...props} />\n </Authenticated>\n );\n}\n"],"mappings":"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,MAAwC,OAAO;AAC3D,SAASC,QAAQ,EAAEC,WAAW;AAS9B,OAAO,MAAMC,aAAqC,GAChDC,KAAyB,IACtB;EACH,MAAM;IAAEC;EAAc,CAAC,GAAGH,WAAW,EAAE;EACvC,MAAMI,KAAK,GAAGL,QAAQ,CAACG,KAAK,CAACG,UAAU,CAAC;EACxC,IAAI,CAACH,KAAK,CAACI,QAAQ,IAAI,CAACH,aAAa,EAAE;IACrC,IAAIA,aAAa,KAAK,KAAK,EAAEC,KAAK,EAAE;IACpC,MAAMG,kBAAkB,GAAGL,KAAK,CAACM,kBAAkB,KAAK,MAAM,IAAI,CAAC;IACnE,oBAAO,oBAAC,kBAAkB,OAAG;EAC/B;EACA,oBAAO,0CAAGN,KAAK,CAACO,QAAQ,CAAI;AAC9B,CAAC;AAED,OAAO,SAASC,iBAAiB,CAC/BC,SAA2B,EAC3B;EACA,OAAQT,KAAQ,iBACd,oBAAC,aAAa,qBACZ,oBAAC,SAAS,EAAKA,KAAK,CAAI,CAE3B;AACH"}
|
package/esm/authConfig.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/authConfig.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 09:21:15
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 25-11-2022 10:29:29
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { createContext } from "react";
|
|
26
|
-
export const defaultAuthConfig = {
|
|
27
|
-
ssr: true
|
|
28
|
-
};
|
|
29
|
-
export const AuthConfigContext = /*#__PURE__*/createContext(defaultAuthConfig);
|
|
30
|
-
//# sourceMappingURL=authConfig.js.map
|
package/esm/authConfig.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authConfig.js","names":["createContext","defaultAuthConfig","ssr","AuthConfigContext"],"sources":["../src/authConfig.ts"],"sourcesContent":["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from \"react\";\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],"mappings":"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,aAAa,QAAQ,OAAO;AAErC,OAAO,MAAMC,iBAA6B,GAAG;EAC3CC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,iBAAiB,gBAAGH,aAAa,CAAaC,iBAAiB,CAAC"}
|
package/esm/hooks/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/hooks/index.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 06:34:56
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 25-11-2022 09:52:31
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 "./useCurrentRouteName";
|
|
26
|
-
export * from "./useKeycloak";
|
|
27
|
-
export * from "./useLogin";
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
package/esm/hooks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/hooks/index.ts"],"sourcesContent":["/**\n * File: /src/hooks/index.ts\n * Project: app\n * File Created: 08-11-2022 06:34:56\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 09:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from \"./useCurrentRouteName\";\nexport * from \"./useKeycloak\";\nexport * from \"./useLogin\";\n"],"mappings":"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,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/hooks/useAuthConfig.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 09:20:41
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 25-11-2022 09:52:31
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 { AuthConfigContext } from "../authConfig";
|
|
27
|
-
export function useAuthConfig() {
|
|
28
|
-
return useContext(AuthConfigContext);
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=useAuthConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthConfig.js","names":["useContext","AuthConfigContext","useAuthConfig"],"sources":["../../src/hooks/useAuthConfig.ts"],"sourcesContent":["/**\n * File: /src/hooks/useAuthConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:20:41\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 09:52:31\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useContext } from \"react\";\nimport { AuthConfigContext } from \"../authConfig\";\n\nexport function useAuthConfig() {\n return useContext(AuthConfigContext);\n}\n"],"mappings":"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,iBAAiB;AAE1B,OAAO,SAASC,aAAa,GAAG;EAC9B,OAAOF,UAAU,CAACC,iBAAiB,CAAC;AACtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentRouteName.js","names":["MultiPlatform","useRoute","useRouter","useCurrentRouteName","isStorybook","isNext","router","route","name"],"sources":["../../src/hooks/useCurrentRouteName.ts"],"sourcesContent":["/**\n * File: /src/hooks/useCurrentRouteName.ts\n * Project: app\n * File Created: 08-11-2022 08:38:23\n * Author: Clay Risser\n * -----\n * Last Modified: 28-01-2023 13:47:18\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 { useRoute } from \"@react-navigation/native\";\nimport { useRouter } from \"next/router\";\n\nexport function useCurrentRouteName() {\n if (MultiPlatform.isStorybook) return null;\n if (MultiPlatform.isNext) {\n const router = useRouter();\n return router.route;\n }\n const route = useRoute();\n return route.name;\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,aAAa,QAAQ,mBAAmB;AACjD,SAASC,QAAQ,QAAQ,0BAA0B;AACnD,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,SAASC,mBAAmB,GAAG;EACpC,IAAIH,aAAa,CAACI,WAAW,EAAE,OAAO,IAAI;EAC1C,IAAIJ,aAAa,CAACK,MAAM,EAAE;IACxB,MAAMC,MAAM,GAAGJ,SAAS,EAAE;IAC1B,OAAOI,MAAM,CAACC,KAAK;EACrB;EACA,MAAMA,KAAK,GAAGN,QAAQ,EAAE;EACxB,OAAOM,KAAK,CAACC,IAAI;AACnB"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/hooks/useKeycloak/index.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 14:10:44
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 28-11-2022 14:56:28
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 "./useKeycloak";
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/useKeycloak/index.ts"],"sourcesContent":["/**\n * File: /src/hooks/useKeycloak/index.ts\n * Project: app\n * File Created: 08-11-2022 14:10:44\n * Author: Clay Risser\n * -----\n * Last Modified: 28-11-2022 14:56:28\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 {\n KeycloakResourceAccess,\n KeycloakRoles,\n KeycloakTokenParsed,\n} from \"keycloak-js\";\nexport * from \"./useKeycloak\";\n\nexport interface IKeycloak {\n authenticated?: boolean;\n realmAccess?: KeycloakRoles;\n refreshToken?: string;\n refreshTokenParsed?: KeycloakTokenParsed;\n resourceAccess?: KeycloakResourceAccess;\n subject?: string;\n token?: string;\n tokenParsed?: KeycloakTokenParsed;\n login: () => Promise<unknown> | unknown;\n logout: () => Promise<unknown> | unknown;\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;;AAOA;AAA8B"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/hooks/useKeycloak/useKeycloak.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 06:04:59
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 28-01-2023 13:48:24
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 { MultiPlatform } from "multiplatform.one";
|
|
26
|
-
import { useKeycloak as useReactKeycloak } from "@react-keycloak/web";
|
|
27
|
-
import { useKeycloak as useSsrKeycloak } from "@react-keycloak/ssr";
|
|
28
|
-
import { useAuthConfig } from "../useAuthConfig";
|
|
29
|
-
export function useKeycloak() {
|
|
30
|
-
const authConfig = useAuthConfig();
|
|
31
|
-
if (MultiPlatform.isStorybook) return {
|
|
32
|
-
authenticated: true
|
|
33
|
-
};
|
|
34
|
-
if (MultiPlatform.isNext && authConfig.ssr) {
|
|
35
|
-
const {
|
|
36
|
-
keycloak: ssrKeycloak,
|
|
37
|
-
initialized
|
|
38
|
-
} = useSsrKeycloak();
|
|
39
|
-
const keycloak = {
|
|
40
|
-
...ssrKeycloak
|
|
41
|
-
};
|
|
42
|
-
if (!initialized) keycloak.authenticated = undefined;
|
|
43
|
-
return keycloak;
|
|
44
|
-
}
|
|
45
|
-
const {
|
|
46
|
-
keycloak: reactKeycloak,
|
|
47
|
-
initialized
|
|
48
|
-
} = useReactKeycloak();
|
|
49
|
-
const keycloak = {
|
|
50
|
-
...reactKeycloak
|
|
51
|
-
};
|
|
52
|
-
if (!initialized) keycloak.authenticated = undefined;
|
|
53
|
-
return keycloak;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=useKeycloak.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useKeycloak.js","names":["MultiPlatform","useKeycloak","useReactKeycloak","useSsrKeycloak","useAuthConfig","authConfig","isStorybook","authenticated","isNext","ssr","keycloak","ssrKeycloak","initialized","undefined","reactKeycloak"],"sources":["../../../src/hooks/useKeycloak/useKeycloak.ts"],"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: 28-01-2023 13:48:24\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 { MultiPlatform } from \"multiplatform.one\";\nimport { useKeycloak as useReactKeycloak } from \"@react-keycloak/web\";\nimport { useKeycloak as useSsrKeycloak } from \"@react-keycloak/ssr\";\nimport { IKeycloak } from \"./index\";\nimport { useAuthConfig } from \"../useAuthConfig\";\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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,aAAa,QAAQ,mBAAmB;AACjD,SAASC,WAAW,IAAIC,gBAAgB,QAAQ,qBAAqB;AACrE,SAASD,WAAW,IAAIE,cAAc,QAAQ,qBAAqB;AAEnE,SAASC,aAAa;AAEtB,OAAO,SAASH,WAAW,GAAG;EAC5B,MAAMI,UAAU,GAAGD,aAAa,EAAE;EAClC,IAAIJ,aAAa,CAACM,WAAW,EAAE,OAAO;IAAEC,aAAa,EAAE;EAAK,CAAC;EAC7D,IAAIP,aAAa,CAACQ,MAAM,IAAIH,UAAU,CAACI,GAAG,EAAE;IAC1C,MAAM;MAAEC,QAAQ,EAAEC,WAAW;MAAEC;IAAY,CAAC,GAAGT,cAAc,EAAE;IAC/D,MAAMO,QAAQ,GAAG;MAAE,GAAGC;IAAY,CAAa;IAC/C,IAAI,CAACC,WAAW,EAAEF,QAAQ,CAACH,aAAa,GAAGM,SAAS;IACpD,OAAOH,QAAQ;EACjB;EACA,MAAM;IAAEA,QAAQ,EAAEI,aAAa;IAAEF;EAAY,CAAC,GAAGV,gBAAgB,EAAE;EACnE,MAAMQ,QAAQ,GAAG;IAAE,GAAGI;EAAc,CAAa;EACjD,IAAI,CAACF,WAAW,EAAEF,QAAQ,CAACH,aAAa,GAAGM,SAAS;EACpD,OAAOH,QAAQ;AACjB"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/hooks/useKeycloak/useKeycloak.native.ts
|
|
3
|
-
* Project: app
|
|
4
|
-
* File Created: 08-11-2022 14:10:25
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* Last Modified: 28-01-2023 13:47:33
|
|
8
|
-
* Modified By: Clay Risser
|
|
9
|
-
* -----
|
|
10
|
-
* Risser Labs LLC (c) Copyright 2021 - 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 atob from "core-js-pure/stable/atob";
|
|
26
|
-
import escape from "core-js-pure/stable/escape";
|
|
27
|
-
import { MultiPlatform } from "multiplatform.one";
|
|
28
|
-
import { useKeycloak as useExpoKeycloak } from "expo-keycloak-auth";
|
|
29
|
-
export function useKeycloak() {
|
|
30
|
-
if (MultiPlatform.isStorybook) return {
|
|
31
|
-
authenticated: true
|
|
32
|
-
};
|
|
33
|
-
const {
|
|
34
|
-
ready,
|
|
35
|
-
login,
|
|
36
|
-
isLoggedIn,
|
|
37
|
-
token,
|
|
38
|
-
logout,
|
|
39
|
-
refreshToken
|
|
40
|
-
} = useExpoKeycloak();
|
|
41
|
-
const keycloak = new ExpoKeycloak(ready, isLoggedIn, login, logout, token || undefined, refreshToken || undefined);
|
|
42
|
-
return keycloak;
|
|
43
|
-
}
|
|
44
|
-
export class ExpoKeycloak {
|
|
45
|
-
constructor(ready, isLoggedIn, login, logout, token, refreshToken) {
|
|
46
|
-
this.logout = logout;
|
|
47
|
-
this.token = token;
|
|
48
|
-
this.refreshToken = refreshToken;
|
|
49
|
-
this.authenticated = void 0;
|
|
50
|
-
this.tokenParsed = void 0;
|
|
51
|
-
this.refreshTokenParsed = void 0;
|
|
52
|
-
this.subject = void 0;
|
|
53
|
-
this.realmAccess = void 0;
|
|
54
|
-
this.resourceAccess = void 0;
|
|
55
|
-
this.login = void 0;
|
|
56
|
-
if (ready) this.authenticated = isLoggedIn;
|
|
57
|
-
if (this.authenticated) {
|
|
58
|
-
if (this.token) this.tokenParsed = decodeToken(this.token);
|
|
59
|
-
if (this.refreshToken) {
|
|
60
|
-
this.refreshTokenParsed = decodeToken(this.refreshToken);
|
|
61
|
-
}
|
|
62
|
-
if (this.tokenParsed) {
|
|
63
|
-
this.subject = this.tokenParsed.sub;
|
|
64
|
-
this.realmAccess = this.tokenParsed.realm_access;
|
|
65
|
-
this.resourceAccess = this.tokenParsed.resource_access;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this.login = () => login();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function decodeToken(str) {
|
|
72
|
-
str = str.split(".")[1];
|
|
73
|
-
str = str.replace(/-/g, "+");
|
|
74
|
-
str = str.replace(/_/g, "/");
|
|
75
|
-
switch (str.length % 4) {
|
|
76
|
-
case 0:
|
|
77
|
-
break;
|
|
78
|
-
case 2:
|
|
79
|
-
str += "==";
|
|
80
|
-
break;
|
|
81
|
-
case 3:
|
|
82
|
-
str += "=";
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
throw "Invalid token";
|
|
86
|
-
}
|
|
87
|
-
str = decodeURIComponent(escape(atob(str)));
|
|
88
|
-
str = JSON.parse(str);
|
|
89
|
-
return str;
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=useKeycloak.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useKeycloak.native.js","names":["atob","escape","MultiPlatform","useKeycloak","useExpoKeycloak","isStorybook","authenticated","ready","login","isLoggedIn","token","logout","refreshToken","keycloak","ExpoKeycloak","undefined","constructor","tokenParsed","refreshTokenParsed","subject","realmAccess","resourceAccess","decodeToken","sub","realm_access","resource_access","str","split","replace","length","decodeURIComponent","JSON","parse"],"sources":["../../../src/hooks/useKeycloak/useKeycloak.native.ts"],"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: 28-01-2023 13:47:33\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 { AuthRequestPromptOptions, AuthSessionResult } from \"expo-auth-session\";\nimport { MultiPlatform } from \"multiplatform.one\";\nimport {\n KeycloakResourceAccess,\n KeycloakRoles,\n KeycloakTokenParsed,\n} from \"keycloak-js\";\nimport { useKeycloak as useExpoKeycloak } from \"expo-keycloak-auth\";\nimport { IKeycloak } from \"./index\";\n\nexport function useKeycloak() {\n if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;\n const { ready, login, isLoggedIn, token, logout, refreshToken } =\n useExpoKeycloak();\n const keycloak = new ExpoKeycloak(\n ready,\n isLoggedIn,\n login,\n logout,\n token || undefined,\n refreshToken || undefined\n );\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: (\n options?: AuthRequestPromptOptions\n ) => 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"],"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,IAAI,MAAM,0BAA0B;AAC3C,OAAOC,MAAM,MAAM,4BAA4B;AAE/C,SAASC,aAAa,QAAQ,mBAAmB;AAMjD,SAASC,WAAW,IAAIC,eAAe,QAAQ,oBAAoB;AAGnE,OAAO,SAASD,WAAW,GAAG;EAC5B,IAAID,aAAa,CAACG,WAAW,EAAE,OAAO;IAAEC,aAAa,EAAE;EAAK,CAAC;EAC7D,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,UAAU;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAa,CAAC,GAC7DR,eAAe,EAAE;EACnB,MAAMS,QAAQ,GAAG,IAAIC,YAAY,CAC/BP,KAAK,EACLE,UAAU,EACVD,KAAK,EACLG,MAAM,EACND,KAAK,IAAIK,SAAS,EAClBH,YAAY,IAAIG,SAAS,CAC1B;EACD,OAAOF,QAAQ;AACjB;AAEA,OAAO,MAAMC,YAAY,CAAsB;EAe7CE,WAAW,CACTT,KAAc,EACdE,UAA+B,EAC/BD,KAE2C,EACpCG,MAAqB,EACrBD,KAAc,EACdE,YAAqB,EAC5B;IAAA,KAHOD,MAAqB,GAArBA,MAAqB;IAAA,KACrBD,KAAc,GAAdA,KAAc;IAAA,KACdE,YAAqB,GAArBA,YAAqB;IAAA,KAtB9BN,aAAa;IAAA,KAEbW,WAAW;IAAA,KAEXC,kBAAkB;IAAA,KAElBC,OAAO;IAAA,KAEPC,WAAW;IAAA,KAEXC,cAAc;IAAA,KAEdb,KAAK;IAYH,IAAID,KAAK,EAAE,IAAI,CAACD,aAAa,GAAGG,UAAU;IAC1C,IAAI,IAAI,CAACH,aAAa,EAAE;MACtB,IAAI,IAAI,CAACI,KAAK,EAAE,IAAI,CAACO,WAAW,GAAGK,WAAW,CAAC,IAAI,CAACZ,KAAK,CAAC;MAC1D,IAAI,IAAI,CAACE,YAAY,EAAE;QACrB,IAAI,CAACM,kBAAkB,GAAGI,WAAW,CAAC,IAAI,CAACV,YAAY,CAAC;MAC1D;MACA,IAAI,IAAI,CAACK,WAAW,EAAE;QACpB,IAAI,CAACE,OAAO,GAAG,IAAI,CAACF,WAAW,CAACM,GAAG;QACnC,IAAI,CAACH,WAAW,GAAG,IAAI,CAACH,WAAW,CAACO,YAAY;QAChD,IAAI,CAACH,cAAc,GAAG,IAAI,CAACJ,WAAW,CAACQ,eAAe;MACxD;IACF;IACA,IAAI,CAACjB,KAAK,GAAG,MAAMA,KAAK,EAAE;EAC5B;AACF;AAEA,SAASc,WAAW,CAACI,GAAW,EAAE;EAChCA,GAAG,GAAGA,GAAG,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACvBD,GAAG,GAAGA,GAAG,CAACE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;EAC5BF,GAAG,GAAGA,GAAG,CAACE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;EAC5B,QAAQF,GAAG,CAACG,MAAM,GAAG,CAAC;IACpB,KAAK,CAAC;MACJ;IACF,KAAK,CAAC;MACJH,GAAG,IAAI,IAAI;MACX;IACF,KAAK,CAAC;MACJA,GAAG,IAAI,GAAG;MACV;IACF;MACE,MAAM,eAAe;EAAC;EAE1BA,GAAG,GAAGI,kBAAkB,CAAC7B,MAAM,CAACD,IAAI,CAAC0B,GAAG,CAAC,CAAC,CAAC;EAC3CA,GAAG,GAAGK,IAAI,CAACC,KAAK,CAACN,GAAG,CAAC;EACrB,OAAOA,GAAG;AACZ"}
|