@multiplatform.one/keycloak 0.3.9 → 0.3.11
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 +2 -1
- package/dist/esm/hooks/index.mjs.map +2 -2
- package/dist/esm/hooks/useKeycloak/useKeycloak.mjs +0 -3
- package/dist/esm/hooks/useKeycloak/useKeycloak.mjs.map +2 -2
- package/dist/esm/hooks/useTokensFromQuery/index.mjs +12 -0
- package/dist/esm/hooks/useTokensFromQuery/index.mjs.map +7 -0
- package/dist/esm/hooks/useTokensFromQuery/index.native.mjs +7 -0
- package/dist/esm/hooks/useTokensFromQuery/index.native.mjs.map +7 -0
- package/dist/esm/hooks/useTokensFromState.mjs +10 -0
- package/dist/esm/hooks/useTokensFromState.mjs.map +7 -0
- package/dist/esm/provider/afterAuth.mjs +1 -1
- package/dist/esm/provider/afterAuth.mjs.map +2 -2
- package/dist/esm/provider/index.mjs +5 -4
- package/dist/esm/provider/index.mjs.map +2 -2
- package/dist/esm/provider/keycloakProvider.mjs +4 -24
- package/dist/esm/provider/keycloakProvider.mjs.map +2 -2
- package/dist/esm/util.mjs +26 -0
- package/dist/esm/util.mjs.map +7 -0
- package/dist/jsx/hooks/index.mjs +2 -1
- package/dist/jsx/hooks/index.mjs.map +2 -2
- package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs +0 -3
- package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs.map +2 -2
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs +10 -0
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs.map +7 -0
- package/dist/jsx/hooks/useTokensFromQuery/index.native.mjs +5 -0
- package/dist/jsx/hooks/useTokensFromQuery/index.native.mjs.map +7 -0
- package/dist/jsx/hooks/useTokensFromState.mjs +10 -0
- package/dist/jsx/hooks/useTokensFromState.mjs.map +7 -0
- package/dist/jsx/provider/afterAuth.mjs +1 -1
- package/dist/jsx/provider/afterAuth.mjs.map +2 -2
- package/dist/jsx/provider/index.mjs +5 -4
- package/dist/jsx/provider/index.mjs.map +2 -2
- package/dist/jsx/provider/keycloakProvider.mjs +4 -23
- package/dist/jsx/provider/keycloakProvider.mjs.map +2 -2
- package/dist/jsx/util.mjs +25 -0
- package/dist/jsx/util.mjs.map +7 -0
- package/dist/lib/hooks/index.d.ts +3 -2
- package/dist/lib/hooks/index.js +5 -3
- package/dist/lib/hooks/index.js.map +2 -2
- package/dist/lib/hooks/useKeycloak/useKeycloak.d.ts +1 -1
- package/dist/lib/hooks/useKeycloak/useKeycloak.js +0 -3
- package/dist/lib/hooks/useKeycloak/useKeycloak.js.map +2 -2
- package/dist/lib/hooks/useTokensFromQuery/index.d.ts +24 -0
- package/dist/lib/hooks/useTokensFromQuery/index.js +34 -0
- package/dist/lib/hooks/useTokensFromQuery/index.js.map +7 -0
- package/dist/lib/hooks/useTokensFromQuery/index.native.d.ts +24 -0
- package/dist/lib/hooks/useTokensFromQuery/index.native.js +29 -0
- package/dist/lib/hooks/useTokensFromQuery/index.native.js.map +7 -0
- package/dist/lib/hooks/useTokensFromState.d.ts +24 -0
- package/dist/lib/hooks/useTokensFromState.js +34 -0
- package/dist/lib/hooks/useTokensFromState.js.map +7 -0
- package/dist/lib/provider/afterAuth.js +1 -1
- package/dist/lib/provider/afterAuth.js.map +2 -2
- package/dist/lib/provider/index.js +4 -3
- package/dist/lib/provider/index.js.map +2 -2
- package/dist/lib/provider/keycloakProvider.js +9 -29
- package/dist/lib/provider/keycloakProvider.js.map +2 -2
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -1
- package/dist/lib/util.d.ts +25 -0
- package/dist/lib/util.js +51 -0
- package/dist/lib/util.js.map +7 -0
- package/package.json +4 -4
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useKeycloak/useKeycloak.ts +1 -4
- package/src/hooks/{useIsPassedInToken → useTokensFromQuery}/index.native.ts +3 -3
- package/src/hooks/{useIsPassedInToken → useTokensFromQuery}/index.ts +3 -3
- package/src/hooks/useTokensFromState.ts +31 -0
- package/src/provider/afterAuth.tsx +1 -1
- package/src/provider/index.tsx +5 -4
- package/src/provider/keycloakProvider.tsx +4 -22
- package/src/util.ts +42 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useTokensFromState.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useTokensFromState.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 16-05-2023 06:29:02\n * Author: Clay Risser\n * -----\n * Last Modified: 16-05-2023 07:40:36\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 { useAuthState } from '../state';\nimport { validToken } from '../util';\n\nexport function useTokensFromState() {\n const authState = useAuthState();\n return !!validToken(authState.token, authState.refreshToken);\n}\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,SAAS,qBAAqB;AACnC,QAAM,YAAY,aAAa;AAC/B,SAAO,CAAC,CAAC,WAAW,UAAU,OAAO,UAAU,YAAY;AAC7D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,8 +5,8 @@ import { useKeycloak } from "../hooks";
|
|
|
5
5
|
const logger = console;
|
|
6
6
|
const AfterAuth = ({ children }) => {
|
|
7
7
|
const authConfig = useAuthConfig();
|
|
8
|
-
const { token, refreshToken, authenticated, idToken } = useKeycloak();
|
|
9
8
|
const authState = useAuthState();
|
|
9
|
+
const { token, refreshToken, authenticated, idToken } = useKeycloak();
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
if (!authenticated)
|
|
12
12
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/provider/afterAuth.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * File: /auth/provider/afterAuth.tsx\n * Project: app\n * File Created: 22-11-2022 17:49:58\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:39\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport type { FC, ReactNode } from 'react';\nimport { useAuthConfig } from '../hooks/useAuthConfig';\nimport { useAuthState } from '../state';\nimport { useKeycloak } from '../hooks';\n\nexport interface AfterAuthProps {\n children: ReactNode;\n}\n\nconst logger = console;\n\nexport const AfterAuth: FC<AfterAuthProps> = ({ children }: AfterAuthProps) => {\n const authConfig = useAuthConfig();\n const { token, refreshToken, authenticated, idToken } = useKeycloak();\n
|
|
5
|
-
"mappings": "AAwBA,SAAgB,iBAAiB;AAEjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAM5B,MAAM,SAAS;AAER,MAAM,YAAgC,CAAC,EAAE,SAAS,MAAsB;AAC7E,QAAM,aAAa,cAAc;AACjC,QAAM,EAAE,OAAO,cAAc,eAAe,QAAQ,IAAI,YAAY;
|
|
4
|
+
"sourcesContent": ["/**\n * File: /auth/provider/afterAuth.tsx\n * Project: app\n * File Created: 22-11-2022 17:49:58\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 18:00:39\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect } from 'react';\nimport type { FC, ReactNode } from 'react';\nimport { useAuthConfig } from '../hooks/useAuthConfig';\nimport { useAuthState } from '../state';\nimport { useKeycloak } from '../hooks';\n\nexport interface AfterAuthProps {\n children: ReactNode;\n}\n\nconst logger = console;\n\nexport const AfterAuth: FC<AfterAuthProps> = ({ children }: AfterAuthProps) => {\n const authConfig = useAuthConfig();\n const authState = useAuthState();\n const { token, refreshToken, authenticated, idToken } = useKeycloak();\n\n useEffect(() => {\n if (!authenticated) return;\n if (authConfig.persist && token) {\n authState.setToken(token);\n if (idToken) authState.setIdToken(idToken);\n if (authConfig.ensureFreshness && refreshToken) authState.setRefreshToken(refreshToken);\n }\n }, [token, refreshToken, idToken]);\n\n useEffect(() => {\n if (authConfig.debug && authState.token) logger.debug('token', authState.token);\n }, [authState.token]);\n\n useEffect(() => {\n if (authConfig.debug && authState.idToken) logger.debug('idToken', authState.idToken);\n }, [authState.idToken]);\n\n useEffect(() => {\n if (authConfig.debug && authState.refreshToken) logger.debug('refreshToken', authState.refreshToken);\n }, [authState.refreshToken]);\n\n useEffect(() => {\n if (authConfig.debug) logger.debug('authenticated', authenticated);\n }, [authenticated]);\n\n return <>{children}</>;\n};\n"],
|
|
5
|
+
"mappings": "AAwBA,SAAgB,iBAAiB;AAEjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAM5B,MAAM,SAAS;AAER,MAAM,YAAgC,CAAC,EAAE,SAAS,MAAsB;AAC7E,QAAM,aAAa,cAAc;AACjC,QAAM,YAAY,aAAa;AAC/B,QAAM,EAAE,OAAO,cAAc,eAAe,QAAQ,IAAI,YAAY;AAEpE,YAAU,MAAM;AACd,QAAI,CAAC;AAAe;AACpB,QAAI,WAAW,WAAW,OAAO;AAC/B,gBAAU,SAAS,KAAK;AACxB,UAAI;AAAS,kBAAU,WAAW,OAAO;AACzC,UAAI,WAAW,mBAAmB;AAAc,kBAAU,gBAAgB,YAAY;AAAA,IACxF;AAAA,EACF,GAAG,CAAC,OAAO,cAAc,OAAO,CAAC;AAEjC,YAAU,MAAM;AACd,QAAI,WAAW,SAAS,UAAU;AAAO,aAAO,MAAM,SAAS,UAAU,KAAK;AAAA,EAChF,GAAG,CAAC,UAAU,KAAK,CAAC;AAEpB,YAAU,MAAM;AACd,QAAI,WAAW,SAAS,UAAU;AAAS,aAAO,MAAM,WAAW,UAAU,OAAO;AAAA,EACtF,GAAG,CAAC,UAAU,OAAO,CAAC;AAEtB,YAAU,MAAM;AACd,QAAI,WAAW,SAAS,UAAU;AAAc,aAAO,MAAM,gBAAgB,UAAU,YAAY;AAAA,EACrG,GAAG,CAAC,UAAU,YAAY,CAAC;AAE3B,YAAU,MAAM;AACd,QAAI,WAAW;AAAO,aAAO,MAAM,iBAAiB,aAAa;AAAA,EACnE,GAAG,CAAC,aAAa,CAAC;AAElB,SAAO,GAAG,SAAS;AACrB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { AuthConfigContext, defaultAuthConfig } from "../authConfig";
|
|
3
3
|
import { KeycloakProvider } from "./keycloakProvider";
|
|
4
|
-
import {
|
|
4
|
+
import { useTokensFromState, useTokensFromQuery } from "../hooks";
|
|
5
5
|
import { config } from "app/config";
|
|
6
6
|
const persist = config.get("KEYCLOAK_PERSIST") === "1";
|
|
7
7
|
const AuthProvider = ({
|
|
@@ -24,7 +24,8 @@ const AuthProvider = ({
|
|
|
24
24
|
onTokens,
|
|
25
25
|
...keycloakInitOptions
|
|
26
26
|
}) => {
|
|
27
|
-
const
|
|
27
|
+
const tokensFromQuery = useTokensFromQuery();
|
|
28
|
+
const tokensFromState = useTokensFromState();
|
|
28
29
|
const authConfig = useMemo(
|
|
29
30
|
() => ({
|
|
30
31
|
...defaultAuthConfig,
|
|
@@ -32,8 +33,8 @@ const AuthProvider = ({
|
|
|
32
33
|
ensureFreshness,
|
|
33
34
|
loginRoute,
|
|
34
35
|
messageHandlerKeys,
|
|
35
|
-
persist: !
|
|
36
|
-
ssr: !
|
|
36
|
+
persist: !tokensFromState && !tokensFromQuery && cookies && ssr ? false : persist,
|
|
37
|
+
ssr: !tokensFromState && !tokensFromQuery && cookies ? ssr : false
|
|
37
38
|
}),
|
|
38
39
|
[debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr]
|
|
39
40
|
);
|
|
@@ -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';\nimport {
|
|
5
|
-
"mappings": "AAwBA,SAAgB,eAAe;AAK/B,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;
|
|
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 { useTokensFromState, useTokensFromQuery } 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 tokensFromQuery = useTokensFromQuery();\n const tokensFromState = useTokensFromState();\n const authConfig = useMemo(\n () => ({\n ...defaultAuthConfig,\n debug,\n ensureFreshness,\n loginRoute,\n messageHandlerKeys,\n persist: !tokensFromState && !tokensFromQuery && cookies && ssr ? false : persist,\n ssr: !tokensFromState && !tokensFromQuery && cookies ? ssr : false,\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": "AAwBA,SAAgB,eAAe;AAK/B,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,wBAAwB;AACjC,SAAS,oBAAoB,0BAA0B;AAEvD,SAAS,cAAc;AAevB,MAAM,UAAU,OAAO,IAAI,kBAAkB,MAAM;AAE5C,MAAM,eAAsC,CAAC;AAAA;AAAA,EAElD;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,CAAC,mBAAmB,CAAC,mBAAmB,WAAW,MAAM,QAAQ;AAAA,MAC1E,KAAK,CAAC,mBAAmB,CAAC,mBAAmB,UAAU,MAAM;AAAA,IAC/D;AAAA,IACA,CAAC,OAAO,iBAAiB,YAAY,oBAAoB,SAAS,GAAG;AAAA,EACvE;AAEA,MAAI,UAAU;AACZ,WAAO,CAAC,kBAAkB,SAAS,OAAO,aAAa,SAAS,EAAxD,kBAAkB;AAAA,EAC5B;AAEA,SACE,CAAC,kBAAkB,SAAS,OAAO,YACjC,CAAC;AAAA,IACC,SAAS;AAAA,IACT,gBAAgB;AAAA,MACd;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP;AAAA,IACA,qBAAqB;AAAA,IACrB,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,UAAU;AAAA,IAET,SACH,EAbC,iBAcH,EAfC,kBAAkB;AAiBvB;AAEA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,8 +6,9 @@ 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 {
|
|
9
|
+
import { useTokensFromQuery } from "../hooks";
|
|
10
10
|
import { useRouter } from "next/router";
|
|
11
|
+
import { validToken } from "../util";
|
|
11
12
|
const logger = console;
|
|
12
13
|
function KeycloakProvider({
|
|
13
14
|
children,
|
|
@@ -39,7 +40,7 @@ function KeycloakProvider({
|
|
|
39
40
|
refreshToken
|
|
40
41
|
)
|
|
41
42
|
);
|
|
42
|
-
const
|
|
43
|
+
const tokensFromQuery = useTokensFromQuery();
|
|
43
44
|
useEffect(() => {
|
|
44
45
|
if (token !== true && refreshToken !== true && idToken !== true)
|
|
45
46
|
return;
|
|
@@ -194,7 +195,7 @@ function KeycloakProvider({
|
|
|
194
195
|
initOptions2.idToken = idToken;
|
|
195
196
|
if (refreshToken && typeof refreshToken === "string")
|
|
196
197
|
initOptions2.refreshToken = refreshToken;
|
|
197
|
-
if (
|
|
198
|
+
if (tokensFromQuery) {
|
|
198
199
|
initOptions2.checkLoginIframe = false;
|
|
199
200
|
initOptions2.flow = "implicit";
|
|
200
201
|
initOptions2.onLoad = void 0;
|
|
@@ -233,26 +234,6 @@ function KeycloakProvider({
|
|
|
233
234
|
onTokens={onTokens}
|
|
234
235
|
><AfterAuth>{children}</AfterAuth></ReactKeycloakProvider>;
|
|
235
236
|
}
|
|
236
|
-
function validToken(token, refreshToken) {
|
|
237
|
-
if (typeof token !== "string")
|
|
238
|
-
return token;
|
|
239
|
-
if (refreshToken) {
|
|
240
|
-
if (refreshToken === true || isTokenValid(refreshToken))
|
|
241
|
-
return token;
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
return isTokenValid(token) ? token : false;
|
|
245
|
-
}
|
|
246
|
-
function isTokenValid(token) {
|
|
247
|
-
try {
|
|
248
|
-
const { exp } = JSON.parse(Buffer.from(token.split(".")?.[1] || "", "base64").toString() || "{}");
|
|
249
|
-
return Math.floor(Date.now() / 1e3) <= exp;
|
|
250
|
-
} catch (err) {
|
|
251
|
-
if (err instanceof SyntaxError)
|
|
252
|
-
return false;
|
|
253
|
-
throw err;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
237
|
const defaultKeycloakInitOptions = {
|
|
257
238
|
checkLoginIframe: true,
|
|
258
239
|
checkLoginIframeInterval: 5,
|
|
@@ -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 { 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', JSON.stringify({ 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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'REFRESH_TOKEN',\n payload: '<some_refresh_token>',\n }),\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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'TOKEN',\n payload: '<some_token>',\n }),\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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'ID_TOKEN',\n payload: '<some_id_token>',\n }),\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 [keycloakInitOptions, token, refreshToken, idToken],\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.flow = 'implicit';\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;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,qBAAqB,kBAAkB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;
|
|
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 { useTokensFromQuery } from '../hooks';\nimport { useRouter } from 'next/router';\nimport { validToken } from '../util';\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 tokensFromQuery = useTokensFromQuery();\n\n useEffect(() => {\n if (token !== true && refreshToken !== true && idToken !== true) return;\n if (debug) logger.debug('post message', JSON.stringify({ 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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'REFRESH_TOKEN',\n payload: '<some_refresh_token>',\n }),\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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'TOKEN',\n payload: '<some_token>',\n }),\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', JSON.stringify(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 window.removeEventListener('message', messageCallback);\n }\n };\n if (debug) {\n logger.debug(\n 'listening for message',\n JSON.stringify({\n type: 'ID_TOKEN',\n payload: '<some_id_token>',\n }),\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 [keycloakInitOptions, token, refreshToken, idToken],\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 (tokensFromQuery) {\n initOptions.checkLoginIframe = false;\n initOptions.flow = 'implicit';\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\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;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,qBAAqB,kBAAkB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAY3B,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,cAAc,eAAe,IAAI;AAAA,IACtC;AAAA,MACG,oBACG,kBAAkB,UAAU,MAAM,cAAc,SAAS,KAAK,SAC7D,WAAW,UAAU,iBACxB;AAAA,IACJ;AAAA,EACF;AACA,QAAM,C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AA,EAClB,0BAA0B;AAAA,EAC1B,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,YAAY;AACd;",
|
|
6
6
|
"names": ["initOptions"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function validToken(token, refreshToken) {
|
|
2
|
+
if (typeof token !== "string")
|
|
3
|
+
return token;
|
|
4
|
+
if (refreshToken) {
|
|
5
|
+
if (refreshToken === true || isTokenValid(refreshToken))
|
|
6
|
+
return token;
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return isTokenValid(token) ? token : false;
|
|
10
|
+
}
|
|
11
|
+
function isTokenValid(token) {
|
|
12
|
+
try {
|
|
13
|
+
const { exp } = JSON.parse(Buffer.from(token.split(".")?.[1] || "", "base64").toString() || "{}");
|
|
14
|
+
return Math.floor(Date.now() / 1e3) <= exp;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err instanceof SyntaxError)
|
|
17
|
+
return false;
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
isTokenValid,
|
|
23
|
+
validToken
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=util.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/util.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/util.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 16-05-2023 06:29:32\n * Author: Clay Risser\n * -----\n * Last Modified: 16-05-2023 06:33:36\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 function 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\nexport function 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"],
|
|
5
|
+
"mappings": "AAwBO,SAAS,WAAW,OAAyB,cAAiC;AACnF,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;AAEO,SAAS,aAAa,OAAe;AAC1C,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;",
|
|
6
|
+
"names": []
|
|
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: 16-05-2023 07:40:57
|
|
8
8
|
* Modified By: Clay Risser
|
|
9
9
|
* -----
|
|
10
10
|
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
24
|
export * from './useCurrentRouteName';
|
|
25
|
-
export * from './useIsPassedInToken';
|
|
26
25
|
export * from './useKeycloak';
|
|
27
26
|
export * from './useLogin';
|
|
27
|
+
export * from './useTokensFromQuery';
|
|
28
|
+
export * from './useTokensFromState';
|
package/dist/lib/hooks/index.js
CHANGED
|
@@ -16,14 +16,16 @@ 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);
|
|
20
19
|
__reExport(hooks_exports, require("./useKeycloak"), module.exports);
|
|
21
20
|
__reExport(hooks_exports, require("./useLogin"), module.exports);
|
|
21
|
+
__reExport(hooks_exports, require("./useTokensFromQuery"), module.exports);
|
|
22
|
+
__reExport(hooks_exports, require("./useTokensFromState"), module.exports);
|
|
22
23
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
24
|
0 && (module.exports = {
|
|
24
25
|
...require("./useCurrentRouteName"),
|
|
25
|
-
...require("./useIsPassedInToken"),
|
|
26
26
|
...require("./useKeycloak"),
|
|
27
|
-
...require("./useLogin")
|
|
27
|
+
...require("./useLogin"),
|
|
28
|
+
...require("./useTokensFromQuery"),
|
|
29
|
+
...require("./useTokensFromState")
|
|
28
30
|
});
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -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: 16-05-2023 07:40:57\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';\nexport * from './useTokensFromQuery';\nexport * from './useTokensFromState';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAwBA,0BAAc,kCAxBd;AAyBA,0BAAc,0BAzBd;AA0BA,0BAAc,uBA1Bd;AA2BA,0BAAc,iCA3Bd;AA4BA,0BAAc,iCA5Bd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -46,7 +46,6 @@ function useKeycloak() {
|
|
|
46
46
|
const authConfig = (0, import_useAuthConfig.useAuthConfig)();
|
|
47
47
|
if (import_multiplatform.MultiPlatform.isStorybook)
|
|
48
48
|
return { authenticated: true };
|
|
49
|
-
console.log("SSR", authConfig.ssr);
|
|
50
49
|
if (import_multiplatform.MultiPlatform.isNext && authConfig.ssr) {
|
|
51
50
|
const { keycloak: keycloak2, initialized: initialized2 } = (0, import_react_keycloak_ssr.useKeycloak)();
|
|
52
51
|
return __spreadProps(__spreadValues({}, keycloak2), {
|
|
@@ -54,8 +53,6 @@ function useKeycloak() {
|
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
55
|
const { keycloak, initialized } = (0, import_react_keycloak_web.useKeycloak)();
|
|
57
|
-
console.log("a1", keycloak.authenticated);
|
|
58
|
-
console.log("a2", initialized ? keycloak.authenticated : void 0);
|
|
59
56
|
return __spreadProps(__spreadValues({}, keycloak), {
|
|
60
57
|
authenticated: initialized ? keycloak.authenticated : void 0
|
|
61
58
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/hooks/useKeycloak/useKeycloak.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * File: /src/hooks/useKeycloak/useKeycloak.ts\n * Project: app\n * File Created: 08-11-2022 06:04:59\n * Author: Clay Risser\n * -----\n * Last Modified: 15-05-2023
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,2BAA8B;AAC9B,2BAA8B;AAC9B,gCAAgD;AAChD,gCAA8C;AAEvC,SAAS,cAAc;AAC5B,QAAM,iBAAa,oCAAc;AACjC,MAAI,mCAAc;AAAa,WAAO,EAAE,eAAe,KAAK;AAC5D,
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useKeycloak/useKeycloak.ts\n * Project: app\n * File Created: 08-11-2022 06:04:59\n * Author: Clay Risser\n * -----\n * Last Modified: 15-05-2023 18:10:07\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { IKeycloak } from './index';\nimport { MultiPlatform } from 'multiplatform.one';\nimport { useAuthConfig } from '../useAuthConfig';\nimport { useKeycloak as useReactKeycloak } from '@bitspur/react-keycloak-web';\nimport { useKeycloak as useSsrKeycloak } from '@bitspur/react-keycloak-ssr';\n\nexport function useKeycloak() {\n const authConfig = useAuthConfig();\n if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;\n if (MultiPlatform.isNext && authConfig.ssr) {\n const { keycloak, initialized } = useSsrKeycloak();\n return {\n ...keycloak,\n authenticated: initialized ? keycloak?.authenticated : undefined,\n } as IKeycloak;\n }\n const { keycloak, initialized } = useReactKeycloak();\n return {\n ...keycloak,\n authenticated: initialized ? keycloak.authenticated : undefined,\n } as IKeycloak;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,2BAA8B;AAC9B,2BAA8B;AAC9B,gCAAgD;AAChD,gCAA8C;AAEvC,SAAS,cAAc;AAC5B,QAAM,iBAAa,oCAAc;AACjC,MAAI,mCAAc;AAAa,WAAO,EAAE,eAAe,KAAK;AAC5D,MAAI,mCAAc,UAAU,WAAW,KAAK;AAC1C,UAAM,EAAE,UAAAA,WAAU,aAAAC,aAAY,QAAI,0BAAAC,aAAe;AACjD,WAAO,iCACFF,YADE;AAAA,MAEL,eAAeC,eAAcD,aAAA,gBAAAA,UAAU,gBAAgB;AAAA,IACzD;AAAA,EACF;AACA,QAAM,EAAE,UAAU,YAAY,QAAI,0BAAAG,aAAiB;AACnD,SAAO,iCACF,WADE;AAAA,IAEL,eAAe,cAAc,SAAS,gBAAgB;AAAA,EACxD;AACF;",
|
|
6
6
|
"names": ["keycloak", "initialized", "useSsrKeycloak", "useReactKeycloak"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useTokensFromQuery/index.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 15-05-2023 01:54:44
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 16-05-2023 07:40:41
|
|
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 useTokensFromQuery(): 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 useTokensFromQuery_exports = {};
|
|
20
|
+
__export(useTokensFromQuery_exports, {
|
|
21
|
+
useTokensFromQuery: () => useTokensFromQuery
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useTokensFromQuery_exports);
|
|
24
|
+
var import_multiplatform = require("multiplatform.one");
|
|
25
|
+
var import_router = require("next/router");
|
|
26
|
+
function useTokensFromQuery() {
|
|
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
|
+
useTokensFromQuery
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useTokensFromQuery/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useTokensFromQuery/index.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 15-05-2023 01:54:44\n * Author: Clay Risser\n * -----\n * Last Modified: 16-05-2023 07:40:41\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 useTokensFromQuery() {\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/useTokensFromQuery/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: 16-05-2023 07:40:46
|
|
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 useTokensFromQuery: () => 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
|
+
useTokensFromQuery: () => useTokensFromQuery
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(index_native_exports);
|
|
24
|
+
const useTokensFromQuery = () => false;
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
useTokensFromQuery
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/useTokensFromQuery/index.native.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useTokensFromQuery/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: 16-05-2023 07:40:46\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 useTokensFromQuery = () => false;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,qBAAqB,MAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useTokensFromState.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 16-05-2023 06:29:02
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 16-05-2023 07:40:36
|
|
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 useTokensFromState(): 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 useTokensFromState_exports = {};
|
|
20
|
+
__export(useTokensFromState_exports, {
|
|
21
|
+
useTokensFromState: () => useTokensFromState
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useTokensFromState_exports);
|
|
24
|
+
var import_state = require("../state");
|
|
25
|
+
var import_util = require("../util");
|
|
26
|
+
function useTokensFromState() {
|
|
27
|
+
const authState = (0, import_state.useAuthState)();
|
|
28
|
+
return !!(0, import_util.validToken)(authState.token, authState.refreshToken);
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
useTokensFromState
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=useTokensFromState.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useTokensFromState.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * File: /src/hooks/useTokensFromState.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 16-05-2023 06:29:02\n * Author: Clay Risser\n * -----\n * Last Modified: 16-05-2023 07:40:36\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 { useAuthState } from '../state';\nimport { validToken } from '../util';\n\nexport function useTokensFromState() {\n const authState = useAuthState();\n return !!validToken(authState.token, authState.refreshToken);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,mBAA6B;AAC7B,kBAA2B;AAEpB,SAAS,qBAAqB;AACnC,QAAM,gBAAY,2BAAa;AAC/B,SAAO,CAAC,KAAC,wBAAW,UAAU,OAAO,UAAU,YAAY;AAC7D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -29,8 +29,8 @@ var import_hooks = require("../hooks");
|
|
|
29
29
|
const logger = console;
|
|
30
30
|
const AfterAuth = ({ children }) => {
|
|
31
31
|
const authConfig = (0, import_useAuthConfig.useAuthConfig)();
|
|
32
|
-
const { token, refreshToken, authenticated, idToken } = (0, import_hooks.useKeycloak)();
|
|
33
32
|
const authState = (0, import_state.useAuthState)();
|
|
33
|
+
const { token, refreshToken, authenticated, idToken } = (0, import_hooks.useKeycloak)();
|
|
34
34
|
(0, import_react.useEffect)(() => {
|
|
35
35
|
if (!authenticated)
|
|
36
36
|
return;
|