@open-pioneer/authentication-keycloak 4.8.0 → 4.9.0-dev.20261002130116

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @open-pioneer/authentication-keycloak
2
2
 
3
+ ## 4.9.0-dev.20261002130116
4
+
5
+ ### Patch Changes
6
+
7
+ - 6b160f3: A few minor fixes while cleaning up the code:
8
+ - The plugin reads the notification texts from `currentIntl`, so it no longer triggers the `ServiceOptions.intl` deprecation warning.
9
+ - The plugin no longer starts the token refresh timer or shows a notification when the service was destroyed while `keycloak.init()` was still pending.
10
+
3
11
  ## 4.8.0
4
12
 
5
13
  ### Minor Changes
@@ -62,53 +70,53 @@
62
70
 
63
71
  - f67fd7e: Support configuration of keycloak's login options and logout options.
64
72
 
65
- For example, to redirect to a different site after logout:
66
-
67
- ```ts
68
- // app.ts
69
- const element = createCustomElement({
70
- component: AppUI,
71
- appMetadata,
72
- config: {
73
- properties: {
74
- "@open-pioneer/authentication-keycloak": {
75
- keycloakOptions: {
76
- // ...
77
- keycloakLogoutOptions: {
78
- redirectUri: "https://example.com"
79
- }
80
- }
81
- } satisfies KeycloakProperties
82
- }
83
- }
84
- });
85
- ```
86
-
87
- The plugin also supports options for the `logout` method to supply dynamic logout options:
88
-
89
- ```ts
90
- // via auth service
91
- const authService = ...;
92
- authService.logout({
93
- // These are passed directly the keycloak plugin (if it is being used).
94
- pluginOptions: {
95
- redirectUri: "https://example.com",
96
- }
97
- })
98
-
99
- // via direct reference to the plugin ("authentication-keycloak.KeycloakAuthPlugin")
100
- const keycloakAuthPlugin = ...;
101
- keycloakAuthPlugin.logout({
102
- redirectUri: "https://example.com",
103
- });
104
- ```
73
+ For example, to redirect to a different site after logout:
74
+
75
+ ```ts
76
+ // app.ts
77
+ const element = createCustomElement({
78
+ component: AppUI,
79
+ appMetadata,
80
+ config: {
81
+ properties: {
82
+ "@open-pioneer/authentication-keycloak": {
83
+ keycloakOptions: {
84
+ // ...
85
+ keycloakLogoutOptions: {
86
+ redirectUri: "https://example.com",
87
+ },
88
+ },
89
+ } satisfies KeycloakProperties,
90
+ },
91
+ },
92
+ });
93
+ ```
94
+
95
+ The plugin also supports options for the `logout` method to supply dynamic logout options:
96
+
97
+ ```ts
98
+ // via auth service
99
+ const authService = ...;
100
+ authService.logout({
101
+ // These are passed directly the keycloak plugin (if it is being used).
102
+ pluginOptions: {
103
+ redirectUri: "https://example.com",
104
+ }
105
+ })
106
+
107
+ // via direct reference to the plugin ("authentication-keycloak.KeycloakAuthPlugin")
108
+ const keycloakAuthPlugin = ...;
109
+ keycloakAuthPlugin.logout({
110
+ redirectUri: "https://example.com",
111
+ });
112
+ ```
105
113
 
106
114
  - f67fd7e: Make `RefreshOptions` optional with sensible default values. The default values have been changed to:
107
- - `autoRefresh`: true
108
- - `interval` (for token lifetime checks): 10 seconds
109
- - `timeLeft`: 60 seconds (minimum required lifetime during token validity checks)
115
+ - `autoRefresh`: true
116
+ - `interval` (for token lifetime checks): 10 seconds
117
+ - `timeLeft`: 60 seconds (minimum required lifetime during token validity checks)
110
118
 
111
- These values are used when they are not explicitly configured using package properties.
119
+ These values are used when they are not explicitly configured using package properties.
112
120
 
113
121
  ### Patch Changes
114
122
 
@@ -132,13 +140,13 @@
132
140
  ### Major Changes
133
141
 
134
142
  - 9477e54: Update dependencies
135
- - React 19
136
- - Vite 6
137
- - FormatJS 3
138
- - Open Pioneer Build Tools
139
- - ...
143
+ - React 19
144
+ - Vite 6
145
+ - FormatJS 3
146
+ - Open Pioneer Build Tools
147
+ - ...
140
148
 
141
- For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
149
+ For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
142
150
 
143
151
  ## 2.4.0
144
152
 
@@ -146,39 +154,39 @@
146
154
 
147
155
  - 1ce5f11: Replace change events for auth state with signals from Reactivity API
148
156
 
