@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* File: /src/session.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 10-01-2024 02:31:26
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* BitSpur (c) Copyright 2021 - 2024
|
|
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 { Session as NextSession } from 'next-auth';
|
|
23
|
+
import type { SessionContextValue as NextSessionContextValue, UseSessionOptions } from 'next-auth/react';
|
|
24
|
+
import { MultiPlatform } from 'multiplatform.one';
|
|
25
|
+
import { useSession as useNextSession, getSession as getNextSession } from 'next-auth/react';
|
|
26
|
+
|
|
27
|
+
let _getServerSession: (() => Promise<Session | null>) | undefined;
|
|
28
|
+
|
|
29
|
+
export async function getSession(): Promise<Session | null> {
|
|
30
|
+
if (MultiPlatform.isServer) {
|
|
31
|
+
if (typeof _getServerSession === 'function') return _getServerSession();
|
|
32
|
+
const getSession = (await import('next-auth')).getServerSession;
|
|
33
|
+
_getServerSession = () => getSession();
|
|
34
|
+
return _getServerSession();
|
|
35
|
+
}
|
|
36
|
+
return getNextSession();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type SessionContextValue<R extends boolean> = Partial<
|
|
40
|
+
Omit<NextSessionContextValue<R> & { session: Session }, 'data'>
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
let useSession = <R extends boolean>(
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
options?: UseSessionOptions<R>,
|
|
46
|
+
): SessionContextValue<R> => {
|
|
47
|
+
return {};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (MultiPlatform.isNext) {
|
|
51
|
+
useSession = <R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R> => {
|
|
52
|
+
const nextSession = useNextSession(options);
|
|
53
|
+
return {
|
|
54
|
+
update: nextSession.update,
|
|
55
|
+
status: nextSession.status,
|
|
56
|
+
session: nextSession.data as Session,
|
|
57
|
+
} as SessionContextValue<R>;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Session extends NextSession {
|
|
62
|
+
accessToken?: string;
|
|
63
|
+
err?: Error;
|
|
64
|
+
idToken?: string;
|
|
65
|
+
refreshToken?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { useSession };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* File: /src/state
|
|
2
|
+
* File: /src/state.ts
|
|
3
3
|
* Project: @multiplatform.one/keycloak
|
|
4
4
|
* File Created: 22-06-2023 10:07:56
|
|
5
5
|
* Author: Clay Risser
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { createStateStore } from 'multiplatform.one/zustand';
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
import { MultiPlatform } from 'multiplatform.one';
|
|
24
|
+
|
|
25
|
+
export const persist = MultiPlatform.isIframe || (!MultiPlatform.isNext && !MultiPlatform.isServer);
|
|
25
26
|
|
|
26
27
|
const { useStore } = createStateStore(
|
|
27
28
|
'auth',
|
|
@@ -31,7 +32,7 @@ const { useStore } = createStateStore(
|
|
|
31
32
|
token: '',
|
|
32
33
|
},
|
|
33
34
|
undefined,
|
|
34
|
-
{ persist
|
|
35
|
+
{ persist },
|
|
35
36
|
);
|
|
36
37
|
|
|
37
38
|
export function useAuthState() {
|
package/src/{util.ts → token.ts}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* File: /src/
|
|
2
|
+
* File: /src/token.ts
|
|
3
3
|
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created:
|
|
4
|
+
* File Created: 10-01-2024 16:19:33
|
|
5
5
|
* Author: Clay Risser
|
|
6
6
|
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 -
|
|
7
|
+
* BitSpur (c) Copyright 2021 - 2024
|
|
8
8
|
*
|
|
9
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
10
|
* you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,12 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
import type { KeycloakTokenParsed } from 'keycloak-js';
|
|
23
|
+
import { jwtDecode } from 'jwt-decode';
|
|
24
|
+
|
|
25
|
+
export function validToken(token?: string | boolean, refreshToken?: string | boolean) {
|
|
26
|
+
if (typeof token === 'undefined') return;
|
|
27
|
+
if (!token) return false;
|
|
23
28
|
if (typeof token !== 'string') return token;
|
|
24
29
|
if (refreshToken) {
|
|
25
30
|
if (refreshToken === true || isTokenValid(refreshToken)) return token;
|
|
@@ -29,11 +34,20 @@ export function validToken(token: string | boolean, refreshToken?: string | bool
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export function isTokenValid(token: string) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const { exp } = jwtDecode(token) as TokenParsed;
|
|
38
|
+
if (!exp) return false;
|
|
39
|
+
return Math.floor(Date.now() / 1000) <= exp;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface TokenParsed extends KeycloakTokenParsed {
|
|
43
|
+
jti?: string;
|
|
44
|
+
sid?: string;
|
|
45
|
+
typ?: 'Bearer' | string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AccessTokenParsed extends TokenParsed {
|
|
49
|
+
email?: string;
|
|
50
|
+
email_verified?: boolean;
|
|
51
|
+
preferred_username?: string;
|
|
52
|
+
scope?: string;
|
|
39
53
|
}
|
package/src/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
File without changes
|
package/lib/Authenticated.d.mts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React__default, { ReactNode, ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* File: /src/Authenticated.tsx
|
|
5
|
-
* Project: @multiplatform.one/keycloak
|
|
6
|
-
* File Created: 22-06-2023 10:07:56
|
|
7
|
-
* Author: Clay Risser
|
|
8
|
-
* -----
|
|
9
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
interface AuthenticatedProps {
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
disabled?: boolean;
|
|
27
|
-
loggedOutComponent?: ComponentType;
|
|
28
|
-
loginRoute?: string;
|
|
29
|
-
}
|
|
30
|
-
declare function Authenticated({ children, disabled, loginRoute, loggedOutComponent }: AuthenticatedProps): React__default.JSX.Element;
|
|
31
|
-
declare function withAuthenticated<P extends object>(Component: ComponentType<P>): (props: P) => React__default.JSX.Element;
|
|
32
|
-
|
|
33
|
-
export { Authenticated, type AuthenticatedProps, withAuthenticated };
|
package/lib/Authenticated.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React__default, { ReactNode, ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* File: /src/Authenticated.tsx
|
|
5
|
-
* Project: @multiplatform.one/keycloak
|
|
6
|
-
* File Created: 22-06-2023 10:07:56
|
|
7
|
-
* Author: Clay Risser
|
|
8
|
-
* -----
|
|
9
|
-
* BitSpur (c) Copyright 2021 - 2023
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
interface AuthenticatedProps {
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
disabled?: boolean;
|
|
27
|
-
loggedOutComponent?: ComponentType;
|
|
28
|
-
loginRoute?: string;
|
|
29
|
-
}
|
|
30
|
-
declare function Authenticated({ children, disabled, loginRoute, loggedOutComponent }: AuthenticatedProps): React__default.JSX.Element;
|
|
31
|
-
declare function withAuthenticated<P extends object>(Component: ComponentType<P>): (props: P) => React__default.JSX.Element;
|
|
32
|
-
|
|
33
|
-
export { Authenticated, type AuthenticatedProps, withAuthenticated };
|
package/lib/Authenticated.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
var _chunkAUUZ6BI7js = require("./chunk-AUUZ6BI7.js");
|
|
6
|
-
require("./chunk-UBVYEZI3.js");
|
|
7
|
-
require("./chunk-6NDWOV55.js");
|
|
8
|
-
require("./chunk-KLLABHIC.js");
|
|
9
|
-
require("./chunk-MZ6E62HK.js");
|
|
10
|
-
require("./chunk-OYWAYMFN.js");
|
|
11
|
-
require("./chunk-UL6L5ONI.js");
|
|
12
|
-
require("./chunk-3ZPHNEJL.js");
|
|
13
|
-
require("./chunk-YGNNHTFE.js");
|
|
14
|
-
require("./chunk-C2FNSVJO.js");
|
|
15
|
-
require("./chunk-A7UBOIAL.js");
|
|
16
|
-
require("./chunk-NWRANDZ6.js");
|
|
17
|
-
require("./chunk-XEO3YXBM.js");
|
|
18
|
-
exports.Authenticated = _chunkAUUZ6BI7js.Authenticated;
|
|
19
|
-
exports.withAuthenticated = _chunkAUUZ6BI7js.withAuthenticated;
|
package/lib/Authenticated.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Authenticated,
|
|
3
|
-
withAuthenticated
|
|
4
|
-
} from "./chunk-RYM7KERK.mjs";
|
|
5
|
-
import "./chunk-AYKQVWMR.mjs";
|
|
6
|
-
import "./chunk-2GUOEPFY.mjs";
|
|
7
|
-
import "./chunk-NXTVYIBR.mjs";
|
|
8
|
-
import "./chunk-J4CCMILN.mjs";
|
|
9
|
-
import "./chunk-L5HMOY4M.mjs";
|
|
10
|
-
import "./chunk-UHTKOFS6.mjs";
|
|
11
|
-
import "./chunk-Y4XMF3R6.mjs";
|
|
12
|
-
import "./chunk-UOKDJT5L.mjs";
|
|
13
|
-
import "./chunk-AD6VPMID.mjs";
|
|
14
|
-
import "./chunk-64PPU7Q3.mjs";
|
|
15
|
-
import "./chunk-7MTPH6XK.mjs";
|
|
16
|
-
import "./chunk-RPUOO7AV.mjs";
|
|
17
|
-
export {
|
|
18
|
-
Authenticated,
|
|
19
|
-
withAuthenticated
|
|
20
|
-
};
|
package/lib/authConfig.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
declare const defaultAuthConfig: AuthConfig;
|
|
4
|
-
declare const AuthConfigContext: React.Context<AuthConfig>;
|
|
5
|
-
interface AuthConfig {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
ensureFreshness?: boolean;
|
|
8
|
-
loginRoute?: string;
|
|
9
|
-
messageHandlerKeys?: string[];
|
|
10
|
-
persist?: boolean;
|
|
11
|
-
ssr?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { type AuthConfig, AuthConfigContext, defaultAuthConfig };
|
package/lib/authConfig.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
declare const defaultAuthConfig: AuthConfig;
|
|
4
|
-
declare const AuthConfigContext: React.Context<AuthConfig>;
|
|
5
|
-
interface AuthConfig {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
ensureFreshness?: boolean;
|
|
8
|
-
loginRoute?: string;
|
|
9
|
-
messageHandlerKeys?: string[];
|
|
10
|
-
persist?: boolean;
|
|
11
|
-
ssr?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { type AuthConfig, AuthConfigContext, defaultAuthConfig };
|
package/lib/authConfig.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
|
|
6
|
-
require("./chunk-XEO3YXBM.js");
|
|
7
|
-
exports.AuthConfigContext = _chunkA7UBOIALjs.AuthConfigContext;
|
|
8
|
-
exports.defaultAuthConfig = _chunkA7UBOIALjs.defaultAuthConfig;
|
package/lib/authConfig.mjs
DELETED
package/lib/chunk-2GUOEPFY.mjs
DELETED
|
File without changes
|
package/lib/chunk-3ZPHNEJL.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
|
|
6
|
-
// src/hooks/useAuthConfig.ts
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
function useAuthConfig() {
|
|
9
|
-
return _react.useContext.call(void 0, _chunkA7UBOIALjs.AuthConfigContext);
|
|
10
|
-
}
|
|
11
|
-
exports.useAuthConfig = useAuthConfig;
|
package/lib/chunk-64PPU7Q3.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/authConfig.ts
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
var defaultAuthConfig = {
|
|
4
|
-
ensureFreshness: true,
|
|
5
|
-
persist: false,
|
|
6
|
-
ssr: false
|
|
7
|
-
};
|
|
8
|
-
var AuthConfigContext = createContext(defaultAuthConfig);
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
defaultAuthConfig,
|
|
12
|
-
AuthConfigContext
|
|
13
|
-
};
|
package/lib/chunk-6NDWOV55.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/chunk-7MTPH6XK.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/util.ts
|
|
2
|
-
function validToken(token, refreshToken) {
|
|
3
|
-
if (typeof token !== "string")
|
|
4
|
-
return token;
|
|
5
|
-
if (refreshToken) {
|
|
6
|
-
if (refreshToken === true || isTokenValid(refreshToken))
|
|
7
|
-
return token;
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
return isTokenValid(token) ? token : false;
|
|
11
|
-
}
|
|
12
|
-
function isTokenValid(token) {
|
|
13
|
-
try {
|
|
14
|
-
const { exp } = JSON.parse(Buffer.from(token.split(".")?.[1] || "", "base64").toString() || "{}");
|
|
15
|
-
return Math.floor(Date.now() / 1e3) <= exp;
|
|
16
|
-
} catch (err) {
|
|
17
|
-
if (err instanceof SyntaxError)
|
|
18
|
-
return false;
|
|
19
|
-
throw err;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
validToken,
|
|
25
|
-
isTokenValid
|
|
26
|
-
};
|
package/lib/chunk-A7UBOIAL.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
}); // src/authConfig.ts
|
|
5
|
-
var _react = require("react");
|
|
6
|
-
var defaultAuthConfig = {
|
|
7
|
-
ensureFreshness: true,
|
|
8
|
-
persist: false,
|
|
9
|
-
ssr: false
|
|
10
|
-
};
|
|
11
|
-
var AuthConfigContext = _react.createContext.call(void 0, defaultAuthConfig);
|
|
12
|
-
exports.defaultAuthConfig = defaultAuthConfig;
|
|
13
|
-
exports.AuthConfigContext = AuthConfigContext;
|
package/lib/chunk-AD6VPMID.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/state/index.ts
|
|
2
|
-
import { createStateStore } from "multiplatform.one/zustand";
|
|
3
|
-
import { config } from "app/config";
|
|
4
|
-
var { useStore } = createStateStore(
|
|
5
|
-
"auth",
|
|
6
|
-
{
|
|
7
|
-
idToken: "",
|
|
8
|
-
refreshToken: "",
|
|
9
|
-
token: ""
|
|
10
|
-
},
|
|
11
|
-
void 0,
|
|
12
|
-
{ persist: config.get("KEYCLOAK_PERSIST") === "1" }
|
|
13
|
-
);
|
|
14
|
-
function useAuthState() {
|
|
15
|
-
return useStore();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
useAuthState
|
|
20
|
-
};
|
package/lib/chunk-AUUZ6BI7.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function _define_property(obj, key, value) {
|
|
3
|
-
if (key in obj) {
|
|
4
|
-
Object.defineProperty(obj, key, {
|
|
5
|
-
value: value,
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true
|
|
9
|
-
});
|
|
10
|
-
} else {
|
|
11
|
-
obj[key] = value;
|
|
12
|
-
}
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
function _object_spread(target) {
|
|
16
|
-
for(var i = 1; i < arguments.length; i++){
|
|
17
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
18
|
-
var ownKeys = Object.keys(source);
|
|
19
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
20
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
21
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
ownKeys.forEach(function(key) {
|
|
25
|
-
_define_property(target, key, source[key]);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return target;
|
|
29
|
-
}
|
|
30
|
-
Object.defineProperty(exports, "__esModule", {
|
|
31
|
-
value: true
|
|
32
|
-
});
|
|
33
|
-
function _interopRequireDefault(obj) {
|
|
34
|
-
return obj && obj.__esModule ? obj : {
|
|
35
|
-
default: obj
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
var _chunkKLLABHICjs = require("./chunk-KLLABHIC.js");
|
|
39
|
-
var _chunkMZ6E62HKjs = require("./chunk-MZ6E62HK.js");
|
|
40
|
-
var _chunkUL6L5ONIjs = require("./chunk-UL6L5ONI.js");
|
|
41
|
-
var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
|
|
42
|
-
var _chunkYGNNHTFEjs = require("./chunk-YGNNHTFE.js");
|
|
43
|
-
var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
|
|
44
|
-
// src/Authenticated.tsx
|
|
45
|
-
var _react = require("react");
|
|
46
|
-
var _react2 = _interopRequireDefault(_react);
|
|
47
|
-
function Authenticated(param) {
|
|
48
|
-
var children = param.children, disabled = param.disabled, loginRoute = param.loginRoute, loggedOutComponent = param.loggedOutComponent;
|
|
49
|
-
var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
|
|
50
|
-
var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
|
|
51
|
-
var login = _chunkMZ6E62HKjs.useLogin.call(void 0, loginRoute);
|
|
52
|
-
var tokensFromQuery = _chunkKLLABHICjs.useTokensFromQuery.call(void 0);
|
|
53
|
-
var tokensFromState = _chunkYGNNHTFEjs.useTokensFromState.call(void 0);
|
|
54
|
-
var authenticated = _chunkUL6L5ONIjs.useKeycloak.call(void 0).authenticated;
|
|
55
|
-
_react.useEffect.call(void 0, function() {
|
|
56
|
-
if (authenticated !== false) return;
|
|
57
|
-
if (authConfig.persist) {
|
|
58
|
-
authState.setIdToken("");
|
|
59
|
-
authState.setRefreshToken("");
|
|
60
|
-
authState.setToken("");
|
|
61
|
-
}
|
|
62
|
-
if (typeof window !== "undefined" && !tokensFromQuery && !tokensFromState && window.self === window.top) login();
|
|
63
|
-
}, [
|
|
64
|
-
authenticated
|
|
65
|
-
]);
|
|
66
|
-
if (disabled || authenticated) return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
|
|
67
|
-
var LoggedOutComponent = loggedOutComponent || function() {
|
|
68
|
-
return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, authConfig.debug ? "not authenticated" : null);
|
|
69
|
-
};
|
|
70
|
-
return /* @__PURE__ */ _react2.default.createElement(LoggedOutComponent, null);
|
|
71
|
-
}
|
|
72
|
-
function withAuthenticated(Component) {
|
|
73
|
-
return function(props) {
|
|
74
|
-
return /* @__PURE__ */ _react2.default.createElement(Authenticated, null, /* @__PURE__ */ _react2.default.createElement(Component, _object_spread({}, props)));
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
exports.Authenticated = Authenticated;
|
|
78
|
-
exports.withAuthenticated = withAuthenticated;
|
package/lib/chunk-AYKQVWMR.mjs
DELETED
|
File without changes
|