@multiplatform.one/keycloak 0.7.14 → 0.7.16
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/package.json +28 -28
- package/routes/index.d.ts +22 -0
- package/routes/index.js +22 -0
- package/src/Authenticated.tsx +27 -17
- package/src/authConfig.ts +3 -9
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useTokensFromQuery/index.ts +1 -0
- package/src/hooks/useTokensFromState.ts +1 -1
- package/src/index.ts +3 -0
- package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
- package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/index.ts} +4 -7
- package/src/keycloak/keycloak.native.ts +148 -0
- package/src/keycloak/keycloak.ts +175 -0
- package/src/provider/AfterAuth.tsx +63 -0
- package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
- package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
- package/{lib/@types/expoKeycloakAuth.d.d.ts → src/provider/AuthProvider/index.ts} +4 -7
- package/src/provider/KeycloakProvider.tsx +53 -0
- package/src/{hooks/useCurrentRouteName/index.native.ts → provider/index.ts} +6 -11
- package/src/routes.ts +163 -0
- package/src/session/index.ts +22 -0
- package/src/session/session.native.ts +31 -0
- package/src/session/session.ts +68 -0
- package/src/{state/index.ts → state.ts} +5 -4
- package/src/{util.ts → token.ts} +25 -11
- package/src/types.ts +4 -1
- package/lib/@types/coreJsPure.d.d.mts +0 -2
- package/lib/@types/coreJsPure.d.d.ts +0 -2
- package/lib/@types/coreJsPure.d.js +0 -1
- package/lib/@types/coreJsPure.d.mjs +0 -0
- package/lib/@types/expoKeycloakAuth.d.js +0 -1
- package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
- package/lib/Authenticated.d.mts +0 -33
- package/lib/Authenticated.d.ts +0 -33
- package/lib/Authenticated.js +0 -19
- package/lib/Authenticated.mjs +0 -20
- package/lib/authConfig.d.mts +0 -14
- package/lib/authConfig.d.ts +0 -14
- package/lib/authConfig.js +0 -8
- package/lib/authConfig.mjs +0 -9
- package/lib/chunk-2GUOEPFY.mjs +0 -0
- package/lib/chunk-3ZPHNEJL.js +0 -11
- package/lib/chunk-64PPU7Q3.mjs +0 -13
- package/lib/chunk-6NDWOV55.js +0 -1
- package/lib/chunk-7MTPH6XK.mjs +0 -26
- package/lib/chunk-A7UBOIAL.js +0 -13
- package/lib/chunk-AD6VPMID.mjs +0 -20
- package/lib/chunk-AUUZ6BI7.js +0 -78
- package/lib/chunk-AYKQVWMR.mjs +0 -0
- package/lib/chunk-BVB33X7V.mjs +0 -265
- package/lib/chunk-C2FNSVJO.js +0 -17
- package/lib/chunk-J4CCMILN.mjs +0 -41
- package/lib/chunk-K33RKJZX.js +0 -443
- package/lib/chunk-KLLABHIC.js +0 -13
- package/lib/chunk-L5HMOY4M.mjs +0 -18
- package/lib/chunk-MZ6E62HK.js +0 -33
- package/lib/chunk-NWRANDZ6.js +0 -98
- package/lib/chunk-NXTVYIBR.mjs +0 -11
- package/lib/chunk-OYWAYMFN.js +0 -17
- package/lib/chunk-RPUOO7AV.mjs +0 -10
- package/lib/chunk-RYM7KERK.mjs +0 -52
- package/lib/chunk-UBVYEZI3.js +0 -1
- package/lib/chunk-UHTKOFS6.mjs +0 -84
- package/lib/chunk-UL6L5ONI.js +0 -460
- package/lib/chunk-UOKDJT5L.mjs +0 -16
- package/lib/chunk-W5DJLFTQ.js +0 -56
- package/lib/chunk-WT5W6BSZ.js +0 -161
- package/lib/chunk-XEO3YXBM.js +0 -22
- package/lib/chunk-XO4W2SMN.mjs +0 -50
- package/lib/chunk-XVPWAAZ4.mjs +0 -76
- package/lib/chunk-Y4XMF3R6.mjs +0 -13
- package/lib/chunk-YGNNHTFE.js +0 -12
- package/lib/hooks/index.d.mts +0 -9
- package/lib/hooks/index.d.ts +0 -9
- package/lib/hooks/index.js +0 -23
- package/lib/hooks/index.mjs +0 -34
- package/lib/hooks/useAuthConfig.d.mts +0 -6
- package/lib/hooks/useAuthConfig.d.ts +0 -6
- package/lib/hooks/useAuthConfig.js +0 -8
- package/lib/hooks/useAuthConfig.mjs +0 -8
- package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
- package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
- package/lib/hooks/useCurrentRouteName/index.js +0 -7
- package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
- package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
- package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
- package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
- package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
- package/lib/hooks/useKeycloak/index.d.mts +0 -46
- package/lib/hooks/useKeycloak/index.d.ts +0 -46
- package/lib/hooks/useKeycloak/index.js +0 -11
- package/lib/hooks/useKeycloak/index.mjs +0 -12
- package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
- package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
- package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
- package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
- package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
- package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
- package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
- package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
- package/lib/hooks/useLogin.d.mts +0 -3
- package/lib/hooks/useLogin.d.ts +0 -3
- package/lib/hooks/useLogin.js +0 -11
- package/lib/hooks/useLogin.mjs +0 -11
- package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.js +0 -7
- package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
- package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.js +0 -10
- package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
- package/lib/hooks/useTokensFromState.d.mts +0 -3
- package/lib/hooks/useTokensFromState.d.ts +0 -3
- package/lib/hooks/useTokensFromState.js +0 -9
- package/lib/hooks/useTokensFromState.mjs +0 -9
- package/lib/index.d.mts +0 -13
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -34
- package/lib/index.mjs +0 -56
- package/lib/provider/afterAuth.d.mts +0 -29
- package/lib/provider/afterAuth.d.ts +0 -29
- package/lib/provider/afterAuth.js +0 -18
- package/lib/provider/afterAuth.mjs +0 -18
- package/lib/provider/index.d.mts +0 -39
- package/lib/provider/index.d.ts +0 -39
- package/lib/provider/index.js +0 -22
- package/lib/provider/index.mjs +0 -25
- package/lib/provider/keycloakProvider.d.mts +0 -42
- package/lib/provider/keycloakProvider.d.ts +0 -42
- package/lib/provider/keycloakProvider.js +0 -20
- package/lib/provider/keycloakProvider.mjs +0 -21
- package/lib/provider/keycloakProvider.native.d.mts +0 -29
- package/lib/provider/keycloakProvider.native.d.ts +0 -29
- package/lib/provider/keycloakProvider.native.js +0 -87
- package/lib/provider/keycloakProvider.native.mjs +0 -30
- package/lib/state/index.d.mts +0 -11
- package/lib/state/index.d.ts +0 -11
- package/lib/state/index.js +0 -7
- package/lib/state/index.mjs +0 -7
- package/lib/types.d.mts +0 -17
- package/lib/types.d.ts +0 -17
- package/lib/types.js +0 -8
- package/lib/types.mjs +0 -7
- package/lib/util.d.mts +0 -4
- package/lib/util.d.ts +0 -4
- package/lib/util.js +0 -8
- package/lib/util.mjs +0 -9
- package/src/hooks/useCurrentRouteName/index.ts +0 -34
- package/src/hooks/useKeycloak/index.ts +0 -47
- package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
- package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
- package/src/hooks/useLogin.ts +0 -47
- package/src/provider/afterAuth.tsx +0 -65
- package/src/provider/index.tsx +0 -117
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* File: /src/hooks/useKeycloak/useKeycloak.ts
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 22-06-2023 10:07:56
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import type { IKeycloak } from './index';
|
|
23
|
-
import { MultiPlatform } from 'multiplatform.one';
|
|
24
|
-
import { useAuthConfig } from '../useAuthConfig';
|
|
25
|
-
import { useKeycloak as useReactKeycloak } from '@bitspur/react-keycloak-web';
|
|
26
|
-
import { useKeycloak as useSsrKeycloak } from '@bitspur/react-keycloak-ssr';
|
|
27
|
-
|
|
28
|
-
export function useKeycloak() {
|
|
29
|
-
const authConfig = useAuthConfig();
|
|
30
|
-
if (MultiPlatform.isStorybook) {
|
|
31
|
-
return new Keycloak(
|
|
32
|
-
{
|
|
33
|
-
email: 'storybook@example.com',
|
|
34
|
-
login: async () => undefined,
|
|
35
|
-
logout: async () => undefined,
|
|
36
|
-
subject: '0',
|
|
37
|
-
username: 'storybook',
|
|
38
|
-
},
|
|
39
|
-
true,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (MultiPlatform.isNext && authConfig.ssr) {
|
|
43
|
-
const { keycloak, initialized } = useSsrKeycloak();
|
|
44
|
-
return new Keycloak(keycloak, initialized);
|
|
45
|
-
}
|
|
46
|
-
const { keycloak, initialized } = useReactKeycloak();
|
|
47
|
-
return new Keycloak(keycloak, initialized);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class Keycloak implements IKeycloak {
|
|
51
|
-
authenticated?: boolean;
|
|
52
|
-
|
|
53
|
-
constructor(private readonly keycloak: IKeycloak | undefined, initialized: boolean) {
|
|
54
|
-
this.authenticated = initialized ? keycloak?.authenticated : undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get idToken() {
|
|
58
|
-
return this.keycloak?.idToken;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get realmAccess() {
|
|
62
|
-
return this.keycloak?.realmAccess;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get refreshToken() {
|
|
66
|
-
return this.keycloak?.refreshToken;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get refreshTokenParsed() {
|
|
70
|
-
return this.keycloak?.refreshTokenParsed;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get resourceAccess() {
|
|
74
|
-
return this.keycloak?.resourceAccess;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get subject() {
|
|
78
|
-
return this.keycloak?.subject;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get token() {
|
|
82
|
-
return this.keycloak?.token;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get tokenParsed() {
|
|
86
|
-
return this.keycloak?.tokenParsed;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get email() {
|
|
90
|
-
return this.keycloak?.tokenParsed?.email;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get username() {
|
|
94
|
-
return this.keycloak?.tokenParsed?.preferred_username;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async login() {
|
|
98
|
-
if (!this.keycloak) return;
|
|
99
|
-
return this.keycloak.login();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async logout() {
|
|
103
|
-
if (!this.keycloak) return;
|
|
104
|
-
return this.keycloak.logout();
|
|
105
|
-
}
|
|
106
|
-
}
|
package/src/hooks/useLogin.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* File: /src/hooks/useLogin.ts
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 22-06-2023 10:07:56
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { MultiPlatform } from 'multiplatform.one';
|
|
23
|
-
import { useAuthConfig } from './useAuthConfig';
|
|
24
|
-
import { useCurrentRouteName } from './useCurrentRouteName';
|
|
25
|
-
import { useKeycloak } from './useKeycloak/useKeycloak';
|
|
26
|
-
import { useRouter } from 'solito/router';
|
|
27
|
-
|
|
28
|
-
export function useLogin(loginRoute?: string) {
|
|
29
|
-
if (MultiPlatform.isStorybook) return () => null;
|
|
30
|
-
const keycloak = useKeycloak();
|
|
31
|
-
const authConfig = useAuthConfig();
|
|
32
|
-
const currentRouteName = useCurrentRouteName();
|
|
33
|
-
const router = useRouter();
|
|
34
|
-
return () => {
|
|
35
|
-
if (!loginRoute) loginRoute = authConfig.loginRoute;
|
|
36
|
-
if (!loginRoute) {
|
|
37
|
-
keycloak.login();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const url = new URL(`x://${loginRoute}`);
|
|
41
|
-
const searchParams = new URLSearchParams(url.search);
|
|
42
|
-
if (currentRouteName) searchParams.append('backTo', currentRouteName);
|
|
43
|
-
let query = searchParams.toString();
|
|
44
|
-
if (query.length) query = `?${query}`;
|
|
45
|
-
router.push(`${url.pathname.substring(2)}${query}`);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/provider/afterAuth.tsx
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 22-06-2023 10:07:56
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import React, { useEffect } from 'react';
|
|
23
|
-
import type { FC, ReactNode } from 'react';
|
|
24
|
-
import { useAuthConfig } from '../hooks/useAuthConfig';
|
|
25
|
-
import { useAuthState } from '../state';
|
|
26
|
-
import { useKeycloak } from '../hooks';
|
|
27
|
-
|
|
28
|
-
export interface AfterAuthProps {
|
|
29
|
-
children: ReactNode;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const logger = console;
|
|
33
|
-
|
|
34
|
-
export const AfterAuth: FC<AfterAuthProps> = ({ children }: AfterAuthProps) => {
|
|
35
|
-
const authConfig = useAuthConfig();
|
|
36
|
-
const authState = useAuthState();
|
|
37
|
-
const { token, refreshToken, authenticated, idToken } = useKeycloak();
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!authenticated) return;
|
|
41
|
-
if (authConfig.persist && token) {
|
|
42
|
-
authState.setToken(token);
|
|
43
|
-
if (idToken) authState.setIdToken(idToken);
|
|
44
|
-
if (authConfig.ensureFreshness && refreshToken) authState.setRefreshToken(refreshToken);
|
|
45
|
-
}
|
|
46
|
-
}, [token, refreshToken, idToken]);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (authConfig.debug && authState.token) logger.debug('token', authState.token);
|
|
50
|
-
}, [authState.token]);
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (authConfig.debug && authState.idToken) logger.debug('idToken', authState.idToken);
|
|
54
|
-
}, [authState.idToken]);
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (authConfig.debug && authState.refreshToken) logger.debug('refreshToken', authState.refreshToken);
|
|
58
|
-
}, [authState.refreshToken]);
|
|
59
|
-
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (authConfig.debug) logger.debug('authenticated', authenticated);
|
|
62
|
-
}, [authenticated]);
|
|
63
|
-
|
|
64
|
-
return <>{children}</>;
|
|
65
|
-
};
|
package/src/provider/index.tsx
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/provider/index.tsx
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 22-06-2023 10:07:56
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import React, { useMemo } from 'react';
|
|
23
|
-
import type { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';
|
|
24
|
-
import type { AuthConfig } from '../authConfig';
|
|
25
|
-
import type { FC, ComponentType, ReactNode } from 'react';
|
|
26
|
-
import type { KeycloakConfig, KeycloakInitOptions } from '@bitspur/keycloak-js';
|
|
27
|
-
import { AuthConfigContext, defaultAuthConfig } from '../authConfig';
|
|
28
|
-
import { KeycloakProvider } from './keycloakProvider';
|
|
29
|
-
import { useTokensFromState, useTokensFromQuery } from '../hooks';
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
import { config } from 'app/config';
|
|
32
|
-
|
|
33
|
-
export interface AuthProviderProps
|
|
34
|
-
extends Partial<Omit<AuthConfig, 'persist'>>,
|
|
35
|
-
Partial<Omit<KeycloakConfig, 'url'>>,
|
|
36
|
-
KeycloakInitOptions {
|
|
37
|
-
children: ReactNode;
|
|
38
|
-
cookies?: unknown;
|
|
39
|
-
disabled?: boolean;
|
|
40
|
-
baseUrl?: string;
|
|
41
|
-
loadingComponent?: ComponentType;
|
|
42
|
-
onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
|
|
43
|
-
onTokens?: (tokens: AuthClientTokens) => void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const persist = config.get('KEYCLOAK_PERSIST') === '1';
|
|
47
|
-
|
|
48
|
-
export const AuthProvider: FC<AuthProviderProps> = ({
|
|
49
|
-
// keycloak config
|
|
50
|
-
realm,
|
|
51
|
-
clientId,
|
|
52
|
-
baseUrl,
|
|
53
|
-
// auth config
|
|
54
|
-
debug,
|
|
55
|
-
ensureFreshness,
|
|
56
|
-
loginRoute,
|
|
57
|
-
messageHandlerKeys,
|
|
58
|
-
ssr,
|
|
59
|
-
// props
|
|
60
|
-
children,
|
|
61
|
-
cookies,
|
|
62
|
-
disabled,
|
|
63
|
-
loadingComponent,
|
|
64
|
-
onEvent,
|
|
65
|
-
onTokens,
|
|
66
|
-
...keycloakInitOptions
|
|
67
|
-
}: AuthProviderProps) => {
|
|
68
|
-
const tokensFromQuery = useTokensFromQuery();
|
|
69
|
-
const tokensFromState = useTokensFromState();
|
|
70
|
-
const authConfig = useMemo(
|
|
71
|
-
() => ({
|
|
72
|
-
...defaultAuthConfig,
|
|
73
|
-
...(typeof debug !== 'undefined' ? { debug } : {}),
|
|
74
|
-
...(typeof ensureFreshness !== 'undefined' ? { ensureFreshness } : {}),
|
|
75
|
-
...(typeof loginRoute !== 'undefined' ? { loginRoute } : {}),
|
|
76
|
-
...(typeof messageHandlerKeys !== 'undefined' ? { messageHandlerKeys } : {}),
|
|
77
|
-
persist:
|
|
78
|
-
!tokensFromState && !tokensFromQuery && cookies && ssr
|
|
79
|
-
? false
|
|
80
|
-
: typeof persist !== 'undefined'
|
|
81
|
-
? persist
|
|
82
|
-
: defaultAuthConfig.persist,
|
|
83
|
-
ssr:
|
|
84
|
-
!tokensFromState && !tokensFromQuery && cookies
|
|
85
|
-
? typeof ssr !== 'undefined'
|
|
86
|
-
? ssr
|
|
87
|
-
: defaultAuthConfig.ssr
|
|
88
|
-
: false,
|
|
89
|
-
}),
|
|
90
|
-
[debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr],
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
if (disabled) {
|
|
94
|
-
return <AuthConfigContext.Provider value={authConfig}>{children}</AuthConfigContext.Provider>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<AuthConfigContext.Provider value={authConfig}>
|
|
99
|
-
<KeycloakProvider
|
|
100
|
-
cookies={cookies}
|
|
101
|
-
keycloakConfig={{
|
|
102
|
-
realm: realm || 'main',
|
|
103
|
-
clientId: clientId || 'app',
|
|
104
|
-
url: baseUrl,
|
|
105
|
-
}}
|
|
106
|
-
keycloakInitOptions={keycloakInitOptions}
|
|
107
|
-
loadingComponent={loadingComponent}
|
|
108
|
-
onEvent={onEvent}
|
|
109
|
-
onTokens={onTokens}
|
|
110
|
-
>
|
|
111
|
-
{children}
|
|
112
|
-
</KeycloakProvider>
|
|
113
|
-
</AuthConfigContext.Provider>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export * from './keycloakProvider';
|