149
- Example: watch for updates of the auth state
150
-
151
- ```typescript
152
- const myAuthService = ...
153
- watch(
154
- () => [myAuthService.getAuthState()],
155
- ([state]) => {
156
- console.log(state);
157
- },
158
- {
159
- immediate: true
160
- }
161
- );
162
- ```
163
-
164
- The Auth Service forwards the auth state from the underlying AuthPlugin.
165
- Therefore, the plugin implementation must use reactive signals when its auth state changes in order to signal changes to the service.
166
-
167
- ```typescript
168
- class DummyPlugin implements AuthPlugin {
169
- #state = reactive<AuthState>({
170
- kind: "not-authenticated"
171
- });
172
-
173
- getAuthState(): AuthState {
174
- return this.#state.value;
175
- }
176
-
177
- $setAuthState(newState: AuthState) {
178
- this.#state.value = newState;
179
- }
157
+ Example: watch for updates of the auth state
158
+
159
+ ```typescript
160
+ const myAuthService = ...
161
+ watch(
162
+ () => [myAuthService.getAuthState()],
163
+ ([state]) => {
164
+ console.log(state);
165
+ },
166
+ {
167
+ immediate: true
168
+ }
169
+ );
170
+ ```
171
+
172
+ The Auth Service forwards the auth state from the underlying AuthPlugin.
173
+ Therefore, the plugin implementation must use reactive signals when its auth state changes in order to signal changes to the service.
174
+
175
+ ```typescript
176
+ class DummyPlugin implements AuthPlugin {
177
+ #state = reactive<AuthState>({
178
+ kind: "not-authenticated",
179
+ });
180
+
181
+ getAuthState(): AuthState {
182
+ return this.#state.value;
183
+ }
184
+
185
+ $setAuthState(newState: AuthState) {
186
+ this.#state.value = newState;
180
187
  }
181
- ```
188
+ }
189
+ ```
182
190
 
183
191
  ### Patch Changes
184
192
 
@@ -1,5 +1,5 @@
1
1
  import { reactive } from '@conterra/reactivity-core';
2
- import { createLogger, destroyResource } from '@open-pioneer/core';
2
+ import { createLogger } from '@open-pioneer/core';
3
3
  import Keycloak from 'keycloak-js';
4
4
  import { sourceId$1 as sourceId } from './_virtual/source-info.js';
5
5
  import { getKeycloakConfig } from './getKeycloakConfig.js';
@@ -7,18 +7,17 @@ import { getKeycloakConfig } from './getKeycloakConfig.js';
7
7
  const LOG = createLogger(sourceId);
8
8
  class KeycloakAuthPluginImpl {
9
9
  #notifier;
10
- #intl;
10
+ #currentIntl;
11
11
  #keycloakOptions;
12
12
  #keycloak;
13
- // oxlint-disable-next-line @typescript-eslint/no-explicit-any
14
13
  #timerId;
15
- #watcher;
14
+ #destroyed = false;
16
15
  #state = reactive({
17
16
  kind: "pending"
18
17
  });
19
18
  constructor(options) {
20
19
  this.#notifier = options.references.notifier;
21
- this.#intl = options.intl;
20
+ this.#currentIntl = options.currentIntl;
22
21
  try {
23
22
  this.#keycloakOptions = getKeycloakConfig(options.properties);
24
23
  } catch (e) {
@@ -30,16 +29,20 @@ class KeycloakAuthPluginImpl {
30
29
  throw new Error("Failed to construct keycloak instance", { cause: e });
31
30
  }
32
31
  this.#init().catch((e) => {
32
+ if (this.#destroyed) {
33
+ return;
34
+ }
33
35
  this.#updateState({
34
36
  kind: "error",
35
37
  error: e
36
38
  });
39
+ const intl = this.#currentIntl.value;
37
40
  this.#notifier.notify({
38
41
  level: "error",
39
- title: this.#intl.formatMessage({
42
+ title: intl.formatMessage({
40
43
  id: "loginFailed.title"
41
44
  }),
42
- message: this.#intl.formatMessage({
45
+ message: intl.formatMessage({
43
46
  id: "loginFailed.message"
44
47
  })
45
48
  });
@@ -47,9 +50,8 @@ class KeycloakAuthPluginImpl {
47
50
  });
48
51
  }
