@multiplatform.one/keycloak 0.3.29 → 0.3.31

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/keycloak",
3
- "version": "0.3.29",
3
+ "version": "0.3.31",
4
4
  "description": "keycloak client for multiplatform.one ecosystem",
5
5
  "main": "dist/lib",
6
6
  "module": "dist/esm",
@@ -4,7 +4,7 @@
4
4
  * File Created: 08-11-2022 06:04:59
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 31-05-2023 12:41:30
7
+ * Last Modified: 31-05-2023 12:49:27
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
10
  * Risser Labs LLC (c) Copyright 2021 - 2022
@@ -30,12 +30,17 @@ import { useKeycloak as useSsrKeycloak } from '@bitspur/react-keycloak-ssr';
30
30
 
31
31
  export function useKeycloak() {
32
32
  const authConfig = useAuthConfig();
33
- if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;
33
+ if (MultiPlatform.isStorybook) {
34
+ return { authenticated: true, username: 'storybook', email: 'storybook@example.com', userId: '0' } as IKeycloak;
35
+ }
34
36
  if (MultiPlatform.isNext && authConfig.ssr) {
35
37
  const { keycloak, initialized } = useSsrKeycloak();
36
38
  return {
37
39
  ...keycloak,
38
40
  authenticated: initialized ? keycloak?.authenticated : undefined,
41
+ email: keycloak?.tokenParsed?.email,
42
+ userId: keycloak?.tokenParsed?.sub,
43
+ username: keycloak?.tokenParsed?.preferred_username,
39
44
  } as IKeycloak;
40
45
  }
41
46
  const { keycloak, initialized } = useReactKeycloak();
@@ -220,6 +220,7 @@ export function KeycloakProvider({
220
220
  if (debug) initOptions.enableLogging = true;
221
221
  if (token && typeof token === 'string') {
222
222
  initOptions.token = token;
223
+ initOptions.timeSkew = 0;
223
224
  if (idToken && typeof idToken === 'string') initOptions.idToken = idToken;
224
225
  if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;
225
226
  }
@@ -227,7 +228,6 @@ export function KeycloakProvider({
227
228
  initOptions.checkLoginIframe = false;
228
229
  initOptions.flow = 'implicit';
229
230
  initOptions.onLoad = undefined;
230
- initOptions.timeSkew = 0;
231
231
  }
232
232
  return initOptions;
233
233
  }, [keycloakInitOptions, token, refreshToken, idToken]);
@@ -238,8 +238,7 @@ export function KeycloakProvider({
238
238
  // @ts-ignore
239
239
  <SSRKeycloakProvider
240
240
  LoadingComponent={<LoadingComponent />}
241
- // keycloak-js already handles refreshing tokens
242
- autoRefreshToken={false}
241
+ autoRefreshToken={initOptions.checkLoginIframe}
243
242
  initOptions={initOptions}
244
243
  onEvent={handleEvent}
245
244
  onTokens={onTokens}
@@ -259,8 +258,7 @@ export function KeycloakProvider({
259
258
  <ReactKeycloakProvider
260
259
  LoadingComponent={<LoadingComponent />}
261
260
  authClient={keycloak}
262
- // keycloak-js already handles refreshing tokens
263
- autoRefreshToken={false}
261
+ autoRefreshToken={initOptions.checkLoginIframe}
264
262
  initOptions={initOptions}
265
263
  onEvent={handleEvent}
266
264
  onTokens={onTokens}