@multiplatform.one/keycloak 0.3.1 → 0.3.4
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/hooks/index.mjs +1 -0
- package/dist/esm/hooks/index.mjs.map +2 -2
- package/dist/esm/hooks/useIsPassedInToken/index.mjs +12 -0
- package/dist/esm/hooks/useIsPassedInToken/index.mjs.map +7 -0
- package/dist/esm/hooks/useIsPassedInToken/index.native.mjs +7 -0
- package/dist/esm/hooks/useIsPassedInToken/index.native.mjs.map +7 -0
- package/dist/esm/provider/index.mjs +3 -1
- package/dist/esm/provider/index.mjs.map +2 -2
- package/dist/esm/provider/keycloakProvider.mjs +39 -37
- package/dist/esm/provider/keycloakProvider.mjs.map +2 -2
- package/dist/jsx/hooks/index.mjs +1 -0
- package/dist/jsx/hooks/index.mjs.map +2 -2
- package/dist/jsx/hooks/useIsPassedInToken/index.mjs +10 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.mjs.map +7 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.native.mjs +5 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.native.mjs.map +7 -0
- package/dist/jsx/provider/index.mjs +3 -1
- package/dist/jsx/provider/index.mjs.map +2 -2
- package/dist/jsx/provider/keycloakProvider.mjs +48 -38
- package/dist/jsx/provider/keycloakProvider.mjs.map +2 -2
- package/dist/lib/hooks/index.d.ts +2 -1
- package/dist/lib/hooks/index.js +2 -0
- package/dist/lib/hooks/index.js.map +2 -2
- package/dist/lib/hooks/useIsPassedInToken/index.d.ts +24 -0
- package/dist/lib/hooks/useIsPassedInToken/index.js +34 -0
- package/dist/lib/hooks/useIsPassedInToken/index.js.map +7 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.d.ts +24 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.js +29 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.js.map +7 -0
- package/dist/lib/provider/index.js +3 -1
- package/dist/lib/provider/index.js.map +2 -2
- package/dist/lib/provider/keycloakProvider.d.ts +0 -1
- package/dist/lib/provider/keycloakProvider.js +49 -40
- package/dist/lib/provider/keycloakProvider.js.map +2 -2
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useIsPassedInToken/index.native.ts +25 -0
- package/src/hooks/useIsPassedInToken/index.ts +31 -0
- package/src/provider/index.tsx +3 -1
- package/src/provider/keycloakProvider.tsx +50 -37
|
@@ -6,6 +6,7 @@ import { ReactKeycloakProvider } from "@bitspur/react-keycloak-web";
|
|
|
6
6
|
import { SSRKeycloakProvider, SSRCookies } from "@bitspur/react-keycloak-ssr";
|
|
7
7
|
import { useAuthConfig } from "../hooks/useAuthConfig";
|
|
8
8
|
import { useAuthState } from "../state";
|
|
9
|
+
import { useIsPassedInToken } from "../hooks";
|
|
9
10
|
import { useRouter } from "next/router";
|
|
10
11
|
const logger = console;
|
|
11
12
|
function KeycloakProvider({
|
|
@@ -21,16 +22,24 @@ function KeycloakProvider({
|
|
|
21
22
|
const authState = useAuthState();
|
|
22
23
|
const LoadingComponent = loadingComponent || (() => <>{debug ? "authenticating" : null}</>);
|
|
23
24
|
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
25
|
+
const [refreshToken, setRefreshToken] = useState(
|
|
26
|
+
validToken(
|
|
27
|
+
ensureFreshness && ("refreshToken" in query && (query.refreshToken?.toString() || true) || persist && authState.refreshToken) || false
|
|
28
|
+
)
|
|
29
|
+
);
|
|
24
30
|
const [idToken, setIdToken] = useState(
|
|
25
|
-
|
|
31
|
+
validToken(
|
|
32
|
+
"idToken" in query && (query.idToken?.toString() || true) || persist && authState.idToken || false,
|
|
33
|
+
refreshToken
|
|
34
|
+
)
|
|
26
35
|
);
|
|
27
36
|
const [token, setToken] = useState(
|
|
28
|
-
|
|
37
|
+
validToken(
|
|
38
|
+
"token" in query && (query.token?.toString() || true) || persist && authState.token || false,
|
|
39
|
+
refreshToken
|
|
40
|
+
)
|
|
29
41
|
);
|
|
30
|
-
const
|
|
31
|
-
ensureFreshness && ("refreshToken" in query && (query.refreshToken?.toString() || true) || persist && authState.refreshToken) || false
|
|
32
|
-
);
|
|
33
|
-
const explicitToken = "idToken" in query || "token" in query || "refreshToken" in query;
|
|
42
|
+
const isPassedInToken = useIsPassedInToken();
|
|
34
43
|
useEffect(() => {
|
|
35
44
|
if (token !== true && refreshToken !== true && idToken !== true)
|
|
36
45
|
return;
|
|
@@ -43,18 +52,10 @@ function KeycloakProvider({
|
|
|
43
52
|
window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
44
53
|
}, []);
|
|
45
54
|
useEffect(() => {
|
|
46
|
-
if (
|
|
47
|
-
setIdToken(false);
|
|
48
|
-
if (typeof refreshToken === "string" && !isTokenValid(refreshToken))
|
|
49
|
-
setRefreshToken(false);
|
|
50
|
-
if (typeof token === "string" && !isTokenValid(token))
|
|
51
|
-
setToken(false);
|
|
52
|
-
}, [idToken, token, refreshToken]);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (token !== true)
|
|
55
|
+
if (refreshToken !== true)
|
|
55
56
|
return;
|
|
56
57
|
const messageCallback = (e) => {
|
|
57
|
-
let data = e?.data;
|
|
58
|
+
let data = e?.data || null;
|
|
58
59
|
if (typeof data === "string") {
|
|
59
60
|
try {
|
|
60
61
|
data = JSON.parse(data);
|
|
@@ -66,16 +67,16 @@ function KeycloakProvider({
|
|
|
66
67
|
const message = data;
|
|
67
68
|
if (!message.type)
|
|
68
69
|
return;
|
|
69
|
-
if (message.type.toUpperCase() === "
|
|
70
|
+
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
70
71
|
if (debug)
|
|
71
|
-
logger.debug("setting token", message.payload);
|
|
72
|
-
|
|
72
|
+
logger.debug("setting refresh token", message.payload);
|
|
73
|
+
setRefreshToken(validToken(message.payload));
|
|
73
74
|
}
|
|
74
75
|
};
|
|
75
76
|
if (debug) {
|
|
76
77
|
logger.debug("listening for message", {
|
|
77
|
-
type: "
|
|
78
|
-
payload: "<
|
|
78
|
+
type: "REFRESH_TOKEN",
|
|
79
|
+
payload: "<some_refresh_token>"
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
window.addEventListener("message", messageCallback);
|
|
@@ -84,10 +85,10 @@ function KeycloakProvider({
|
|
|
84
85
|
};
|
|
85
86
|
}, []);
|
|
86
87
|
useEffect(() => {
|
|
87
|
-
if (
|
|
88
|
+
if (token !== true)
|
|
88
89
|
return;
|
|
89
90
|
const messageCallback = (e) => {
|
|
90
|
-
let data = e?.data;
|
|
91
|
+
let data = e?.data || null;
|
|
91
92
|
if (typeof data === "string") {
|
|
92
93
|
try {
|
|
93
94
|
data = JSON.parse(data);
|
|
@@ -99,16 +100,16 @@ function KeycloakProvider({
|
|
|
99
100
|
const message = data;
|
|
100
101
|
if (!message.type)
|
|
101
102
|
return;
|
|
102
|
-
if (message.type.toUpperCase() === "
|
|
103
|
+
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
103
104
|
if (debug)
|
|
104
|
-
logger.debug("setting
|
|
105
|
-
|
|
105
|
+
logger.debug("setting token", message.payload);
|
|
106
|
+
setToken(validToken(message.payload, refreshToken));
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
if (debug) {
|
|
109
110
|
logger.debug("listening for message", {
|
|
110
|
-
type: "
|
|
111
|
-
payload: "<
|
|
111
|
+
type: "TOKEN",
|
|
112
|
+
payload: "<some_token>"
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
window.addEventListener("message", messageCallback);
|
|
@@ -117,10 +118,10 @@ function KeycloakProvider({
|
|
|
117
118
|
};
|
|
118
119
|
}, []);
|
|
119
120
|
useEffect(() => {
|
|
120
|
-
if (
|
|
121
|
+
if (idToken !== true)
|
|
121
122
|
return;
|
|
122
123
|
const messageCallback = (e) => {
|
|
123
|
-
let data = e?.data;
|
|
124
|
+
let data = e?.data || null;
|
|
124
125
|
if (typeof data === "string") {
|
|
125
126
|
try {
|
|
126
127
|
data = JSON.parse(data);
|
|
@@ -132,16 +133,16 @@ function KeycloakProvider({
|
|
|
132
133
|
const message = data;
|
|
133
134
|
if (!message.type)
|
|
134
135
|
return;
|
|
135
|
-
if (message.type.toUpperCase() === "
|
|
136
|
+
if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
|
|
136
137
|
if (debug)
|
|
137
|
-
logger.debug("setting
|
|
138
|
-
|
|
138
|
+
logger.debug("setting id token", message.payload);
|
|
139
|
+
setIdToken(validToken(message.payload, refreshToken));
|
|
139
140
|
}
|
|
140
141
|
};
|
|
141
142
|
if (debug) {
|
|
142
143
|
logger.debug("listening for message", {
|
|
143
|
-
type: "
|
|
144
|
-
payload: "<
|
|
144
|
+
type: "ID_TOKEN",
|
|
145
|
+
payload: "<some_id_token>"
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
148
|
window.addEventListener("message", messageCallback);
|
|
@@ -181,7 +182,7 @@ function KeycloakProvider({
|
|
|
181
182
|
initOptions2.idToken = idToken;
|
|
182
183
|
if (refreshToken && typeof refreshToken === "string")
|
|
183
184
|
initOptions2.refreshToken = refreshToken;
|
|
184
|
-
if (
|
|
185
|
+
if (isPassedInToken) {
|
|
185
186
|
initOptions2.checkLoginIframe = false;
|
|
186
187
|
initOptions2.onLoad = void 0;
|
|
187
188
|
}
|
|
@@ -219,6 +220,16 @@ function KeycloakProvider({
|
|
|
219
220
|
onTokens={onTokens}
|
|
220
221
|
><AfterAuth>{children}</AfterAuth></ReactKeycloakProvider>;
|
|
221
222
|
}
|
|
223
|
+
function validToken(token, refreshToken) {
|
|
224
|
+
if (typeof token !== "string")
|
|
225
|
+
return token;
|
|
226
|
+
if (refreshToken) {
|
|
227
|
+
if (refreshToken === true || isTokenValid(refreshToken))
|
|
228
|
+
return token;
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return isTokenValid(token) ? token : false;
|
|
232
|
+
}
|
|
222
233
|
function isTokenValid(token) {
|
|
223
234
|
try {
|
|
224
235
|
const { exp } = JSON.parse(Buffer.from(token.split(".")?.[1] || "", "base64").toString() || "{}");
|
|
@@ -238,7 +249,6 @@ const defaultKeycloakInitOptions = {
|
|
|
238
249
|
};
|
|
239
250
|
export {
|
|
240
251
|
KeycloakProvider,
|
|
241
|
-
defaultKeycloakInitOptions
|
|
242
|
-
isTokenValid
|
|
252
|
+
defaultKeycloakInitOptions
|
|
243
253
|
};
|
|
244
254
|
//# sourceMappingURL=keycloakProvider.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 '@bitspur/keycloak-js';\nimport React, { useMemo, useEffect, useState, useCallback } from 'react';\nimport type { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';\nimport type { KeycloakInitOptions, KeycloakConfig } from '@bitspur/keycloak-js';\nimport type { ReactNode, ComponentType } from 'react';\nimport { AfterAuth } from './afterAuth';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { ReactKeycloakProvider } from '@bitspur/react-keycloak-web';\nimport { SSRKeycloakProvider, SSRCookies } from '@bitspur/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 keycloakConfig: KeycloakConfig;\n keycloakInitOptions?: KeycloakInitOptions;\n loadingComponent?: ComponentType;\n onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;\n onTokens?: (tokens: AuthClientTokens) => void;\n}\n\nconst logger = console;\n\nexport function KeycloakProvider({\n children,\n cookies,\n keycloakConfig,\n keycloakInitOptions,\n loadingComponent,\n onEvent,\n onTokens,\n}: KeycloakProviderProps) {\n const { debug, ensureFreshness, persist, messageHandlerKeys, ssr } = useAuthConfig();\n const authState = useAuthState();\n const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);\n const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };\n const [
|
|
5
|
-
"mappings": "AAwBA,OAAO,cAAc;AACrB,SAAgB,SAAS,WAAW,UAAU,mBAAmB;AAIjE,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,qBAAqB,kBAAkB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAY1B,MAAM,SAAS;AAER,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,QAAM,EAAE,OAAO,iBAAiB,SAAS,oBAAoB,IAAI,IAAI,cAAc;AACnF,QAAM,YAAY,aAAa;AAC/B,QAAM,mBAAmB,qBAAqB,MAAM,GAAG,QAAQ,mBAAmB,KAAK;AACvF,QAAM,EAAE,MAAM,IAAI,cAAc,SAAS,UAAU,IAAI,EAAE,OAAO,CAAC,EAAE;AACnE,QAAM,CAAC,
|
|
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 '@bitspur/keycloak-js';\nimport React, { useMemo, useEffect, useState, useCallback } from 'react';\nimport type { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';\nimport type { KeycloakInitOptions, KeycloakConfig } from '@bitspur/keycloak-js';\nimport type { ReactNode, ComponentType } from 'react';\nimport { AfterAuth } from './afterAuth';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { ReactKeycloakProvider } from '@bitspur/react-keycloak-web';\nimport { SSRKeycloakProvider, SSRCookies } from '@bitspur/react-keycloak-ssr';\nimport { useAuthConfig } from '../hooks/useAuthConfig';\nimport { useAuthState } from '../state';\nimport { useIsPassedInToken } from '../hooks';\nimport { useRouter } from 'next/router';\n\nexport interface KeycloakProviderProps {\n children: ReactNode;\n cookies?: unknown;\n keycloakConfig: KeycloakConfig;\n keycloakInitOptions?: KeycloakInitOptions;\n loadingComponent?: ComponentType;\n onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;\n onTokens?: (tokens: AuthClientTokens) => void;\n}\n\nconst logger = console;\n\nexport function KeycloakProvider({\n children,\n cookies,\n keycloakConfig,\n keycloakInitOptions,\n loadingComponent,\n onEvent,\n onTokens,\n}: KeycloakProviderProps) {\n const { debug, ensureFreshness, persist, messageHandlerKeys, ssr } = useAuthConfig();\n const authState = useAuthState();\n const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);\n const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };\n const [refreshToken, setRefreshToken] = useState<string | boolean>(\n validToken(\n (ensureFreshness &&\n (('refreshToken' in query && (query.refreshToken?.toString() || true)) ||\n (persist && authState.refreshToken))) ||\n false,\n ),\n );\n const [idToken, setIdToken] = useState<string | boolean>(\n validToken(\n ('idToken' in query && (query.idToken?.toString() || true)) || (persist && authState.idToken) || false,\n refreshToken,\n ),\n );\n const [token, setToken] = useState<string | boolean>(\n validToken(\n ('token' in query && (query.token?.toString() || true)) || (persist && authState.token) || false,\n refreshToken,\n ),\n );\n const isPassedInToken = useIsPassedInToken();\n\n useEffect(() => {\n if (token !== true && refreshToken !== true && idToken !== true) return;\n if (debug) logger.debug('post message', { type: 'LOADED' });\n (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 (refreshToken !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data || null;\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(validToken(message.payload));\n }\n };\n if (debug) {\n logger.debug('listening for message', {\n type: 'REFRESH_TOKEN',\n payload: '<some_refresh_token>',\n });\n }\n window.addEventListener('message', messageCallback);\n return () => {\n window.removeEventListener('message', messageCallback);\n };\n }, []);\n\n useEffect(() => {\n if (token !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data || null;\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(validToken(message.payload, refreshToken));\n }\n };\n if (debug) {\n logger.debug('listening for message', {\n type: 'TOKEN',\n payload: '<some_token>',\n });\n }\n window.addEventListener('message', messageCallback);\n return () => {\n window.removeEventListener('message', messageCallback);\n };\n }, []);\n\n useEffect(() => {\n if (idToken !== true) return;\n const messageCallback = (e: MessageEvent<any>) => {\n let data = e?.data || null;\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() === 'ID_TOKEN' && message.payload) {\n if (debug) logger.debug('setting id token', message.payload);\n setIdToken(validToken(message.payload, refreshToken));\n }\n };\n if (debug) {\n logger.debug('listening for message', {\n type: 'ID_TOKEN',\n payload: '<some_id_token>',\n });\n }\n window.addEventListener('message', messageCallback);\n return () => {\n window.removeEventListener('message', messageCallback);\n };\n }, []);\n\n const handleEvent = useCallback((eventType: AuthClientEvent, error?: AuthClientError) => {\n if (error) {\n if (typeof error === 'string') throw new Error(error);\n const err: Error & { errorDescription?: string } = new Error(error.error);\n err.errorDescription = error.error_description;\n throw err;\n }\n if (onEvent) onEvent(eventType, error);\n }, []);\n\n const keycloak = useMemo(\n () =>\n typeof window !== 'undefined' &&\n new Keycloak({\n url: keycloakConfig.url,\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 (debug) initOptions.enableLogging = true;\n if (token && typeof token === 'string') {\n initOptions.token = token;\n if (idToken && typeof idToken === 'string') initOptions.idToken = idToken;\n if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;\n if (isPassedInToken) {\n initOptions.checkLoginIframe = false;\n initOptions.onLoad = undefined;\n }\n }\n return initOptions;\n }, [keycloakInitOptions, token, refreshToken, idToken]);\n\n if (token === true || idToken === true || refreshToken === true) return <LoadingComponent />;\n if (cookies && ssr) {\n return (\n // @ts-ignore\n <SSRKeycloakProvider\n LoadingComponent={<LoadingComponent />}\n // keycloak-js already handles refreshing tokens\n autoRefreshToken={false}\n initOptions={initOptions}\n onEvent={handleEvent}\n onTokens={onTokens}\n persistor={SSRCookies(cookies)}\n keycloakConfig={{\n clientId: keycloakConfig.clientId,\n realm: keycloakConfig.realm,\n url: keycloakConfig.url,\n }}\n >\n <AfterAuth>{children}</AfterAuth>\n </SSRKeycloakProvider>\n );\n }\n if (!keycloak) return <>{children}</>;\n return (\n <ReactKeycloakProvider\n LoadingComponent={<LoadingComponent />}\n authClient={keycloak}\n // keycloak-js already handles refreshing tokens\n autoRefreshToken={false}\n initOptions={initOptions}\n onEvent={handleEvent}\n onTokens={onTokens}\n >\n <AfterAuth>{children}</AfterAuth>\n </ReactKeycloakProvider>\n );\n}\n\nfunction validToken(token: string | boolean, refreshToken?: string | boolean) {\n if (typeof token !== 'string') return token;\n if (refreshToken) {\n if (refreshToken === true || isTokenValid(refreshToken)) return token;\n return false;\n }\n return isTokenValid(token) ? token : false;\n}\n\nfunction isTokenValid(token: string) {\n try {\n const { exp } = JSON.parse(Buffer.from(token.split('.')?.[1] || '', 'base64').toString() || '{}');\n return Math.floor(Date.now() / 1000) <= exp;\n } catch (err) {\n if (err instanceof SyntaxError) return false;\n throw err;\n }\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": "AAwBA,OAAO,cAAc;AACrB,SAAgB,SAAS,WAAW,UAAU,mBAAmB;AAIjE,SAAS,iBAAiB;AAC1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K,eAAe;AAAA,QACtB;AAAA,OAEA,CAAC,WAAW,SAAS,EAApB,UACH,EAfC;AAAA;AAAA,EAiBL;AACA,MAAI,CAAC;AAAU,WAAO,GAAG,SAAS;AAClC,SACE,CAAC;AAAA,IACC,kBAAkB,CAAC,iBAAiB;AAAA,IACpC,YAAY;AAAA,IAEZ,kBAAkB;AAAA,IAClB,aAAa;AAAA,IACb,SAAS;AAAA,IACT,UAAU;AAAA,GAEV,CAAC,WAAW,SAAS,EAApB,UACH,EAVC;AAYL;AAEA,SAAS,WAAW,OAAyB,cAAiC;AAC5E,MAAI,OAAO,UAAU;AAAU,WAAO;AACtC,MAAI,cAAc;AAChB,QAAI,iBAAiB,QAAQ,aAAa,YAAY;AAAG,aAAO;AAChE,WAAO;AAAA,EACT;AACA,SAAO,aAAa,KAAK,IAAI,QAAQ;AACvC;AAEA,SAAS,aAAa,OAAe;AACnC,MAAI;AACF,UAAM,EAAE,IAAI,IAAI,KAAK,MAAM,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,QAAQ,EAAE,SAAS,KAAK,IAAI;AAChG,WAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,KAAK;AAAA,EAC1C,SAAS,KAAP;AACA,QAAI,eAAe;AAAa,aAAO;AACvC,UAAM;AAAA,EACR;AACF;AAEO,MAAM,6BAAkD;AAAA,EAC7D,kBAAkB;AAAA,EAClB,0BAA0B;AAAA,EAC1B,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,YAAY;AACd;",
|
|
6
6
|
"names": ["initOptions"]
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* File Created: 08-11-2022 06:34:56
|
|
5
5
|
* Author: Clay Risser
|
|
6
6
|
* -----
|
|
7
|
-
* Last Modified:
|
|
7
|
+
* Last Modified: 15-05-2023 01:58:05
|
|
8
8
|
* Modified By: Clay Risser
|
|
9
9
|
* -----
|
|
10
10
|
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
@@ -22,5 +22,6 @@
|
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
24
|
export * from './useCurrentRouteName';
|
|
25
|
+
export * from './useIsPassedInToken';
|
|
25
26
|
export * from './useKeycloak';
|
|
26
27
|
export * from './useLogin';
|
package/dist/lib/hooks/index.js
CHANGED
|
@@ -16,11 +16,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var hooks_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(hooks_exports);
|
|
18
18
|
__reExport(hooks_exports, require("./useCurrentRouteName"), module.exports);
|
|
19
|
+
__reExport(hooks_exports, require("./useIsPassedInToken"), module.exports);
|
|
19
20
|
__reExport(hooks_exports, require("./useKeycloak"), module.exports);
|
|
20
21
|
__reExport(hooks_exports, require("./useLogin"), module.exports);
|
|
21
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
23
|
0 && (module.exports = {
|
|
23
24
|
...require("./useCurrentRouteName"),
|
|
25
|
+
...require("./useIsPassedInToken"),
|
|
24
26
|
...require("./useKeycloak"),
|
|
25
27
|
...require("./useLogin")
|
|
26
28
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/index.ts"],
|
|
4
|
-
"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:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAwBA,0BAAc,kCAxBd;AAyBA,0BAAc,
|
|
4
|
+
"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: 15-05-2023 01:58:05\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 './useIsPassedInToken';\nexport * from './useKeycloak';\nexport * from './useLogin';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAwBA,0BAAc,kCAxBd;AAyBA,0BAAc,iCAzBd;AA0BA,0BAAc,0BA1Bd;AA2BA,0BAAc,uBA3Bd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useIsPassedInToken/index.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 15-05-2023 01:54:44
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 15-05-2023 01:56:30
|
|
8
|
+
* Modified By: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Risser Labs LLC (c) Copyright 2022 - 2023
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useIsPassedInToken(): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 useIsPassedInToken_exports = {};
|
|
20
|
+
__export(useIsPassedInToken_exports, {
|
|
21
|
+
useIsPassedInToken: () => useIsPassedInToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useIsPassedInToken_exports);
|
|
24
|
+
var import_multiplatform = require("multiplatform.one");
|
|
25
|
+
var import_router = require("next/router");
|
|
26
|
+
function useIsPassedInToken() {
|
|
27
|
+
const { query } = import_multiplatform.MultiPlatform.isNext ? (0, import_router.useRouter)() : { query: {} };
|
|
28
|
+
return "idToken" in query || "token" in query || "refreshToken" in query;
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
useIsPassedInToken
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useIsPassedInToken/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useIsPassedInToken/index.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 15-05-2023 01:54:44\n * Author: Clay Risser\n * -----\n * Last Modified: 15-05-2023 01:56:30\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022 - 2023\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 { useRouter } from 'next/router';\n\nexport function useIsPassedInToken() {\n const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };\n return 'idToken' in query || 'token' in query || 'refreshToken' in query;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,2BAA8B;AAC9B,oBAA0B;AAEnB,SAAS,qBAAqB;AACnC,QAAM,EAAE,MAAM,IAAI,mCAAc,aAAS,yBAAU,IAAI,EAAE,OAAO,CAAC,EAAE;AACnE,SAAO,aAAa,SAAS,WAAW,SAAS,kBAAkB;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useIsPassedInToken/index.native.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 15-05-2023 01:54:48
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 15-05-2023 01:55:27
|
|
8
|
+
* Modified By: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Risser Labs LLC (c) Copyright 2022 - 2023
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
export declare const useIsPassedInToken: () => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 index_native_exports = {};
|
|
20
|
+
__export(index_native_exports, {
|
|
21
|
+
useIsPassedInToken: () => useIsPassedInToken
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(index_native_exports);
|
|
24
|
+
const useIsPassedInToken = () => false;
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
useIsPassedInToken
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useIsPassedInToken/index.native.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useIsPassedInToken/index.native.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 15-05-2023 01:54:48\n * Author: Clay Risser\n * -----\n * Last Modified: 15-05-2023 01:55:27\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022 - 2023\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 const useIsPassedInToken = () => false;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,qBAAqB,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -55,6 +55,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
55
55
|
var import_react = require("react");
|
|
56
56
|
var import_authConfig = require("../authConfig");
|
|
57
57
|
var import_keycloakProvider = require("./keycloakProvider");
|
|
58
|
+
var import_hooks = require("../hooks");
|
|
58
59
|
var import_config = require("app/config");
|
|
59
60
|
__reExport(provider_exports, require("./keycloakProvider"), module.exports);
|
|
60
61
|
const persist = import_config.config.get("KEYCLOAK_PERSIST") === "1";
|
|
@@ -93,13 +94,14 @@ const AuthProvider = (_a) => {
|
|
|
93
94
|
"onEvent",
|
|
94
95
|
"onTokens"
|
|
95
96
|
]);
|
|
97
|
+
const isPassedInToken = (0, import_hooks.useIsPassedInToken)();
|
|
96
98
|
const authConfig = (0, import_react.useMemo)(
|
|
97
99
|
() => __spreadProps(__spreadValues({}, import_authConfig.defaultAuthConfig), {
|
|
98
100
|
debug,
|
|
99
101
|
ensureFreshness,
|
|
100
102
|
loginRoute,
|
|
101
103
|
messageHandlerKeys,
|
|
102
|
-
persist,
|
|
104
|
+
persist: ssr || isPassedInToken ? false : persist,
|
|
103
105
|
ssr
|
|
104
106
|
}),
|
|
105
107
|
[debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';\nimport type { AuthConfig } from '../authConfig';\nimport type { FC, ComponentType, ReactNode } from 'react';\nimport type { KeycloakConfig, KeycloakInitOptions } from '@bitspur/keycloak-js';\nimport { AuthConfigContext, defaultAuthConfig } from '../authConfig';\nimport { KeycloakProvider } from './keycloakProvider';\n// @ts-ignore\nimport { config } from 'app/config';\n\nexport interface AuthProviderProps\n extends Partial<Omit<AuthConfig, 'persist'>>,\n Omit<KeycloakConfig, 'url'>,\n KeycloakInitOptions {\n children: ReactNode;\n cookies?: unknown;\n disabled?: boolean;\n baseUrl?: string;\n loadingComponent?: ComponentType;\n onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;\n onTokens?: (tokens: AuthClientTokens) => void;\n}\n\nconst persist = config.get('KEYCLOAK_PERSIST') === '1';\n\nexport const AuthProvider: FC<AuthProviderProps> = ({\n // keycloak config\n realm,\n clientId,\n baseUrl,\n // auth config\n debug,\n ensureFreshness,\n loginRoute,\n messageHandlerKeys,\n ssr,\n // props\n children,\n cookies,\n disabled,\n loadingComponent,\n onEvent,\n onTokens,\n ...keycloakInitOptions\n}: AuthProviderProps) => {\n const authConfig = useMemo(\n () => ({\n ...defaultAuthConfig,\n debug,\n ensureFreshness,\n loginRoute,\n messageHandlerKeys,\n persist,\n ssr,\n }),\n [debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr],\n );\n\n if (disabled) {\n return <AuthConfigContext.Provider value={authConfig}>{children}</AuthConfigContext.Provider>;\n }\n\n return (\n <AuthConfigContext.Provider value={authConfig}>\n <KeycloakProvider\n cookies={cookies}\n keycloakConfig={{\n realm,\n clientId,\n url: baseUrl,\n }}\n keycloakInitOptions={keycloakInitOptions}\n loadingComponent={loadingComponent}\n onEvent={onEvent}\n onTokens={onTokens}\n >\n {children}\n </KeycloakProvider>\n </AuthConfigContext.Provider>\n );\n};\n\nexport * from './keycloakProvider';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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 { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';\nimport type { AuthConfig } from '../authConfig';\nimport type { FC, ComponentType, ReactNode } from 'react';\nimport type { KeycloakConfig, KeycloakInitOptions } from '@bitspur/keycloak-js';\nimport { AuthConfigContext, defaultAuthConfig } from '../authConfig';\nimport { KeycloakProvider } from './keycloakProvider';\nimport { useIsPassedInToken } from '../hooks';\n// @ts-ignore\nimport { config } from 'app/config';\n\nexport interface AuthProviderProps\n extends Partial<Omit<AuthConfig, 'persist'>>,\n Omit<KeycloakConfig, 'url'>,\n KeycloakInitOptions {\n children: ReactNode;\n cookies?: unknown;\n disabled?: boolean;\n baseUrl?: string;\n loadingComponent?: ComponentType;\n onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;\n onTokens?: (tokens: AuthClientTokens) => void;\n}\n\nconst persist = config.get('KEYCLOAK_PERSIST') === '1';\n\nexport const AuthProvider: FC<AuthProviderProps> = ({\n // keycloak config\n realm,\n clientId,\n baseUrl,\n // auth config\n debug,\n ensureFreshness,\n loginRoute,\n messageHandlerKeys,\n ssr,\n // props\n children,\n cookies,\n disabled,\n loadingComponent,\n onEvent,\n onTokens,\n ...keycloakInitOptions\n}: AuthProviderProps) => {\n const isPassedInToken = useIsPassedInToken();\n const authConfig = useMemo(\n () => ({\n ...defaultAuthConfig,\n debug,\n ensureFreshness,\n loginRoute,\n messageHandlerKeys,\n persist: ssr || isPassedInToken ? false : persist,\n ssr,\n }),\n [debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr],\n );\n\n if (disabled) {\n return <AuthConfigContext.Provider value={authConfig}>{children}</AuthConfigContext.Provider>;\n }\n\n return (\n <AuthConfigContext.Provider value={authConfig}>\n <KeycloakProvider\n cookies={cookies}\n keycloakConfig={{\n realm,\n clientId,\n url: baseUrl,\n }}\n keycloakInitOptions={keycloakInitOptions}\n loadingComponent={loadingComponent}\n onEvent={onEvent}\n onTokens={onTokens}\n >\n {children}\n </KeycloakProvider>\n </AuthConfigContext.Provider>\n );\n};\n\nexport * from './keycloakProvider';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqFW;AA7DX,mBAA+B;AAK/B,wBAAqD;AACrD,8BAAiC;AACjC,mBAAmC;AAEnC,oBAAuB;AA2EvB,6BAAc,+BA5Gd;AAgDA,MAAM,UAAU,qBAAO,IAAI,kBAAkB,MAAM;AAE5C,MAAM,eAAsC,CAAC,OAmB3B;AAnB2B,eAElD;AAAA;AAAA,IACA;AAAA,IACA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAnEF,IAkDoD,IAkB/C,gCAlB+C,IAkB/C;AAAA;AAAA,IAhBH;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGA,QAAM,sBAAkB,iCAAmB;AAC3C,QAAM,iBAAa;AAAA,IACjB,MAAO,iCACF,sCADE;AAAA,MAEL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,OAAO,kBAAkB,QAAQ;AAAA,MAC1C;AAAA,IACF;AAAA,IACA,CAAC,OAAO,iBAAiB,YAAY,oBAAoB,SAAS,GAAG;AAAA,EACvE;AAEA,MAAI,UAAU;AACZ,WAAO,4CAAC,oCAAkB,UAAlB,EAA2B,OAAO,YAAa,UAAS;AAAA,EAClE;AAEA,SACE,4CAAC,oCAAkB,UAAlB,EAA2B,OAAO,YACjC;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,gBAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEC;AAAA;AAAA,EACH,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -34,7 +34,6 @@ export interface KeycloakProviderProps {
|
|
|
34
34
|
onTokens?: (tokens: AuthClientTokens) => void;
|
|
35
35
|
}
|
|
36
36
|
export declare function KeycloakProvider({ children, cookies, keycloakConfig, keycloakInitOptions, loadingComponent, onEvent, onTokens, }: KeycloakProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
-
export declare function isTokenValid(token: string): boolean;
|
|
38
37
|
export declare const defaultKeycloakInitOptions: KeycloakInitOptions;
|
|
39
38
|
export interface MessageSchema {
|
|
40
39
|
type: string;
|