49
52
  destroy() {
50
- clearInterval(this.#timerId);
51
- this.#watcher = destroyResource(this.#watcher);
52
- this.#timerId = void 0;
53
+ this.#destroyed = true;
54
+ this.#stopRefresh();
53
55
  }
54
56
  getAuthState() {
55
57
  return this.#state.value;
@@ -83,6 +85,9 @@ class KeycloakAuthPluginImpl {
83
85
  const error = typeof e === "string" ? new Error(e) : e;
84
86
  throw new Error("Failed to initialize keycloak session", { cause: error });
85
87
  }
88
+ if (this.#destroyed) {
89
+ return;
90
+ }
86
91
  if (isAuthenticated) {
87
92
  this.#updateState({
88
93
  kind: "authenticated",
@@ -112,7 +117,7 @@ class KeycloakAuthPluginImpl {
112
117
  // Mocked in test (must stay on the prototype so `vi.spyOn` can replace it;
113
118
  // a private `#` method would not be spyable).
114
119
  __refresh(interval, timeLeft) {
115
- clearInterval(this.#timerId);
120
+ this.#stopRefresh();
116
121
  this.#timerId = setInterval(() => {
117
122
  LOG.debug("Checking token validity");
118
123
  this.#keycloak.updateToken(timeLeft).then((refreshed) => {
@@ -126,10 +131,16 @@ class KeycloakAuthPluginImpl {
126
131
  this.#updateState({
127
132
  kind: "not-authenticated"
128
133
  });
129
- this.destroy();
134
+ this.#stopRefresh();
130
135
  });
131
136
  }, interval);
132
137
  }
138
+ #stopRefresh() {
139
+ if (this.#timerId !== void 0) {
140
+ clearInterval(this.#timerId);
141
+ this.#timerId = void 0;
142
+ }
143
+ }
133
144
  #updateState(newState) {
134
145
  this.#state.value = newState;
