@multiplatform.one/keycloak 0.7.16 → 0.7.17
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/lib/@types/expoKeycloakAuth.d.d.mts +25 -0
- package/lib/@types/expoKeycloakAuth.d.d.ts +25 -0
- package/lib/@types/expoKeycloakAuth.d.js +1 -0
- package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
- package/lib/Authenticated.d.mts +33 -0
- package/lib/Authenticated.d.ts +33 -0
- package/lib/Authenticated.js +20 -0
- package/lib/Authenticated.mjs +20 -0
- package/lib/authConfig.d.mts +12 -0
- package/lib/authConfig.d.ts +12 -0
- package/lib/authConfig.js +9 -0
- package/lib/authConfig.mjs +9 -0
- package/lib/chunk-2BKS6UM5.js +51 -0
- package/lib/chunk-2BSUCVXL.js +50 -0
- package/lib/chunk-2L5TXBDK.mjs +7 -0
- package/lib/chunk-2VDDEPLF.js +27 -0
- package/lib/chunk-32AVT4GA.js +9 -0
- package/lib/chunk-3ZTSLDX7.js +13 -0
- package/lib/chunk-6F4PWJZI.js +1 -0
- package/lib/chunk-6FRYV4MK.mjs +27 -0
- package/lib/chunk-A2V2S4HP.js +22 -0
- package/lib/chunk-BUZONXAW.js +1 -0
- package/lib/chunk-CGLMLNUS.mjs +245 -0
- package/lib/chunk-FU4CT24B.mjs +32 -0
- package/lib/chunk-HH32BME2.mjs +0 -0
- package/lib/chunk-HTWZLBA4.mjs +13 -0
- package/lib/chunk-I5FNGKQ6.js +16 -0
- package/lib/chunk-JAFUI2JQ.mjs +9 -0
- package/lib/chunk-JPQI72HR.mjs +0 -0
- package/lib/chunk-L3HTVJ4B.mjs +13 -0
- package/lib/chunk-MDAAMGTE.js +1 -0
- package/lib/chunk-NH335CDK.js +32 -0
- package/lib/chunk-OA5TSQWZ.mjs +50 -0
- package/lib/chunk-OAUYHIWG.mjs +0 -0
- package/lib/chunk-OBB23GPX.mjs +0 -0
- package/lib/chunk-OZLV3US5.js +245 -0
- package/lib/chunk-P57PW2II.js +11 -0
- package/lib/chunk-TUJRPTZE.js +13 -0
- package/lib/chunk-UESWAK47.mjs +0 -0
- package/lib/chunk-UH4K7HGE.mjs +163 -0
- package/lib/chunk-UKSHA3X3.mjs +16 -0
- package/lib/chunk-VS4M7GMO.js +1 -0
- package/lib/chunk-WBQAMGXK.mjs +0 -0
- package/lib/chunk-WMH347OL.mjs +22 -0
- package/lib/chunk-WS4IMGVL.js +1 -0
- package/lib/chunk-X53FOCXA.js +28 -0
- package/lib/chunk-Y23BWOII.mjs +51 -0
- package/lib/chunk-Y5MS3XVZ.mjs +28 -0
- package/lib/chunk-YACGLW5Q.js +7 -0
- package/lib/chunk-ZCBD6HWK.js +1 -0
- package/lib/chunk-ZFXKCRJC.mjs +11 -0
- package/lib/chunk-ZW4GP2I5.js +163 -0
- package/lib/hooks/index.d.mts +5 -0
- package/lib/hooks/index.d.ts +5 -0
- package/lib/hooks/index.js +19 -0
- package/lib/hooks/index.mjs +19 -0
- package/lib/hooks/useAuthConfig.d.mts +6 -0
- package/lib/hooks/useAuthConfig.d.ts +6 -0
- package/lib/hooks/useAuthConfig.js +8 -0
- package/lib/hooks/useAuthConfig.mjs +8 -0
- package/lib/hooks/useTokensFromQuery/index.d.mts +3 -0
- package/lib/hooks/useTokensFromQuery/index.d.ts +3 -0
- package/lib/hooks/useTokensFromQuery/index.js +7 -0
- package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
- package/lib/hooks/useTokensFromQuery/index.native.d.mts +3 -0
- package/lib/hooks/useTokensFromQuery/index.native.d.ts +3 -0
- package/lib/hooks/useTokensFromQuery/index.native.js +7 -0
- package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
- package/lib/hooks/useTokensFromState.d.mts +3 -0
- package/lib/hooks/useTokensFromState.d.ts +3 -0
- package/lib/hooks/useTokensFromState.js +9 -0
- package/lib/hooks/useTokensFromState.mjs +9 -0
- package/lib/index.d.mts +16 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +62 -0
- package/lib/index.mjs +62 -0
- package/lib/keycloak/context.d.mts +12 -0
- package/lib/keycloak/context.d.ts +12 -0
- package/lib/keycloak/context.js +7 -0
- package/lib/keycloak/context.mjs +7 -0
- package/lib/keycloak/index.d.mts +7 -0
- package/lib/keycloak/index.d.ts +7 -0
- package/lib/keycloak/index.js +14 -0
- package/lib/keycloak/index.mjs +14 -0
- package/lib/keycloak/keycloak.d.mts +37 -0
- package/lib/keycloak/keycloak.d.ts +37 -0
- package/lib/keycloak/keycloak.js +13 -0
- package/lib/keycloak/keycloak.mjs +13 -0
- package/lib/keycloak/keycloak.native.d.mts +33 -0
- package/lib/keycloak/keycloak.native.d.ts +33 -0
- package/lib/keycloak/keycloak.native.js +134 -0
- package/lib/keycloak/keycloak.native.mjs +134 -0
- package/lib/provider/AfterAuth.d.mts +28 -0
- package/lib/provider/AfterAuth.d.ts +28 -0
- package/lib/provider/AfterAuth.js +18 -0
- package/lib/provider/AfterAuth.mjs +18 -0
- package/lib/provider/AuthProvider/AuthProvider.d.mts +37 -0
- package/lib/provider/AuthProvider/AuthProvider.d.ts +37 -0
- package/lib/provider/AuthProvider/AuthProvider.js +19 -0
- package/lib/provider/AuthProvider/AuthProvider.mjs +19 -0
- package/lib/provider/AuthProvider/AuthProvider.native.d.mts +29 -0
- package/lib/provider/AuthProvider/AuthProvider.native.d.ts +29 -0
- package/lib/provider/AuthProvider/AuthProvider.native.js +25 -0
- package/lib/provider/AuthProvider/AuthProvider.native.mjs +25 -0
- package/lib/provider/AuthProvider/index.d.mts +4 -0
- package/lib/provider/AuthProvider/index.d.ts +4 -0
- package/lib/provider/AuthProvider/index.js +20 -0
- package/lib/provider/AuthProvider/index.mjs +20 -0
- package/lib/provider/KeycloakProvider.d.mts +34 -0
- package/lib/provider/KeycloakProvider.d.ts +34 -0
- package/lib/provider/KeycloakProvider.js +21 -0
- package/lib/provider/KeycloakProvider.mjs +21 -0
- package/lib/provider/index.d.mts +8 -0
- package/lib/provider/index.d.ts +8 -0
- package/lib/provider/index.js +28 -0
- package/lib/provider/index.mjs +28 -0
- package/lib/routes.d.mts +28 -0
- package/lib/routes.d.ts +28 -0
- package/lib/routes.js +127 -0
- package/lib/routes.mjs +127 -0
- package/lib/session/index.d.mts +3 -0
- package/lib/session/index.d.ts +3 -0
- package/lib/session/index.js +10 -0
- package/lib/session/index.mjs +10 -0
- package/lib/session/session.d.mts +18 -0
- package/lib/session/session.d.ts +18 -0
- package/lib/session/session.js +9 -0
- package/lib/session/session.mjs +9 -0
- package/lib/session/session.native.d.mts +8 -0
- package/lib/session/session.native.d.ts +8 -0
- package/lib/session/session.native.js +13 -0
- package/lib/session/session.native.mjs +13 -0
- package/lib/state.d.mts +12 -0
- package/lib/state.d.ts +12 -0
- package/lib/state.js +9 -0
- package/lib/state.mjs +9 -0
- package/lib/token.d.mts +17 -0
- package/lib/token.d.ts +17 -0
- package/lib/token.js +9 -0
- package/lib/token.mjs +9 -0
- package/lib/types.d.mts +20 -0
- package/lib/types.d.ts +20 -0
- package/lib/types.js +1 -0
- package/lib/types.mjs +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/hooks/useTokensFromQuery/index.ts
|
|
2
|
+
var _multiplatformone = require('multiplatform.one');
|
|
3
|
+
var _router = require('next/router');
|
|
4
|
+
function useTokensFromQuery() {
|
|
5
|
+
if (!_multiplatformone.MultiPlatform.isIframe)
|
|
6
|
+
return false;
|
|
7
|
+
const { query } = _multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0, ) : { query: {} };
|
|
8
|
+
return "idToken" in query || "token" in query || "refreshToken" in query;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.useTokensFromQuery = useTokensFromQuery;
|
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeycloakContext
|
|
3
|
+
} from "./chunk-2L5TXBDK.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getSession,
|
|
6
|
+
useSession
|
|
7
|
+
} from "./chunk-FU4CT24B.mjs";
|
|
8
|
+
|
|
9
|
+
// src/keycloak/keycloak.ts
|
|
10
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
11
|
+
import { jwtDecode } from "jwt-decode";
|
|
12
|
+
import { signIn, signOut } from "next-auth/react";
|
|
13
|
+
import { useContext } from "react";
|
|
14
|
+
var Keycloak = class {
|
|
15
|
+
token;
|
|
16
|
+
idToken;
|
|
17
|
+
refreshToken;
|
|
18
|
+
_idTokenParsed;
|
|
19
|
+
_refreshTokenParsed;
|
|
20
|
+
_tokenParsed;
|
|
21
|
+
keycloakClient;
|
|
22
|
+
mock;
|
|
23
|
+
constructor(input, idToken, refreshToken) {
|
|
24
|
+
if (typeof input === "string") {
|
|
25
|
+
this.token = input;
|
|
26
|
+
this.idToken = idToken;
|
|
27
|
+
this.refreshToken = refreshToken;
|
|
28
|
+
} else if (typeof input === "object") {
|
|
29
|
+
if (typeof input.init === "function") {
|
|
30
|
+
this.keycloakClient = input;
|
|
31
|
+
} else if (input.accessToken) {
|
|
32
|
+
const session = input;
|
|
33
|
+
this.token = session.accessToken;
|
|
34
|
+
this.idToken = session.idToken;
|
|
35
|
+
this.refreshToken = session.refreshToken;
|
|
36
|
+
} else {
|
|
37
|
+
this.mock = input;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (this.token && !this._tokenParsed)
|
|
41
|
+
this._tokenParsed = jwtDecode(this.token);
|
|
42
|
+
if (this.idToken && !this._idTokenParsed)
|
|
43
|
+
this._idTokenParsed = jwtDecode(this.idToken);
|
|
44
|
+
if (this.refreshToken && !this._refreshTokenParsed) {
|
|
45
|
+
this._refreshTokenParsed = jwtDecode(this.refreshToken);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get tokenParsed() {
|
|
49
|
+
if (this.keycloakClient)
|
|
50
|
+
return this.keycloakClient.tokenParsed;
|
|
51
|
+
return this._tokenParsed;
|
|
52
|
+
}
|
|
53
|
+
get idTokenParsed() {
|
|
54
|
+
if (this.keycloakClient)
|
|
55
|
+
return this.keycloakClient.idTokenParsed;
|
|
56
|
+
return this._idTokenParsed;
|
|
57
|
+
}
|
|
58
|
+
get refreshTokenParsed() {
|
|
59
|
+
if (this.keycloakClient)
|
|
60
|
+
return this.keycloakClient.refreshTokenParsed;
|
|
61
|
+
return this._refreshTokenParsed;
|
|
62
|
+
}
|
|
63
|
+
get clientId() {
|
|
64
|
+
if (this.keycloakClient)
|
|
65
|
+
return this.keycloakClient.clientId;
|
|
66
|
+
return this.tokenParsed?.azp;
|
|
67
|
+
}
|
|
68
|
+
get email() {
|
|
69
|
+
if (this.keycloakClient)
|
|
70
|
+
return this.keycloakClient.tokenParsed?.email;
|
|
71
|
+
if (this.mock)
|
|
72
|
+
return this.mock.email;
|
|
73
|
+
return this.tokenParsed?.email;
|
|
74
|
+
}
|
|
75
|
+
get realm() {
|
|
76
|
+
if (this.keycloakClient)
|
|
77
|
+
return this.keycloakClient.realm;
|
|
78
|
+
return this.tokenParsed?.iss?.split("/").pop();
|
|
79
|
+
}
|
|
80
|
+
get realmAccess() {
|
|
81
|
+
if (this.keycloakClient)
|
|
82
|
+
return this.keycloakClient.realmAccess;
|
|
83
|
+
return this.tokenParsed?.realm_access;
|
|
84
|
+
}
|
|
85
|
+
get resourceAccess() {
|
|
86
|
+
if (this.keycloakClient)
|
|
87
|
+
return this.keycloakClient.resourceAccess;
|
|
88
|
+
return this.tokenParsed?.resource_access;
|
|
89
|
+
}
|
|
90
|
+
get sessionId() {
|
|
91
|
+
if (this.keycloakClient)
|
|
92
|
+
return this.keycloakClient.sessionId;
|
|
93
|
+
return this.tokenParsed?.session_state;
|
|
94
|
+
}
|
|
95
|
+
get subject() {
|
|
96
|
+
if (this.keycloakClient)
|
|
97
|
+
return this.keycloakClient.subject;
|
|
98
|
+
return this.tokenParsed?.sub;
|
|
99
|
+
}
|
|
100
|
+
get username() {
|
|
101
|
+
if (this.mock)
|
|
102
|
+
return this.mock.username;
|
|
103
|
+
return this.tokenParsed?.preferred_username;
|
|
104
|
+
}
|
|
105
|
+
async login(options = {}) {
|
|
106
|
+
if (this.keycloakClient) {
|
|
107
|
+
await this.keycloakClient.login(options);
|
|
108
|
+
} else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
|
|
109
|
+
await signIn("keycloak", {
|
|
110
|
+
callbackUrl: options.redirectUri
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async logout(options = {}) {
|
|
115
|
+
if (this.keycloakClient) {
|
|
116
|
+
await this.keycloakClient.logout(options);
|
|
117
|
+
} else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
|
|
118
|
+
await fetch("/api/auth/logout", { method: "GET" });
|
|
119
|
+
await signOut({
|
|
120
|
+
callbackUrl: options.redirectUri
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
get authenticated() {
|
|
125
|
+
if (this.mock)
|
|
126
|
+
return true;
|
|
127
|
+
if (this.keycloakClient)
|
|
128
|
+
return !!this.keycloakClient.authenticated;
|
|
129
|
+
if (!this.tokenParsed?.exp || !this.idToken)
|
|
130
|
+
return false;
|
|
131
|
+
return this.tokenParsed.exp > Date.now() / 1e3;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function useKeycloak() {
|
|
135
|
+
const keycloak = useContext(KeycloakContext);
|
|
136
|
+
if (keycloak)
|
|
137
|
+
return keycloak;
|
|
138
|
+
const { session, status } = useSession();
|
|
139
|
+
if (MultiPlatform.isServer)
|
|
140
|
+
return;
|
|
141
|
+
if (MultiPlatform.isStorybook) {
|
|
142
|
+
return new Keycloak({
|
|
143
|
+
email: "storybook@example.com",
|
|
144
|
+
username: "storybook"
|
|
145
|
+
});
|
|
146
|
+
} else if (status === "unauthenticated") {
|
|
147
|
+
return new Keycloak();
|
|
148
|
+
} else if (status === "authenticated" && session?.accessToken) {
|
|
149
|
+
return new Keycloak(session);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function getKeycloak() {
|
|
153
|
+
const session = await getSession();
|
|
154
|
+
if (session?.accessToken)
|
|
155
|
+
return new Keycloak(session);
|
|
156
|
+
return new Keycloak();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export {
|
|
160
|
+
Keycloak,
|
|
161
|
+
useKeycloak,
|
|
162
|
+
getKeycloak
|
|
163
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuthState
|
|
3
|
+
} from "./chunk-WMH347OL.mjs";
|
|
4
|
+
import {
|
|
5
|
+
validToken
|
|
6
|
+
} from "./chunk-6FRYV4MK.mjs";
|
|
7
|
+
|
|
8
|
+
// src/hooks/useTokensFromState.ts
|
|
9
|
+
function useTokensFromState() {
|
|
10
|
+
const authState = useAuthState();
|
|
11
|
+
return !!validToken(authState.token, authState.refreshToken);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
useTokensFromState
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/state.ts
|
|
2
|
+
import { createStateStore } from "multiplatform.one/zustand";
|
|
3
|
+
import { MultiPlatform } from "multiplatform.one";
|
|
4
|
+
var persist = MultiPlatform.isIframe || !MultiPlatform.isNext && !MultiPlatform.isServer;
|
|
5
|
+
var { useStore } = createStateStore(
|
|
6
|
+
"auth",
|
|
7
|
+
{
|
|
8
|
+
idToken: "",
|
|
9
|
+
refreshToken: "",
|
|
10
|
+
token: ""
|
|
11
|
+
},
|
|
12
|
+
void 0,
|
|
13
|
+
{ persist }
|
|
14
|
+
);
|
|
15
|
+
function useAuthState() {
|
|
16
|
+
return useStore();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
persist,
|
|
21
|
+
useAuthState
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkOZLV3US5js = require('./chunk-OZLV3US5.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk32AVT4GAjs = require('./chunk-32AVT4GA.js');
|
|
7
|
+
|
|
8
|
+
// src/provider/KeycloakProvider.tsx
|
|
9
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
10
|
+
function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }) {
|
|
11
|
+
const authConfig = _react.useMemo.call(void 0, () => ({ debug }), [debug]);
|
|
12
|
+
return /* @__PURE__ */ _react2.default.createElement(_chunk32AVT4GAjs.AuthConfigContext.Provider, { value: authConfig }, /* @__PURE__ */ _react2.default.createElement(
|
|
13
|
+
_chunkOZLV3US5js.AuthProvider,
|
|
14
|
+
{
|
|
15
|
+
sessionProvider: { session },
|
|
16
|
+
keycloakConfig: {
|
|
17
|
+
realm: realm || "main",
|
|
18
|
+
clientId: clientId || "app",
|
|
19
|
+
url: baseUrl
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
children
|
|
23
|
+
));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.KeycloakProvider = KeycloakProvider;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuthConfig
|
|
3
|
+
} from "./chunk-HTWZLBA4.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useKeycloak
|
|
6
|
+
} from "./chunk-UH4K7HGE.mjs";
|
|
7
|
+
import {
|
|
8
|
+
persist,
|
|
9
|
+
useAuthState
|
|
10
|
+
} from "./chunk-WMH347OL.mjs";
|
|
11
|
+
|
|
12
|
+
// src/provider/AfterAuth.tsx
|
|
13
|
+
import React, { useEffect } from "react";
|
|
14
|
+
var logger = console;
|
|
15
|
+
function AfterAuth({ children }) {
|
|
16
|
+
const authConfig = useAuthConfig();
|
|
17
|
+
const authState = useAuthState();
|
|
18
|
+
const keycloak = useKeycloak();
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!persist || !keycloak?.authenticated)
|
|
21
|
+
return;
|
|
22
|
+
if (keycloak.token) {
|
|
23
|
+
authState.setToken(keycloak.token);
|
|
24
|
+
if (keycloak.idToken)
|
|
25
|
+
authState.setIdToken(keycloak.idToken);
|
|
26
|
+
if (keycloak.refreshToken)
|
|
27
|
+
authState.setRefreshToken(keycloak.refreshToken);
|
|
28
|
+
}
|
|
29
|
+
}, [keycloak?.authenticated, keycloak?.token, keycloak?.idToken, keycloak?.refreshToken]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (authConfig.debug && keycloak?.token)
|
|
32
|
+
logger.debug("token", keycloak.token);
|
|
33
|
+
}, [keycloak?.token]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (authConfig.debug && keycloak?.idToken)
|
|
36
|
+
logger.debug("idToken", keycloak.idToken);
|
|
37
|
+
}, [keycloak?.idToken]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (authConfig.debug && keycloak?.refreshToken)
|
|
40
|
+
logger.debug("refreshToken", keycloak.refreshToken);
|
|
41
|
+
}, [keycloak?.refreshToken]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (keycloak?.authenticated)
|
|
44
|
+
logger.debug("authenticated", keycloak.authenticated);
|
|
45
|
+
}, [keycloak?.authenticated]);
|
|
46
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
AfterAuth
|
|
51
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthProvider
|
|
3
|
+
} from "./chunk-CGLMLNUS.mjs";
|
|
4
|
+
import {
|
|
5
|
+
AuthConfigContext
|
|
6
|
+
} from "./chunk-JAFUI2JQ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/provider/KeycloakProvider.tsx
|
|
9
|
+
import React, { useMemo } from "react";
|
|
10
|
+
function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }) {
|
|
11
|
+
const authConfig = useMemo(() => ({ debug }), [debug]);
|
|
12
|
+
return /* @__PURE__ */ React.createElement(AuthConfigContext.Provider, { value: authConfig }, /* @__PURE__ */ React.createElement(
|
|
13
|
+
AuthProvider,
|
|
14
|
+
{
|
|
15
|
+
sessionProvider: { session },
|
|
16
|
+
keycloakConfig: {
|
|
17
|
+
realm: realm || "main",
|
|
18
|
+
clientId: clientId || "app",
|
|
19
|
+
url: baseUrl
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
children
|
|
23
|
+
));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
KeycloakProvider
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
__require
|
|
11
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkYACGLW5Qjs = require('./chunk-YACGLW5Q.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkNH335CDKjs = require('./chunk-NH335CDK.js');
|
|
8
|
+
|
|
9
|
+
// src/keycloak/keycloak.ts
|
|
10
|
+
var _multiplatformone = require('multiplatform.one');
|
|
11
|
+
var _jwtdecode = require('jwt-decode');
|
|
12
|
+
var _react = require('next-auth/react');
|
|
13
|
+
var _react3 = require('react');
|
|
14
|
+
var Keycloak = class {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
constructor(input, idToken, refreshToken) {
|
|
24
|
+
if (typeof input === "string") {
|
|
25
|
+
this.token = input;
|
|
26
|
+
this.idToken = idToken;
|
|
27
|
+
this.refreshToken = refreshToken;
|
|
28
|
+
} else if (typeof input === "object") {
|
|
29
|
+
if (typeof input.init === "function") {
|
|
30
|
+
this.keycloakClient = input;
|
|
31
|
+
} else if (input.accessToken) {
|
|
32
|
+
const session = input;
|
|
33
|
+
this.token = session.accessToken;
|
|
34
|
+
this.idToken = session.idToken;
|
|
35
|
+
this.refreshToken = session.refreshToken;
|
|
36
|
+
} else {
|
|
37
|
+
this.mock = input;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (this.token && !this._tokenParsed)
|
|
41
|
+
this._tokenParsed = _jwtdecode.jwtDecode.call(void 0, this.token);
|
|
42
|
+
if (this.idToken && !this._idTokenParsed)
|
|
43
|
+
this._idTokenParsed = _jwtdecode.jwtDecode.call(void 0, this.idToken);
|
|
44
|
+
if (this.refreshToken && !this._refreshTokenParsed) {
|
|
45
|
+
this._refreshTokenParsed = _jwtdecode.jwtDecode.call(void 0, this.refreshToken);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get tokenParsed() {
|
|
49
|
+
if (this.keycloakClient)
|
|
50
|
+
return this.keycloakClient.tokenParsed;
|
|
51
|
+
return this._tokenParsed;
|
|
52
|
+
}
|
|
53
|
+
get idTokenParsed() {
|
|
54
|
+
if (this.keycloakClient)
|
|
55
|
+
return this.keycloakClient.idTokenParsed;
|
|
56
|
+
return this._idTokenParsed;
|
|
57
|
+
}
|
|
58
|
+
get refreshTokenParsed() {
|
|
59
|
+
if (this.keycloakClient)
|
|
60
|
+
return this.keycloakClient.refreshTokenParsed;
|
|
61
|
+
return this._refreshTokenParsed;
|
|
62
|
+
}
|
|
63
|
+
get clientId() {
|
|
64
|
+
if (this.keycloakClient)
|
|
65
|
+
return this.keycloakClient.clientId;
|
|
66
|
+
return _optionalChain([this, 'access', _ => _.tokenParsed, 'optionalAccess', _2 => _2.azp]);
|
|
67
|
+
}
|
|
68
|
+
get email() {
|
|
69
|
+
if (this.keycloakClient)
|
|
70
|
+
return _optionalChain([this, 'access', _3 => _3.keycloakClient, 'access', _4 => _4.tokenParsed, 'optionalAccess', _5 => _5.email]);
|
|
71
|
+
if (this.mock)
|
|
72
|
+
return this.mock.email;
|
|
73
|
+
return _optionalChain([this, 'access', _6 => _6.tokenParsed, 'optionalAccess', _7 => _7.email]);
|
|
74
|
+
}
|
|
75
|
+
get realm() {
|
|
76
|
+
if (this.keycloakClient)
|
|
77
|
+
return this.keycloakClient.realm;
|
|
78
|
+
return _optionalChain([this, 'access', _8 => _8.tokenParsed, 'optionalAccess', _9 => _9.iss, 'optionalAccess', _10 => _10.split, 'call', _11 => _11("/"), 'access', _12 => _12.pop, 'call', _13 => _13()]);
|
|
79
|
+
}
|
|
80
|
+
get realmAccess() {
|
|
81
|
+
if (this.keycloakClient)
|
|
82
|
+
return this.keycloakClient.realmAccess;
|
|
83
|
+
return _optionalChain([this, 'access', _14 => _14.tokenParsed, 'optionalAccess', _15 => _15.realm_access]);
|
|
84
|
+
}
|
|
85
|
+
get resourceAccess() {
|
|
86
|
+
if (this.keycloakClient)
|
|
87
|
+
return this.keycloakClient.resourceAccess;
|
|
88
|
+
return _optionalChain([this, 'access', _16 => _16.tokenParsed, 'optionalAccess', _17 => _17.resource_access]);
|
|
89
|
+
}
|
|
90
|
+
get sessionId() {
|
|
91
|
+
if (this.keycloakClient)
|
|
92
|
+
return this.keycloakClient.sessionId;
|
|
93
|
+
return _optionalChain([this, 'access', _18 => _18.tokenParsed, 'optionalAccess', _19 => _19.session_state]);
|
|
94
|
+
}
|
|
95
|
+
get subject() {
|
|
96
|
+
if (this.keycloakClient)
|
|
97
|
+
return this.keycloakClient.subject;
|
|
98
|
+
return _optionalChain([this, 'access', _20 => _20.tokenParsed, 'optionalAccess', _21 => _21.sub]);
|
|
99
|
+
}
|
|
100
|
+
get username() {
|
|
101
|
+
if (this.mock)
|
|
102
|
+
return this.mock.username;
|
|
103
|
+
return _optionalChain([this, 'access', _22 => _22.tokenParsed, 'optionalAccess', _23 => _23.preferred_username]);
|
|
104
|
+
}
|
|
105
|
+
async login(options = {}) {
|
|
106
|
+
if (this.keycloakClient) {
|
|
107
|
+
await this.keycloakClient.login(options);
|
|
108
|
+
} else if (_multiplatformone.MultiPlatform.isNext && !_multiplatformone.MultiPlatform.isServer) {
|
|
109
|
+
await _react.signIn.call(void 0, "keycloak", {
|
|
110
|
+
callbackUrl: options.redirectUri
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async logout(options = {}) {
|
|
115
|
+
if (this.keycloakClient) {
|
|
116
|
+
await this.keycloakClient.logout(options);
|
|
117
|
+
} else if (_multiplatformone.MultiPlatform.isNext && !_multiplatformone.MultiPlatform.isServer) {
|
|
118
|
+
await fetch("/api/auth/logout", { method: "GET" });
|
|
119
|
+
await _react.signOut.call(void 0, {
|
|
120
|
+
callbackUrl: options.redirectUri
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
get authenticated() {
|
|
125
|
+
if (this.mock)
|
|
126
|
+
return true;
|
|
127
|
+
if (this.keycloakClient)
|
|
128
|
+
return !!this.keycloakClient.authenticated;
|
|
129
|
+
if (!_optionalChain([this, 'access', _24 => _24.tokenParsed, 'optionalAccess', _25 => _25.exp]) || !this.idToken)
|
|
130
|
+
return false;
|
|
131
|
+
return this.tokenParsed.exp > Date.now() / 1e3;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function useKeycloak() {
|
|
135
|
+
const keycloak = _react3.useContext.call(void 0, _chunkYACGLW5Qjs.KeycloakContext);
|
|
136
|
+
if (keycloak)
|
|
137
|
+
return keycloak;
|
|
138
|
+
const { session, status } = _chunkNH335CDKjs.useSession.call(void 0, );
|
|
139
|
+
if (_multiplatformone.MultiPlatform.isServer)
|
|
140
|
+
return;
|
|
141
|
+
if (_multiplatformone.MultiPlatform.isStorybook) {
|
|
142
|
+
return new Keycloak({
|
|
143
|
+
email: "storybook@example.com",
|
|
144
|
+
username: "storybook"
|
|
145
|
+
});
|
|
146
|
+
} else if (status === "unauthenticated") {
|
|
147
|
+
return new Keycloak();
|
|
148
|
+
} else if (status === "authenticated" && _optionalChain([session, 'optionalAccess', _26 => _26.accessToken])) {
|
|
149
|
+
return new Keycloak(session);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function getKeycloak() {
|
|
153
|
+
const session = await _chunkNH335CDKjs.getSession.call(void 0, );
|
|
154
|
+
if (_optionalChain([session, 'optionalAccess', _27 => _27.accessToken]))
|
|
155
|
+
return new Keycloak(session);
|
|
156
|
+
return new Keycloak();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
exports.Keycloak = Keycloak; exports.useKeycloak = useKeycloak; exports.getKeycloak = getKeycloak;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-ZCBD6HWK.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkTUJRPTZEjs = require('../chunk-TUJRPTZE.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunk3ZTSLDX7js = require('../chunk-3ZTSLDX7.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkI5FNGKQ6js = require('../chunk-I5FNGKQ6.js');
|
|
11
|
+
require('../chunk-32AVT4GA.js');
|
|
12
|
+
require('../chunk-A2V2S4HP.js');
|
|
13
|
+
require('../chunk-2VDDEPLF.js');
|
|
14
|
+
require('../chunk-P57PW2II.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.useAuthConfig = _chunk3ZTSLDX7js.useAuthConfig; exports.useTokensFromQuery = _chunkTUJRPTZEjs.useTokensFromQuery; exports.useTokensFromState = _chunkI5FNGKQ6js.useTokensFromState;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "../chunk-HH32BME2.mjs";
|
|
2
|
+
import {
|
|
3
|
+
useTokensFromQuery
|
|
4
|
+
} from "../chunk-L3HTVJ4B.mjs";
|
|
5
|
+
import {
|
|
6
|
+
useAuthConfig
|
|
7
|
+
} from "../chunk-HTWZLBA4.mjs";
|
|
8
|
+
import {
|
|
9
|
+
useTokensFromState
|
|
10
|
+
} from "../chunk-UKSHA3X3.mjs";
|
|
11
|
+
import "../chunk-JAFUI2JQ.mjs";
|
|
12
|
+
import "../chunk-WMH347OL.mjs";
|
|
13
|
+
import "../chunk-6FRYV4MK.mjs";
|
|
14
|
+
import "../chunk-ZFXKCRJC.mjs";
|
|
15
|
+
export {
|
|
16
|
+
useAuthConfig,
|
|
17
|
+
useTokensFromQuery,
|
|
18
|
+
useTokensFromState
|
|
19
|
+
};
|