135
146
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeycloakAuthPluginImpl.js","sources":["KeycloakAuthPluginImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { reactive } from \"@conterra/reactivity-core\";\nimport { AuthState, LoginBehavior } from \"@open-pioneer/authentication\";\nimport { createLogger, destroyResource, Resource } from \"@open-pioneer/core\";\nimport { NotificationService } from \"@open-pioneer/notifier\";\nimport {\n PackageIntl,\n Service,\n ServiceOptions,\n DECLARE_SERVICE_INTERFACE\n} from \"@open-pioneer/runtime\";\nimport Keycloak, { KeycloakLogoutOptions } from \"keycloak-js\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { KeycloakAuthPlugin } from \"./api\";\nimport { getKeycloakConfig, ResolvedKeycloakOptions } from \"./getKeycloakConfig\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n notifier: NotificationService;\n}\n\nexport class KeycloakAuthPluginImpl implements Service, KeycloakAuthPlugin {\n declare [DECLARE_SERVICE_INTERFACE]: \"authentication-keycloak.KeycloakAuthPlugin\";\n\n #notifier: NotificationService;\n #intl: PackageIntl;\n #keycloakOptions: ResolvedKeycloakOptions;\n #keycloak: Keycloak;\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n #timerId: any;\n #watcher: Resource | undefined;\n\n #state = reactive<AuthState>({\n kind: \"pending\"\n });\n\n constructor(options: ServiceOptions<References>) {\n this.#notifier = options.references.notifier;\n this.#intl = options.intl;\n\n try {\n this.#keycloakOptions = getKeycloakConfig(options.properties);\n } catch (e) {\n throw new Error(\"Invalid keycloak configuration\", { cause: e });\n }\n\n try {\n this.#keycloak = new Keycloak(this.#keycloakOptions.config);\n } catch (e) {\n throw new Error(\"Failed to construct keycloak instance\", { cause: e });\n }\n this.#init().catch((e) => {\n this.#updateState({\n kind: \"error\",\n error: e\n });\n this.#notifier.notify({\n level: \"error\",\n title: this.#intl.formatMessage({\n id: \"loginFailed.title\"\n }),\n message: this.#intl.formatMessage({\n id: \"loginFailed.message\"\n })\n });\n\n LOG.error(\"Failed to check if user is authenticated\", e);\n });\n }\n\n destroy() {\n clearInterval(this.#timerId);\n this.#watcher = destroyResource(this.#watcher);\n this.#timerId = undefined;\n }\n\n getAuthState(): AuthState {\n return this.#state.value;\n }\n\n getLoginBehavior(): LoginBehavior {\n const doLogin = () => {\n const options = this.#keycloakOptions.loginOptions;\n LOG.debug(\"Login with options\", options);\n this.#keycloak.login(options);\n };\n return {\n kind: \"effect\",\n login: doLogin\n };\n }\n\n logout(options?: Partial<KeycloakLogoutOptions>) {\n const logoutOptions = {\n ...this.#keycloakOptions.logoutOptions,\n ...options\n };\n LOG.debug(\"Logout with options\", logoutOptions);\n this.#keycloak.logout(logoutOptions);\n }\n\n async #init() {\n const { initOptions, refreshOptions } = this.#keycloakOptions;\n\n let isAuthenticated: boolean;\n try {\n LOG.debug(\"Init with options\", initOptions);\n isAuthenticated = await this.#keycloak.init(initOptions);\n } catch (e) {\n // Note: keycloak.init() can also throw an exception, in addition to a rejected promise.\n // It may also just throw a string..\n const error = typeof e === \"string\" ? new Error(e) : e;\n\n // oxlint-disable-next-line preserve-caught-error\n throw new Error(\"Failed to initialize keycloak session\", { cause: error });\n }\n\n if (isAuthenticated) {\n this.#updateState({\n kind: \"authenticated\",\n sessionInfo: {\n userId: this.#keycloak.subject ? this.#keycloak.subject : \"undefined\",\n userName: this.#keycloak.idTokenParsed?.preferred_username,\n attributes: {\n keycloak: this.#keycloak,\n familyName: this.#keycloak.idTokenParsed?.family_name,\n givenName: this.#keycloak.idTokenParsed?.given_name,\n userName: this.#keycloak.idTokenParsed?.preferred_username\n }\n }\n });\n\n LOG.debug(`User ${this.#keycloak.subject} is authenticated`);\n\n if (refreshOptions.autoRefresh) {\n LOG.debug(\"Starting auto-refresh\", refreshOptions);\n this.__refresh(refreshOptions.interval, refreshOptions.timeLeft);\n }\n } else {\n this.#updateState({\n kind: \"not-authenticated\"\n });\n LOG.debug(\"User is not authenticated\");\n }\n }\n\n // Mocked in test (must stay on the prototype so `vi.spyOn` can replace it;\n // a private `#` method would not be spyable).\n __refresh(interval: number, timeLeft: number) {\n clearInterval(this.#timerId);\n this.#timerId = setInterval(() => {\n LOG.debug(\"Checking token validity\");\n this.#keycloak\n .updateToken(timeLeft)\n .then((refreshed) => {\n if (refreshed) {\n LOG.debug(\"Token refreshed successfully\");\n } else {\n LOG.debug(\"Token is still valid\");\n }\n })\n .catch((e) => {\n LOG.error(\"Failed to refresh token\", e);\n this.#updateState({\n kind: \"not-authenticated\"\n });\n this.destroy();\n });\n }, interval);\n }\n\n #updateState(newState: AuthState) {\n this.#state.value = newState;\n }\n}\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAM1B,MAAM,sBAAA,CAA8D;AAAA,EAGvE,SAAA;AAAA,EACA,KAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA;AAAA,EAGA,QAAA;AAAA,EACA,QAAA;AAAA,EAEA,SAAS,QAAA,CAAoB;AAAA,IACzB,IAAA,EAAM;AAAA,GACT,CAAA;AAAA,EAED,YAAY,OAAA,EA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BAAyB,CAAA;AACnC,MAAA,IAAA,CAAK,UACA,WAAA,CAAY,QAAQ,CAAA,CACpB,IAAA,CAAK,CAAC,SAAA,KAAc;AACjB,QAAA,IAAI,SAAA,EAAW;AACX,UAAA,GAAA,CAAI,MAAM,8BAA8B,CAAA;AAAA,QAC5C,CAAA,MAAO;AACH,UAAA,GAAA,CAAI,MAAM,sBAAsB,CAAA;AAAA,QACpC;AAAA,MACJ,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,CAAA,KAAM;AACV,QAAA,GAAA,CAAI,KAAA,CAAM,2BAA2B,CAAC,CAAA;AACtC,QAAA,IAAA,CAAK,YAAA,CAAa;AAAA,UACd,IAAA,EAAM;AAAA,SACT,CAAA;AACD,QAAA,IAAA,CAAK,OAAA,EAAQ;AAAA,MACjB,CAAC,CAAA;AAAA,IACT,GAAG,QAAQ,CAAA;AAAA,EACf;AAAA,EAEA,aAAa,QAAA,EAAqB;AAC9B,IAAA,IAAA,CAAK,OAAO,KAAA,GAAQ,QAAA;AAAA,EACxB;AACJ;;"}
1
+ {"version":3,"file":"KeycloakAuthPluginImpl.js","sources":["KeycloakAuthPluginImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { AuthState, LoginBehavior } from \"@open-pioneer/authentication\";\nimport { createLogger } from \"@open-pioneer/core\";\nimport { NotificationService } from \"@open-pioneer/notifier\";\nimport {\n PackageIntl,\n Service,\n ServiceOptions,\n DECLARE_SERVICE_INTERFACE\n} from \"@open-pioneer/runtime\";\nimport Keycloak, { KeycloakLogoutOptions } from \"keycloak-js\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { KeycloakAuthPlugin } from \"./api\";\nimport { getKeycloakConfig, ResolvedKeycloakOptions } from \"./getKeycloakConfig\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n notifier: NotificationService;\n}\n\nexport class KeycloakAuthPluginImpl implements Service, KeycloakAuthPlugin {\n declare [DECLARE_SERVICE_INTERFACE]: \"authentication-keycloak.KeycloakAuthPlugin\";\n\n #notifier: NotificationService;\n #currentIntl: ReadonlyReactive<PackageIntl>;\n #keycloakOptions: ResolvedKeycloakOptions;\n #keycloak: Keycloak;\n #timerId: ReturnType<typeof setInterval> | undefined;\n #destroyed = false;\n\n #state = reactive<AuthState>({\n kind: \"pending\"\n });\n\n constructor(options: ServiceOptions<References>) {\n this.#notifier = options.references.notifier;\n this.#currentIntl = options.currentIntl;\n\n try {\n this.#keycloakOptions = getKeycloakConfig(options.properties);\n } catch (e) {\n throw new Error(\"Invalid keycloak configuration\", { cause: e });\n }\n\n try {\n this.#keycloak = new Keycloak(this.#keycloakOptions.config);\n } catch (e) {\n throw new Error(\"Failed to construct keycloak instance\", { cause: e });\n }\n this.#init().catch((e) => {\n if (this.#destroyed) {\n return;\n }\n this.#updateState({\n kind: \"error\",\n error: e\n });\n const intl = this.#currentIntl.value;\n this.#notifier.notify({\n level: \"error\",\n title: intl.formatMessage({\n id: \"loginFailed.title\"\n }),\n message: intl.formatMessage({\n id: \"loginFailed.message\"\n })\n });\n\n LOG.error(\"Failed to check if user is authenticated\", e);\n });\n }\n\n destroy() {\n this.#destroyed = true;\n this.#stopRefresh();\n }\n\n getAuthState(): AuthState {\n return this.#state.value;\n }\n\n getLoginBehavior(): LoginBehavior {\n const doLogin = () => {\n const options = this.#keycloakOptions.loginOptions;\n LOG.debug(\"Login with options\", options);\n this.#keycloak.login(options);\n };\n return {\n kind: \"effect\",\n login: doLogin\n };\n }\n\n logout(options?: Partial<KeycloakLogoutOptions>) {\n const logoutOptions = {\n ...this.#keycloakOptions.logoutOptions,\n ...options\n };\n LOG.debug(\"Logout with options\", logoutOptions);\n this.#keycloak.logout(logoutOptions);\n }\n\n async #init() {\n const { initOptions, refreshOptions } = this.#keycloakOptions;\n\n let isAuthenticated: boolean;\n try {\n LOG.debug(\"Init with options\", initOptions);\n isAuthenticated = await this.#keycloak.init(initOptions);\n } catch (e) {\n // Note: keycloak.init() can also throw an exception, in addition to a rejected promise.\n // It may also just throw a string..\n const error = typeof e === \"string\" ? new Error(e) : e;\n\n // oxlint-disable-next-line preserve-caught-error\n throw new Error(\"Failed to initialize keycloak session\", { cause: error });\n }\n\n if (this.#destroyed) {\n return;\n }\n\n if (isAuthenticated) {\n this.#updateState({\n kind: \"authenticated\",\n sessionInfo: {\n userId: this.#keycloak.subject ? this.#keycloak.subject : \"undefined\",\n userName: this.#keycloak.idTokenParsed?.preferred_username,\n attributes: {\n keycloak: this.#keycloak,\n familyName: this.#keycloak.idTokenParsed?.family_name,\n givenName: this.#keycloak.idTokenParsed?.given_name,\n userName: this.#keycloak.idTokenParsed?.preferred_username\n }\n }\n });\n\n LOG.debug(`User ${this.#keycloak.subject} is authenticated`);\n\n if (refreshOptions.autoRefresh) {\n LOG.debug(\"Starting auto-refresh\", refreshOptions);\n this.__refresh(refreshOptions.interval, refreshOptions.timeLeft);\n }\n } else {\n this.#updateState({\n kind: \"not-authenticated\"\n });\n LOG.debug(\"User is not authenticated\");\n }\n }\n\n // Mocked in test (must stay on the prototype so `vi.spyOn` can replace it;\n // a private `#` method would not be spyable).\n __refresh(interval: number, timeLeft: number) {\n this.#stopRefresh();\n this.#timerId = setInterval(() => {\n LOG.debug(\"Checking token validity\");\n this.#keycloak\n .updateToken(timeLeft)\n .then((refreshed) => {\n if (refreshed) {\n LOG.debug(\"Token refreshed successfully\");\n } else {\n LOG.debug(\"Token is still valid\");\n }\n })\n .catch((e) => {\n LOG.error(\"Failed to refresh token\", e);\n this.#updateState({\n kind: \"not-authenticated\"\n });\n this.#stopRefresh();\n });\n }, interval);\n }\n\n #stopRefresh() {\n if (this.#timerId !== undefined) {\n clearInterval(this.#timerId);\n this.#timerId = undefined;\n }\n }\n\n #updateState(newState: AuthState) {\n this.#state.value = newState;\n }\n}\n"],"names":[],"mappings":";;;;;;AAkB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/) plugin for the [authentication package](https://github.com/open-pioneer/trails-core-packages/blob/main/src/packages/authentication/README.md#implementing-an-authentication-plugin).
4
4
 
5
- The package implements an authentication flow using the [Keycloak JavaScript](#https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter) adapter.
5
+ The package implements an authentication flow using the [Keycloak JavaScript](https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter) adapter.
6
6
  For more information about Keycloak, see the [Keycloak documentation](https://www.keycloak.org/).
7
7
 
8
8
  ## Usage
package/api.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface KeycloakProperties {
12
12
  */
13
13
  keycloakOptions: KeycloakOptions;
14
14
  }
15
+ /** Options for the Keycloak JavaScript adapter and for the token refresh of this plugin. */
15
16
  export interface KeycloakOptions {
16
17
  /**
17
18
  * The configuration details for connecting to Keycloak.
@@ -26,7 +27,7 @@ export interface KeycloakOptions {
26
27
  *
27
28
  * - 'autoRefresh': Whether token refreshing should happen automatically.
28
29
  * - 'interval': The interval (in milliseconds) at which token refreshing should occur.
29
- * - 'timeLeft': The remaining time (in milliseconds) before token expiration.
30
+ * - 'timeLeft': The minimum remaining lifetime (in seconds) before the token is refreshed.
30
31
  */
31
32
  refreshOptions?: RefreshOptions;
32
33
  /**
@@ -60,18 +60,10 @@ function getInitOptions(keycloakInitOptions) {
60
60
  };
61
61
  }
62
62
  function getLoginOptions(keycloakLoginOptions) {
63
- return {
64
- redirectUri: void 0,
65
- // backwards-compat; unsure if needed
66
- ...keycloakLoginOptions
67
- };
63
+ return { ...keycloakLoginOptions };
68
64
  }
69
65
  function getLogoutOptions(keycloakLogoutOptions) {
70
- return {
71
- redirectUri: void 0,
72
- // backwards-compat; unsure if needed
73
- ...keycloakLogoutOptions
74
- };
66
+ return { ...keycloakLogoutOptions };
75
67
  }
76
68
  const isObjectEmpty = (objectName) => {
77
69
  return objectName && Object.keys(objectName).length === 0 && objectName.constructor === Object;
@@ -1 +1 @@
1
- {"version":3,"file":"getKeycloakConfig.js","sources":["getKeycloakConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger } from \"@open-pioneer/core\";\nimport type {\n KeycloakConfig,\n KeycloakInitOptions,\n KeycloakLoginOptions,\n KeycloakLogoutOptions\n} from \"keycloak-js\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport type { KeycloakProperties, RefreshOptions } from \"./api\";\nconst LOG = createLogger(sourceId);\n\nconst DEFAULT_REFRESH_OPTS = {\n autoRefresh: true,\n interval: 10000,\n timeLeft: 60\n} as const;\n\nconst DEFAULT_INIT_OPTS = {\n onLoad: \"check-sso\",\n pkceMethod: \"S256\"\n} as const;\n\nexport type ResolvedRefreshOptions = Required<RefreshOptions>;\n\nexport interface ResolvedKeycloakOptions {\n config: KeycloakConfig;\n initOptions: KeycloakInitOptions;\n refreshOptions: ResolvedRefreshOptions;\n loginOptions: Partial<KeycloakLoginOptions>;\n logoutOptions: Partial<KeycloakLogoutOptions>;\n}\n\n/**\n * Parses the user supplied package properties.\n */\nexport function getKeycloakConfig(\n properties: Partial<KeycloakProperties>\n): ResolvedKeycloakOptions {\n const { keycloakOptions } = properties;\n if (!keycloakOptions) {\n throw new Error(\n `KeycloakOptions not found: The Keycloak configuration options are required by the plugin to perform login and logout operations`\n );\n }\n const {\n refreshOptions,\n keycloakInitOptions,\n keycloakConfig,\n keycloakLoginOptions,\n keycloakLogoutOptions\n } = keycloakOptions;\n return {\n config: getConfig(keycloakConfig),\n refreshOptions: getRefreshOptions(refreshOptions),\n initOptions: getInitOptions(keycloakInitOptions),\n loginOptions: getLoginOptions(keycloakLoginOptions),\n logoutOptions: getLogoutOptions(keycloakLogoutOptions)\n };\n}\n\nfunction getConfig(keycloakConfig: KeycloakConfig | undefined): KeycloakConfig {\n if (!keycloakConfig || isObjectEmpty(keycloakConfig)) {\n throw new Error(\n `KeycloakConfig not found: The Keycloak configuration options are required by the plugin to perform login and logout operations`\n );\n }\n return { ...keycloakConfig };\n}\n\nfunction getRefreshOptions(refreshOptions: RefreshOptions | undefined): ResolvedRefreshOptions {\n if (!refreshOptions || isObjectEmpty(refreshOptions)) {\n LOG.info(`Using default options for keycloak token refresh`, DEFAULT_REFRESH_OPTS);\n }\n return {\n ...DEFAULT_REFRESH_OPTS,\n ...refreshOptions\n };\n}\n\nfunction getInitOptions(keycloakInitOptions: KeycloakInitOptions | undefined): KeycloakInitOptions {\n if (!keycloakInitOptions || isObjectEmpty(keycloakInitOptions)) {\n LOG.info(`Using default options for keycloak init`, DEFAULT_INIT_OPTS);\n }\n return {\n ...DEFAULT_INIT_OPTS,\n ...keycloakInitOptions\n };\n}\n\nfunction getLoginOptions(\n keycloakLoginOptions: Partial<KeycloakLoginOptions> | undefined\n): Partial<KeycloakLoginOptions> {\n return {\n redirectUri: undefined, // backwards-compat; unsure if needed\n ...keycloakLoginOptions\n };\n}\n\nfunction getLogoutOptions(\n keycloakLogoutOptions: Partial<KeycloakLogoutOptions> | undefined\n): Partial<KeycloakLogoutOptions> {\n return {\n redirectUri: undefined, // backwards-compat; unsure if needed\n ...keycloakLogoutOptions\n };\n}\n\nconst isObjectEmpty = (objectName: unknown) => {\n return objectName && Object.keys(objectName).length === 0 && objectName.constructor === Object;\n};\n"],"names":[],"mappings":";;;AAYA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAEjC,MAAM,oBAAA,GAAuB;AAAA,EACzB,WAAA,EAAa,IAAA;AAAA,EACb,QAAA,EAAU,GAAA;AAAA,EACV,QAAA,EAAU;AACd,CAAA;AAEA,MAAM,iBAAA,GAAoB;AAAA,EACtB,MAAA,EAAQ,WAAA;AAAA,EACR,UAAA,EAAY;AAChB,CAAA;AAeO,SAAS,kBACZ,UAAA,EACuB;AACvB,EAAA,MAAM,EAAE,iBAAgB,GAAI,UAAA;AAC5B,EAAA,IAAI,CAAC,eAAA,EAAiB;AAClB,IAAA,MAAM,IAAI,KAAA;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;AAAA;AAAA,IACb,GAAG;AAAA,GACP;AACJ;AAEA,SAAS,iBACL,qBAAA,EAC8B;AAC9B,EAAA,OAAO;AAAA,IACH,WAAA,EAAa,MAAA;AAAA;AAAA,IACb,GAAG;AAAA,GACP;AACJ;AAEA,MAAM,aAAA,GAAgB,CAAC,UAAA,KAAwB;AAC3C,EAAA,OAAO,UAAA,IAAc,OAAO,IAAA,CAAK,UAAU,EAAE,MAAA,KAAW,CAAA,IAAK,WAAW,WAAA,KAAgB,MAAA;AAC5F,CAAA;;"}
1
+ {"version":3,"file":"getKeycloakConfig.js","sources":["getKeycloakConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger } from \"@open-pioneer/core\";\nimport type {\n KeycloakConfig,\n KeycloakInitOptions,\n KeycloakLoginOptions,\n KeycloakLogoutOptions\n} from \"keycloak-js\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport type { KeycloakProperties, RefreshOptions } from \"./api\";\nconst LOG = createLogger(sourceId);\n\nconst DEFAULT_REFRESH_OPTS = {\n autoRefresh: true,\n interval: 10000,\n timeLeft: 60\n} as const;\n\nconst DEFAULT_INIT_OPTS = {\n onLoad: \"check-sso\",\n pkceMethod: \"S256\"\n} as const;\n\nexport type ResolvedRefreshOptions = Required<RefreshOptions>;\n\nexport interface ResolvedKeycloakOptions {\n config: KeycloakConfig;\n initOptions: KeycloakInitOptions;\n refreshOptions: ResolvedRefreshOptions;\n loginOptions: Partial<KeycloakLoginOptions>;\n logoutOptions: Partial<KeycloakLogoutOptions>;\n}\n\n/**\n * Parses the user supplied package properties.\n */\nexport function getKeycloakConfig(\n properties: Partial<KeycloakProperties>\n): ResolvedKeycloakOptions {\n const { keycloakOptions } = properties;\n if (!keycloakOptions) {\n throw new Error(\n `KeycloakOptions not found: The Keycloak configuration options are required by the plugin to perform login and logout operations`\n );\n }\n const {\n refreshOptions,\n keycloakInitOptions,\n keycloakConfig,\n keycloakLoginOptions,\n keycloakLogoutOptions\n } = keycloakOptions;\n return {\n config: getConfig(keycloakConfig),\n refreshOptions: getRefreshOptions(refreshOptions),\n initOptions: getInitOptions(keycloakInitOptions),\n loginOptions: getLoginOptions(keycloakLoginOptions),\n logoutOptions: getLogoutOptions(keycloakLogoutOptions)\n };\n}\n\nfunction getConfig(keycloakConfig: KeycloakConfig | undefined): KeycloakConfig {\n if (!keycloakConfig || isObjectEmpty(keycloakConfig)) {\n throw new Error(\n `KeycloakConfig not found: The Keycloak configuration options are required by the plugin to perform login and logout operations`\n );\n }\n return { ...keycloakConfig };\n}\n\nfunction getRefreshOptions(refreshOptions: RefreshOptions | undefined): ResolvedRefreshOptions {\n if (!refreshOptions || isObjectEmpty(refreshOptions)) {\n LOG.info(`Using default options for keycloak token refresh`, DEFAULT_REFRESH_OPTS);\n }\n return {\n ...DEFAULT_REFRESH_OPTS,\n ...refreshOptions\n };\n}\n\nfunction getInitOptions(keycloakInitOptions: KeycloakInitOptions | undefined): KeycloakInitOptions {\n if (!keycloakInitOptions || isObjectEmpty(keycloakInitOptions)) {\n LOG.info(`Using default options for keycloak init`, DEFAULT_INIT_OPTS);\n }\n return {\n ...DEFAULT_INIT_OPTS,\n ...keycloakInitOptions\n };\n}\n\nfunction getLoginOptions(\n keycloakLoginOptions: Partial<KeycloakLoginOptions> | undefined\n): Partial<KeycloakLoginOptions> {\n return { ...keycloakLoginOptions };\n}\n\nfunction getLogoutOptions(\n keycloakLogoutOptions: Partial<KeycloakLogoutOptions> | undefined\n): Partial<KeycloakLogoutOptions> {\n return { ...keycloakLogoutOptions };\n}\n\nconst isObjectEmpty = (objectName: unknown) => {\n return objectName && Object.keys(objectName).length === 0 && objectName.constructor === Object;\n};\n"],"names":[],"mappings":";;;AAYA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAEjC,MAAM,oBAAA,GAAuB;AAAA,EACzB,WAAA,EAAa,IAAA;AAAA,EACb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AAA,IAAI,CAAC,mBAAA,IAAuB,aAAA,CAAc,mBAAmB,CAAA,EAAG;AAC5D,IAAA,GAAA,CAAI,IAAA,CAAK,2CAA2C,iBAAiB,CAAA;AAAA,EACzE;AACA,EAAA,OAAO;AAAA,IACH,GAAG,iBAAA;AAAA,IACH,GAAG;AAAA,GACP;AACJ;AAEA,SAAS,gBACL,oBAAA,EAC6B;AAC7B,EAAA,OAAO,EAAE,GAAG,oBAAA,EAAqB;AACrC;AAEA,SAAS,iBACL,qBAAA,EAC8B;AAC9B,EAAA,OAAO,EAAE,GAAG,qBAAA,EAAsB;AACtC;AAEA,MAAM,aAAA,GAAgB,CAAC,UAAA,KAAwB;AAC3C,EAAA,OAAO,UAAA,IAAc,OAAO,IAAA,CAAK,UAAU,EAAE,MAAA,KAAW,CAAA,IAAK,WAAW,WAAA,KAAgB,MAAA;AAC5F,CAAA;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/authentication-keycloak",
4
- "version": "4.8.0",
4
+ "version": "4.9.0-dev.20261002130116",
5
5
  "description": "Implements authentication against Keycloak servers.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -10,15 +10,15 @@
10
10
  "license": "Apache-2.0",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/open-pioneer/core-packages",
13
+ "url": "https://github.com/open-pioneer/trails-core-packages",
14
14
  "directory": "src/packages/authentication-keycloak"
15
15
  },
16
16
  "dependencies": {
17
17
  "@conterra/reactivity-core": "^0.8.8",
18
- "@open-pioneer/authentication": "4.8.0",
19
- "@open-pioneer/core": "4.8.0",
20
- "@open-pioneer/notifier": "4.8.0",
21
- "@open-pioneer/runtime": "4.8.0",
18
+ "@open-pioneer/authentication": "4.9.0-dev.20261002130116",
19
+ "@open-pioneer/core": "4.9.0-dev.20261002130116",
20
+ "@open-pioneer/notifier": "4.9.0-dev.20261002130116",
21
+ "@open-pioneer/runtime": "4.9.0-dev.20261002130116",
22
22
  "keycloak-js": "^26.2.4"
23
23
  },
24
24
  "publishConfig": {