@onecx/shell-auth 8.0.0-rc.10
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/LICENSE +201 -0
- package/README.md +16 -0
- package/fesm2022/onecx-shell-auth.mjs +380 -0
- package/fesm2022/onecx-shell-auth.mjs.map +1 -0
- package/package.json +42 -0
- package/types/onecx-shell-auth.d.ts +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @onecx/shell-auth
|
|
2
|
+
|
|
3
|
+
`@onecx/shell-auth` contains all authentication services and utilities meant to be used exclusively by the OneCX Shell and Standalone Shell.
|
|
4
|
+
More information about OneCX libraries can be found in the [OneCX documentation](https://onecx.github.io/docs/documentation/current/onecx-portal-ui-libs/index.html).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @onecx/shell-auth
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Additional Commands
|
|
13
|
+
- `npx nx run shell-auth:build` - Builds the library and outputs the result to the `dist` folder.
|
|
14
|
+
- `npx nx run shell-auth:test` - Runs the unit tests for the library.
|
|
15
|
+
- `npx nx run shell-auth:lint` - Lints the library's codebase.
|
|
16
|
+
- `npx nx run shell-auth:release` - Releases a new version of the library to npm, following semantic versioning guidelines.
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { loadRemoteModule } from '@angular-architects/module-federation';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, Injectable, Injector, provideAppInitializer } from '@angular/core';
|
|
4
|
+
import { ConfigurationService, CONFIG_KEY, AppStateService } from '@onecx/angular-integration-interface';
|
|
5
|
+
import { EventsTopic, EventType } from '@onecx/integration-interface';
|
|
6
|
+
import { filter } from 'rxjs/internal/operators/filter';
|
|
7
|
+
import { createLoggerFactory } from '@onecx/accelerator';
|
|
8
|
+
import Semaphore from 'ts-semaphore';
|
|
9
|
+
|
|
10
|
+
var Injectables;
|
|
11
|
+
(function (Injectables) {
|
|
12
|
+
Injectables["KEYCLOAK_AUTH_SERVICE"] = "KEYCLOAK_AUTH_SERVICE";
|
|
13
|
+
Injectables["CONFIG"] = "CONFIG";
|
|
14
|
+
})(Injectables || (Injectables = {}));
|
|
15
|
+
|
|
16
|
+
// This file is not planned to be in the index.ts so it is private to this lib
|
|
17
|
+
const createLogger = createLoggerFactory('@onecx/shell-auth');
|
|
18
|
+
|
|
19
|
+
const KC_REFRESH_TOKEN_LS = 'onecx_kc_refreshToken';
|
|
20
|
+
const KC_ID_TOKEN_LS = 'onecx_kc_idToken';
|
|
21
|
+
const KC_TOKEN_LS = 'onecx_kc_token';
|
|
22
|
+
class KeycloakAuthService {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.logger = createLogger('KeycloakAuthService');
|
|
25
|
+
this.configService = inject(ConfigurationService);
|
|
26
|
+
this.updateTokenSemaphore = new Semaphore(1);
|
|
27
|
+
}
|
|
28
|
+
async init(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
let token = localStorage.getItem(KC_TOKEN_LS);
|
|
31
|
+
let idToken = localStorage.getItem(KC_ID_TOKEN_LS);
|
|
32
|
+
let refreshToken = localStorage.getItem(KC_REFRESH_TOKEN_LS);
|
|
33
|
+
if (token && refreshToken) {
|
|
34
|
+
const parsedToken = JSON.parse(atob(refreshToken.split('.')[1]));
|
|
35
|
+
if (parsedToken.exp * 1000 < new Date().getTime()) {
|
|
36
|
+
token = null;
|
|
37
|
+
refreshToken = null;
|
|
38
|
+
idToken = null;
|
|
39
|
+
this.clearKCStateFromLocalstorage();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let kcConfig;
|
|
43
|
+
const validKCConfig = await this.getValidKCConfig();
|
|
44
|
+
kcConfig = { ...validKCConfig, ...(config ?? {}) };
|
|
45
|
+
if (!kcConfig.clientId || !kcConfig.realm || !kcConfig.url) {
|
|
46
|
+
kcConfig = './assets/keycloak.json';
|
|
47
|
+
}
|
|
48
|
+
const enableSilentSSOCheck = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ENABLE_SILENT_SSO)) === 'true';
|
|
49
|
+
const timeSkew = await this.getConfigValueNumberOrUndefined(CONFIG_KEY.KEYCLOAK_TIME_SKEW);
|
|
50
|
+
try {
|
|
51
|
+
await import('keycloak-js').then(({ default: Keycloak }) => {
|
|
52
|
+
this.keycloak = new Keycloak(kcConfig);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const errorMessage = 'Keycloak initialization failed! Could not load keycloak-js library which is required in the current environment.';
|
|
57
|
+
this.logger.error(errorMessage, err);
|
|
58
|
+
throw new Error(errorMessage);
|
|
59
|
+
}
|
|
60
|
+
if (!this.keycloak) {
|
|
61
|
+
throw new Error('Keycloak initialization failed!');
|
|
62
|
+
}
|
|
63
|
+
await this.setupEventListener();
|
|
64
|
+
return this.keycloak
|
|
65
|
+
.init({
|
|
66
|
+
onLoad: 'check-sso',
|
|
67
|
+
checkLoginIframe: false,
|
|
68
|
+
silentCheckSsoRedirectUri: enableSilentSSOCheck ? this.getSilentSSOUrl() : undefined,
|
|
69
|
+
idToken: idToken || undefined,
|
|
70
|
+
refreshToken: refreshToken || undefined,
|
|
71
|
+
token: token || undefined,
|
|
72
|
+
timeSkew: timeSkew,
|
|
73
|
+
})
|
|
74
|
+
.catch((err) => {
|
|
75
|
+
this.logger.warn(`Keycloak err: ${err}, try force login`);
|
|
76
|
+
return this.keycloak?.login(this.config);
|
|
77
|
+
})
|
|
78
|
+
.then((loginOk) => {
|
|
79
|
+
if (loginOk) {
|
|
80
|
+
return this.keycloak?.token;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return this.keycloak?.login(this.config).then(() => 'login');
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.then(() => {
|
|
87
|
+
return true;
|
|
88
|
+
})
|
|
89
|
+
.catch((err) => {
|
|
90
|
+
this.logger.error(`KC ERROR ${err} as json ${JSON.stringify(err)}`);
|
|
91
|
+
throw err;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async getValidKCConfig() {
|
|
95
|
+
const clientId = await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_CLIENT_ID);
|
|
96
|
+
if (!clientId) {
|
|
97
|
+
throw new Error('Invalid KC config, missing clientId');
|
|
98
|
+
}
|
|
99
|
+
const realm = await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_REALM);
|
|
100
|
+
if (!realm) {
|
|
101
|
+
throw new Error('Invalid KC config, missing realm');
|
|
102
|
+
}
|
|
103
|
+
const url = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_URL)) ?? '';
|
|
104
|
+
return {
|
|
105
|
+
url,
|
|
106
|
+
clientId,
|
|
107
|
+
realm,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async setupEventListener() {
|
|
111
|
+
if (this.keycloak) {
|
|
112
|
+
const onTokenExpiredEnabled = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ON_TOKEN_EXPIRED_ENABLED)) === 'true';
|
|
113
|
+
const onAuthRefreshErrorEnabled = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ON_AUTH_REFRESH_ERROR_ENABLED)) === 'true';
|
|
114
|
+
this.keycloak.onAuthError = () => {
|
|
115
|
+
this.updateLocalStorage();
|
|
116
|
+
};
|
|
117
|
+
this.keycloak.onAuthLogout = () => {
|
|
118
|
+
this.logger.info('SSO logout nav to root');
|
|
119
|
+
this.clearKCStateFromLocalstorage();
|
|
120
|
+
this.keycloak?.login(this.config);
|
|
121
|
+
};
|
|
122
|
+
this.keycloak.onAuthRefreshSuccess = () => {
|
|
123
|
+
this.updateLocalStorage();
|
|
124
|
+
};
|
|
125
|
+
this.keycloak.onAuthRefreshError = () => {
|
|
126
|
+
this.updateLocalStorage();
|
|
127
|
+
if (onAuthRefreshErrorEnabled) {
|
|
128
|
+
this.logger.info('Auth refresh error - initiating re-login');
|
|
129
|
+
this.keycloak?.login(this.config);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
this.keycloak.onAuthSuccess = () => {
|
|
133
|
+
this.updateLocalStorage();
|
|
134
|
+
};
|
|
135
|
+
this.keycloak.onTokenExpired = () => {
|
|
136
|
+
this.updateLocalStorage();
|
|
137
|
+
if (onTokenExpiredEnabled) {
|
|
138
|
+
// A semaphore is used to prevent executing multiple updateToken calls in parallel.
|
|
139
|
+
this.updateTokenSemaphore.use(async () => {
|
|
140
|
+
this.logger.info('Token expired - proactively refreshing');
|
|
141
|
+
this.keycloak?.updateToken();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
this.keycloak.onActionUpdate = () => {
|
|
146
|
+
this.updateLocalStorage();
|
|
147
|
+
};
|
|
148
|
+
this.keycloak.onReady = () => {
|
|
149
|
+
this.updateLocalStorage();
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
updateLocalStorage() {
|
|
154
|
+
if (this.keycloak) {
|
|
155
|
+
if (this.keycloak.token) {
|
|
156
|
+
localStorage.setItem(KC_TOKEN_LS, this.keycloak.token);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
localStorage.removeItem(KC_TOKEN_LS);
|
|
160
|
+
}
|
|
161
|
+
if (this.keycloak.idToken) {
|
|
162
|
+
localStorage.setItem(KC_ID_TOKEN_LS, this.keycloak.idToken);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
localStorage.removeItem(KC_ID_TOKEN_LS);
|
|
166
|
+
}
|
|
167
|
+
if (this.keycloak.refreshToken) {
|
|
168
|
+
localStorage.setItem(KC_REFRESH_TOKEN_LS, this.keycloak.refreshToken);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
localStorage.removeItem(KC_REFRESH_TOKEN_LS);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
clearKCStateFromLocalstorage() {
|
|
176
|
+
localStorage.removeItem(KC_ID_TOKEN_LS);
|
|
177
|
+
localStorage.removeItem(KC_TOKEN_LS);
|
|
178
|
+
localStorage.removeItem(KC_REFRESH_TOKEN_LS);
|
|
179
|
+
}
|
|
180
|
+
getSilentSSOUrl() {
|
|
181
|
+
let currentBase = document.getElementsByTagName('base')[0].href;
|
|
182
|
+
if (currentBase === '/') {
|
|
183
|
+
currentBase = '';
|
|
184
|
+
}
|
|
185
|
+
return `${currentBase}/assets/silent-check-sso.html`;
|
|
186
|
+
}
|
|
187
|
+
getIdToken() {
|
|
188
|
+
return this.keycloak?.idToken ?? null;
|
|
189
|
+
}
|
|
190
|
+
getAccessToken() {
|
|
191
|
+
return this.keycloak?.token ?? null;
|
|
192
|
+
}
|
|
193
|
+
logout() {
|
|
194
|
+
this.keycloak?.logout();
|
|
195
|
+
}
|
|
196
|
+
async updateTokenIfNeeded() {
|
|
197
|
+
return this.updateTokenSemaphore.use(async () => {
|
|
198
|
+
if (!this.keycloak?.authenticated) {
|
|
199
|
+
return this.keycloak?.login(this.config).then(() => false) ?? Promise.reject('Keycloak not initialized!');
|
|
200
|
+
}
|
|
201
|
+
const minValidity = await this.getConfigValueNumberOrUndefined(CONFIG_KEY.KEYCLOAK_UPDATE_TOKEN_MIN_VALIDITY);
|
|
202
|
+
return this.keycloak.updateToken(minValidity);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getAuthProviderName() {
|
|
206
|
+
return 'keycloak-auth';
|
|
207
|
+
}
|
|
208
|
+
hasRole(_role) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
getUserRoles() {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
getHeaderValues() {
|
|
215
|
+
return { 'apm-principal-token': this.getIdToken() ?? '', Authorization: `Bearer ${this.getAccessToken()}` };
|
|
216
|
+
}
|
|
217
|
+
async getConfigValueNumberOrUndefined(configKey) {
|
|
218
|
+
const value = await this.configService.getProperty(configKey);
|
|
219
|
+
if (value === undefined)
|
|
220
|
+
return undefined;
|
|
221
|
+
const parsed = Number.parseInt(value, 10);
|
|
222
|
+
if (Number.isNaN(parsed))
|
|
223
|
+
return undefined;
|
|
224
|
+
return parsed;
|
|
225
|
+
}
|
|
226
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: KeycloakAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
227
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: KeycloakAuthService }); }
|
|
228
|
+
}
|
|
229
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: KeycloakAuthService, decorators: [{
|
|
230
|
+
type: Injectable
|
|
231
|
+
}] });
|
|
232
|
+
|
|
233
|
+
var globalThis$1 = globalThis;
|
|
234
|
+
|
|
235
|
+
class DisabledAuthService {
|
|
236
|
+
async init(_config) {
|
|
237
|
+
return Promise.resolve(true);
|
|
238
|
+
}
|
|
239
|
+
getIdToken() {
|
|
240
|
+
return "";
|
|
241
|
+
}
|
|
242
|
+
getAccessToken() {
|
|
243
|
+
return "";
|
|
244
|
+
}
|
|
245
|
+
logout() {
|
|
246
|
+
window.location.href = "https://github.com/onecx/";
|
|
247
|
+
}
|
|
248
|
+
async updateTokenIfNeeded() {
|
|
249
|
+
return Promise.resolve(true);
|
|
250
|
+
}
|
|
251
|
+
getHeaderValues() {
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: DisabledAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
255
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: DisabledAuthService }); }
|
|
256
|
+
}
|
|
257
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: DisabledAuthService, decorators: [{
|
|
258
|
+
type: Injectable
|
|
259
|
+
}] });
|
|
260
|
+
|
|
261
|
+
class AuthServiceWrapper {
|
|
262
|
+
constructor() {
|
|
263
|
+
this.configService = inject(ConfigurationService);
|
|
264
|
+
this.appStateService = inject(AppStateService);
|
|
265
|
+
this.injector = inject(Injector);
|
|
266
|
+
this.eventsTopic$ = new EventsTopic();
|
|
267
|
+
this.eventsTopic$
|
|
268
|
+
.pipe(filter((e) => e.type === EventType.AUTH_LOGOUT_BUTTON_CLICKED))
|
|
269
|
+
.subscribe(() => this.authService?.logout());
|
|
270
|
+
// Shell defines these properties to support older library versions
|
|
271
|
+
window.onecxAngularAuth ??= {};
|
|
272
|
+
window.onecxAngularAuth.authServiceProxy ??= {};
|
|
273
|
+
window.onecxAngularAuth.authServiceProxy.v1 ??= {
|
|
274
|
+
updateTokenIfNeeded: () => {
|
|
275
|
+
return this.updateTokenIfNeeded();
|
|
276
|
+
},
|
|
277
|
+
getHeaderValues: () => {
|
|
278
|
+
return this.getHeaderValues();
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
window.onecxAuth ??= {};
|
|
282
|
+
window.onecxAuth.authServiceProxy ??= {};
|
|
283
|
+
window.onecxAuth.authServiceProxy.v1 ??= {
|
|
284
|
+
updateTokenIfNeeded: () => {
|
|
285
|
+
return this.updateTokenIfNeeded();
|
|
286
|
+
},
|
|
287
|
+
getHeaderValues: () => {
|
|
288
|
+
return this.getHeaderValues();
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async init() {
|
|
293
|
+
await this.configService.isInitialized;
|
|
294
|
+
await this.initializeAuthService();
|
|
295
|
+
const initResult = this.getInitResult();
|
|
296
|
+
return initResult;
|
|
297
|
+
}
|
|
298
|
+
async getInitResult() {
|
|
299
|
+
const initResult = await this.authService?.init();
|
|
300
|
+
if (initResult) {
|
|
301
|
+
await this.appStateService.isAuthenticated$.publish();
|
|
302
|
+
}
|
|
303
|
+
return initResult;
|
|
304
|
+
}
|
|
305
|
+
getHeaderValues() {
|
|
306
|
+
return this.authService?.getHeaderValues() ?? {};
|
|
307
|
+
}
|
|
308
|
+
updateTokenIfNeeded() {
|
|
309
|
+
return this.authService?.updateTokenIfNeeded() ?? Promise.reject();
|
|
310
|
+
}
|
|
311
|
+
async initializeAuthService() {
|
|
312
|
+
const serviceTypeConfig = (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE)) ?? 'keycloak';
|
|
313
|
+
switch (serviceTypeConfig) {
|
|
314
|
+
case 'keycloak':
|
|
315
|
+
this.authService = this.injector.get(KeycloakAuthService);
|
|
316
|
+
break;
|
|
317
|
+
case 'custom': {
|
|
318
|
+
// remote module is exposing function as default export (this is a convention)
|
|
319
|
+
// this function is responsible for creating the custom auth service
|
|
320
|
+
// to have access to the dependency mechanism of the shell
|
|
321
|
+
// the function gets a callback which is returning the requested injectable
|
|
322
|
+
const factory = await this.getAuthServiceFactory();
|
|
323
|
+
this.authService = await Promise.resolve(factory((injectable) => this.retrieveInjectables(injectable)));
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case 'disabled':
|
|
327
|
+
this.authService = this.injector.get(DisabledAuthService);
|
|
328
|
+
break;
|
|
329
|
+
default:
|
|
330
|
+
throw new Error('Configured AuthService not found');
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async retrieveInjectables(injectable) {
|
|
334
|
+
if (injectable === Injectables.KEYCLOAK_AUTH_SERVICE) {
|
|
335
|
+
return this.injector.get(KeycloakAuthService);
|
|
336
|
+
}
|
|
337
|
+
else if (injectable === Injectables.CONFIG) {
|
|
338
|
+
return this.configService.getConfig();
|
|
339
|
+
}
|
|
340
|
+
throw new Error('unknown injectable type');
|
|
341
|
+
}
|
|
342
|
+
async getAuthServiceFactory() {
|
|
343
|
+
if (await !this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {
|
|
344
|
+
throw new Error('URL of the custom auth service is not defined');
|
|
345
|
+
}
|
|
346
|
+
const module = await loadRemoteModule({
|
|
347
|
+
type: 'module',
|
|
348
|
+
remoteEntry: (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) ?? '',
|
|
349
|
+
exposedModule: (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_MODULE_NAME)) ?? './CustomAuth',
|
|
350
|
+
});
|
|
351
|
+
return module.default;
|
|
352
|
+
}
|
|
353
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: AuthServiceWrapper, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
354
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: AuthServiceWrapper }); }
|
|
355
|
+
}
|
|
356
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: AuthServiceWrapper, decorators: [{
|
|
357
|
+
type: Injectable
|
|
358
|
+
}], ctorParameters: () => [] });
|
|
359
|
+
|
|
360
|
+
function provideAuthServices() {
|
|
361
|
+
return [AuthServiceWrapper, KeycloakAuthService, DisabledAuthService];
|
|
362
|
+
}
|
|
363
|
+
function provideAuthService() {
|
|
364
|
+
return [
|
|
365
|
+
provideAuthServices(),
|
|
366
|
+
provideAppInitializer(async () => {
|
|
367
|
+
const configService = inject(ConfigurationService);
|
|
368
|
+
const authServiceWrapper = inject(AuthServiceWrapper);
|
|
369
|
+
await configService.isInitialized;
|
|
370
|
+
await authServiceWrapper.init();
|
|
371
|
+
}),
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Generated bundle index. Do not edit.
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
export { AuthServiceWrapper, provideAuthService };
|
|
380
|
+
//# sourceMappingURL=onecx-shell-auth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onecx-shell-auth.mjs","sources":["../../../../libs/shell-auth/src/lib/auth.service.ts","../../../../libs/shell-auth/src/lib/utils/logger.utils.ts","../../../../libs/shell-auth/src/lib/auth_services/keycloak-auth.service.ts","../../../../libs/shell-auth/src/lib/declarations.ts","../../../../libs/shell-auth/src/lib/auth_services/disabled-auth.service.ts","../../../../libs/shell-auth/src/lib/auth-service-wrapper.ts","../../../../libs/shell-auth/src/lib/provide-auth-service.ts","../../../../libs/shell-auth/src/onecx-shell-auth.ts"],"sourcesContent":["export interface AuthService {\n init(config?: Record<string, unknown>): Promise<boolean>\n\n getHeaderValues(): Record<string, string>\n\n logout(): void\n\n updateTokenIfNeeded(): Promise<boolean>\n}\n\nexport enum Injectables {\n KEYCLOAK_AUTH_SERVICE = 'KEYCLOAK_AUTH_SERVICE',\n CONFIG = 'CONFIG',\n}\n\nexport type AuthServiceFactory = (\n injectorFunction: (injectable: Injectables) => Promise<unknown> | unknown\n) => AuthService | Promise<AuthService>\n","// This file is not planned to be in the index.ts so it is private to this lib\nimport { createLoggerFactory } from '@onecx/accelerator'\n\nexport const createLogger = createLoggerFactory('@onecx/shell-auth')\n","import { Injectable, inject } from '@angular/core'\nimport { CONFIG_KEY, ConfigurationService } from '@onecx/angular-integration-interface'\nimport Keycloak, { KeycloakServerConfig } from 'keycloak-js'\nimport { AuthService } from '../auth.service'\nimport { createLogger } from '../utils/logger.utils'\nimport Semaphore from 'ts-semaphore'\n\nconst KC_REFRESH_TOKEN_LS = 'onecx_kc_refreshToken'\nconst KC_ID_TOKEN_LS = 'onecx_kc_idToken'\nconst KC_TOKEN_LS = 'onecx_kc_token'\n\n@Injectable()\nexport class KeycloakAuthService implements AuthService {\n private readonly logger = createLogger('KeycloakAuthService')\n private configService = inject(ConfigurationService)\n private keycloak: Keycloak | undefined\n private readonly updateTokenSemaphore = new Semaphore(1)\n\n config?: Record<string, unknown>\n\n public async init(config?: Record<string, unknown>): Promise<boolean> {\n this.config = config\n let token = localStorage.getItem(KC_TOKEN_LS)\n let idToken = localStorage.getItem(KC_ID_TOKEN_LS)\n let refreshToken = localStorage.getItem(KC_REFRESH_TOKEN_LS)\n if (token && refreshToken) {\n const parsedToken = JSON.parse(atob(refreshToken.split('.')[1]))\n if (parsedToken.exp * 1000 < new Date().getTime()) {\n token = null\n refreshToken = null\n idToken = null\n this.clearKCStateFromLocalstorage()\n }\n }\n\n let kcConfig: KeycloakServerConfig | string\n const validKCConfig = await this.getValidKCConfig()\n kcConfig = { ...validKCConfig, ...(config ?? {}) }\n \n if (!kcConfig.clientId || !kcConfig.realm || !kcConfig.url) {\n kcConfig = './assets/keycloak.json'\n }\n\n const enableSilentSSOCheck =\n (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ENABLE_SILENT_SSO)) === 'true'\n\n const timeSkew = await this.getConfigValueNumberOrUndefined(CONFIG_KEY.KEYCLOAK_TIME_SKEW)\n\n try {\n await import('keycloak-js').then(({ default: Keycloak }) => {\n this.keycloak = new Keycloak(kcConfig)\n })\n } catch (err) {\n const errorMessage = 'Keycloak initialization failed! Could not load keycloak-js library which is required in the current environment.'\n this.logger.error(\n errorMessage,\n err\n )\n throw new Error(\n errorMessage\n )\n }\n\n if (!this.keycloak) {\n throw new Error('Keycloak initialization failed!')\n }\n\n await this.setupEventListener()\n\n return this.keycloak\n .init({\n onLoad: 'check-sso',\n checkLoginIframe: false,\n silentCheckSsoRedirectUri: enableSilentSSOCheck ? this.getSilentSSOUrl() : undefined,\n idToken: idToken || undefined,\n refreshToken: refreshToken || undefined,\n token: token || undefined,\n timeSkew: timeSkew,\n })\n .catch((err) => {\n this.logger.warn(`Keycloak err: ${err}, try force login`)\n return this.keycloak?.login(this.config)\n })\n .then((loginOk) => {\n if (loginOk) {\n return this.keycloak?.token\n } else {\n return this.keycloak?.login(this.config).then(() => 'login')\n }\n })\n .then(() => {\n return true\n })\n .catch((err) => {\n this.logger.error(`KC ERROR ${err} as json ${JSON.stringify(err)}`)\n throw err\n })\n }\n\n protected async getValidKCConfig(): Promise<KeycloakServerConfig> {\n const clientId = await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_CLIENT_ID)\n if (!clientId) {\n throw new Error('Invalid KC config, missing clientId')\n }\n const realm = await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_REALM)\n if (!realm) {\n throw new Error('Invalid KC config, missing realm')\n }\n const url = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_URL)) ?? ''\n return {\n url,\n clientId,\n realm,\n }\n }\n\n private async setupEventListener() {\n if (this.keycloak) {\n const onTokenExpiredEnabled = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ON_TOKEN_EXPIRED_ENABLED)) === 'true'\n\n const onAuthRefreshErrorEnabled = (await this.configService.getProperty(CONFIG_KEY.KEYCLOAK_ON_AUTH_REFRESH_ERROR_ENABLED)) === 'true'\n\n this.keycloak.onAuthError = () => {\n this.updateLocalStorage()\n }\n this.keycloak.onAuthLogout = () => {\n this.logger.info('SSO logout nav to root')\n this.clearKCStateFromLocalstorage()\n this.keycloak?.login(this.config)\n }\n this.keycloak.onAuthRefreshSuccess = () => {\n this.updateLocalStorage()\n }\n this.keycloak.onAuthRefreshError = () => {\n this.updateLocalStorage()\n if (onAuthRefreshErrorEnabled) {\n this.logger.info('Auth refresh error - initiating re-login')\n this.keycloak?.login(this.config)\n }\n }\n this.keycloak.onAuthSuccess = () => {\n this.updateLocalStorage()\n }\n this.keycloak.onTokenExpired = () => {\n this.updateLocalStorage()\n if (onTokenExpiredEnabled) {\n // A semaphore is used to prevent executing multiple updateToken calls in parallel.\n this.updateTokenSemaphore.use(async () => {\n this.logger.info('Token expired - proactively refreshing')\n this.keycloak?.updateToken()\n })\n }\n }\n this.keycloak.onActionUpdate = () => {\n this.updateLocalStorage()\n }\n this.keycloak.onReady = () => {\n this.updateLocalStorage()\n }\n }\n }\n\n private updateLocalStorage() {\n if (this.keycloak) {\n if (this.keycloak.token) {\n localStorage.setItem(KC_TOKEN_LS, this.keycloak.token)\n } else {\n localStorage.removeItem(KC_TOKEN_LS)\n }\n if (this.keycloak.idToken) {\n localStorage.setItem(KC_ID_TOKEN_LS, this.keycloak.idToken)\n } else {\n localStorage.removeItem(KC_ID_TOKEN_LS)\n }\n if (this.keycloak.refreshToken) {\n localStorage.setItem(KC_REFRESH_TOKEN_LS, this.keycloak.refreshToken)\n } else {\n localStorage.removeItem(KC_REFRESH_TOKEN_LS)\n }\n }\n }\n\n private clearKCStateFromLocalstorage() {\n localStorage.removeItem(KC_ID_TOKEN_LS)\n localStorage.removeItem(KC_TOKEN_LS)\n localStorage.removeItem(KC_REFRESH_TOKEN_LS)\n }\n\n private getSilentSSOUrl() {\n let currentBase = document.getElementsByTagName('base')[0].href\n if (currentBase === '/') {\n currentBase = ''\n }\n return `${currentBase}/assets/silent-check-sso.html`\n }\n\n getIdToken(): string | null {\n return this.keycloak?.idToken ?? null\n }\n getAccessToken(): string | null {\n return this.keycloak?.token ?? null\n }\n\n logout(): void {\n this.keycloak?.logout()\n }\n\n async updateTokenIfNeeded(): Promise<boolean> {\n return this.updateTokenSemaphore.use(async () => {\n if (!this.keycloak?.authenticated) {\n return this.keycloak?.login(this.config).then(() => false) ?? Promise.reject('Keycloak not initialized!')\n }\n\n const minValidity = await this.getConfigValueNumberOrUndefined(CONFIG_KEY.KEYCLOAK_UPDATE_TOKEN_MIN_VALIDITY)\n\n return this.keycloak.updateToken(minValidity)\n })\n }\n\n getAuthProviderName(): string {\n return 'keycloak-auth'\n }\n\n hasRole(_role: string): boolean {\n return false\n }\n\n getUserRoles(): string[] {\n return []\n }\n\n getHeaderValues(): Record<string, string> {\n return { 'apm-principal-token': this.getIdToken() ?? '', Authorization: `Bearer ${this.getAccessToken()}` }\n }\n\n async getConfigValueNumberOrUndefined(configKey: CONFIG_KEY): Promise<number | undefined> {\n const value = await this.configService.getProperty(configKey)\n if (value === undefined) return undefined\n\n const parsed = Number.parseInt(value, 10)\n if (Number.isNaN(parsed)) return undefined\n return parsed\n }\n}\n","declare global {\n interface Window {\n onecxAuth?: {\n authServiceProxy?: {\n v1?: {\n getHeaderValues: () => Record<string, string>\n updateTokenIfNeeded: () => Promise<boolean>\n }\n }\n }\n // Shell defines these properties to support older library versions\n onecxAngularAuth?: {\n authServiceProxy?: {\n v1?: {\n getHeaderValues: () => Record<string, string>\n updateTokenIfNeeded: () => Promise<boolean>\n }\n }\n }\n }\n}\n\nexport default globalThis\n","import { Injectable } from '@angular/core';\nimport { AuthService } from '../auth.service';\n\n@Injectable()\nexport class DisabledAuthService implements AuthService {\n\n public async init(_config?: Record<string, unknown>): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n getIdToken(): string | null {\n return \"\";\n }\n getAccessToken(): string | null {\n return \"\";\n }\n\n logout(): void {\n window.location.href = \"https://github.com/onecx/\";\n }\n\n async updateTokenIfNeeded(): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n getHeaderValues(): Record<string, string> {\n return {};\n }\n}\n","import { loadRemoteModule } from '@angular-architects/module-federation'\nimport { Injectable, Injector, inject } from '@angular/core'\nimport { AppStateService, CONFIG_KEY, ConfigurationService } from '@onecx/angular-integration-interface'\nimport { Config, EventsTopic, EventType } from '@onecx/integration-interface'\nimport { filter } from 'rxjs/internal/operators/filter'\nimport { AuthService, AuthServiceFactory, Injectables } from './auth.service'\nimport { KeycloakAuthService } from './auth_services/keycloak-auth.service'\nimport './declarations'\nimport { DisabledAuthService } from './auth_services/disabled-auth.service'\n\n@Injectable()\nexport class AuthServiceWrapper {\n private configService = inject(ConfigurationService)\n private appStateService = inject(AppStateService)\n private injector = inject(Injector)\n\n private eventsTopic$ = new EventsTopic()\n private authService: AuthService | undefined\n\n constructor() {\n this.eventsTopic$\n .pipe(filter((e) => e.type === EventType.AUTH_LOGOUT_BUTTON_CLICKED))\n .subscribe(() => this.authService?.logout())\n // Shell defines these properties to support older library versions\n window.onecxAngularAuth ??= {}\n window.onecxAngularAuth.authServiceProxy ??= {}\n window.onecxAngularAuth.authServiceProxy.v1 ??= {\n updateTokenIfNeeded: (): Promise<boolean> => {\n return this.updateTokenIfNeeded()\n },\n getHeaderValues: (): Record<string, string> => {\n return this.getHeaderValues()\n },\n }\n window.onecxAuth ??= {}\n window.onecxAuth.authServiceProxy ??= {}\n window.onecxAuth.authServiceProxy.v1 ??= {\n updateTokenIfNeeded: (): Promise<boolean> => {\n return this.updateTokenIfNeeded()\n },\n getHeaderValues: (): Record<string, string> => {\n return this.getHeaderValues()\n },\n }\n }\n async init(): Promise<boolean | undefined> {\n await this.configService.isInitialized\n\n await this.initializeAuthService()\n const initResult = this.getInitResult()\n return initResult\n }\n async getInitResult(): Promise<boolean | undefined> {\n const initResult = await this.authService?.init()\n\n if (initResult) {\n await this.appStateService.isAuthenticated$.publish()\n }\n return initResult\n }\n getHeaderValues(): Record<string, string> {\n return this.authService?.getHeaderValues() ?? {}\n }\n updateTokenIfNeeded(): Promise<boolean> {\n return this.authService?.updateTokenIfNeeded() ?? Promise.reject()\n }\n\n async initializeAuthService(): Promise<void> {\n const serviceTypeConfig = (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE)) ?? 'keycloak'\n\n switch (serviceTypeConfig) {\n case 'keycloak':\n this.authService = this.injector.get(KeycloakAuthService)\n break\n case 'custom': {\n // remote module is exposing function as default export (this is a convention)\n // this function is responsible for creating the custom auth service\n // to have access to the dependency mechanism of the shell\n // the function gets a callback which is returning the requested injectable\n const factory = await this.getAuthServiceFactory()\n this.authService = await Promise.resolve(\n factory((injectable: Injectables) => this.retrieveInjectables(injectable))\n )\n break\n }\n case 'disabled':\n this.authService = this.injector.get(DisabledAuthService)\n break\n default:\n throw new Error('Configured AuthService not found')\n }\n }\n\n async retrieveInjectables(injectable: Injectables): Promise<KeycloakAuthService | Config | undefined> {\n if (injectable === Injectables.KEYCLOAK_AUTH_SERVICE) {\n return this.injector.get(KeycloakAuthService)\n } else if (injectable === Injectables.CONFIG) {\n return this.configService.getConfig()\n }\n throw new Error('unknown injectable type')\n }\n\n async getAuthServiceFactory(): Promise<AuthServiceFactory> {\n if (await !this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) {\n throw new Error('URL of the custom auth service is not defined')\n }\n const module = await loadRemoteModule({\n type: 'module',\n remoteEntry: (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_URL)) ?? '',\n exposedModule:\n (await this.configService.getProperty(CONFIG_KEY.AUTH_SERVICE_CUSTOM_MODULE_NAME)) ?? './CustomAuth',\n })\n return module.default as AuthServiceFactory\n }\n}\n","import { inject, provideAppInitializer } from '@angular/core'\nimport { ConfigurationService } from '@onecx/angular-integration-interface'\nimport { AuthServiceWrapper } from './auth-service-wrapper'\nimport { DisabledAuthService } from './auth_services/disabled-auth.service'\nimport { KeycloakAuthService } from './auth_services/keycloak-auth.service'\n\nfunction provideAuthServices() {\n return [AuthServiceWrapper, KeycloakAuthService, DisabledAuthService]\n}\n\nexport function provideAuthService() {\n return [\n provideAuthServices(),\n provideAppInitializer(async () => {\n const configService = inject(ConfigurationService)\n const authServiceWrapper = inject(AuthServiceWrapper)\n await configService.isInitialized\n await authServiceWrapper.init()\n }),\n ]\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAUA,IAAY,WAGX;AAHD,CAAA,UAAY,WAAW,EAAA;AACrB,I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MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC,+BAA+B,CAAC,KAAK,cAAc;AACvG,SAAA,CAAC;QACF,OAAO,MAAM,CAAC,OAA6B;IAC7C;8GAtGW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;kHAAlB,kBAAkB,EAAA,CAAA,CAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAD9B;;;ACJD,SAAS,mBAAmB,GAAA;AAC1B,IAAA,OAAO,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,CAAC;AACvE;SAEgB,kBAAkB,GAAA;IAChC,OAAO;AACL,QAAA,mBAAmB,EAAE;QACrB,qBAAqB,CAAC,YAAW;AAC/B,YAAA,MAAM,aAAa,GAAG,MAAM,CAAC,oBAAoB,CAAC;AAClD,YAAA,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;YACrD,MAAM,aAAa,CAAC,aAAa;AACjC,YAAA,MAAM,kBAAkB,CAAC,IAAI,EAAE;AACjC,QAAA,CAAC,CAAC;KACH;AACH;;ACpBA;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onecx/shell-auth",
|
|
3
|
+
"version": "8.0.0-rc.10",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/onecx/onecx-portal-ui-libs"
|
|
8
|
+
},
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"@angular-architects/module-federation": "^20.0.0",
|
|
11
|
+
"@angular/core": "^21.0.0",
|
|
12
|
+
"@onecx/accelerator": "^8.0.0-rc.10",
|
|
13
|
+
"@onecx/angular-integration-interface": "^8.0.0-rc.10",
|
|
14
|
+
"@onecx/integration-interface": "^8.0.0-rc.10",
|
|
15
|
+
"keycloak-js": "^26.2.3",
|
|
16
|
+
"ts-semaphore": "^1.0.0",
|
|
17
|
+
"rxjs": "~7.8.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependenciesMeta": {
|
|
20
|
+
"keycloak-js": {
|
|
21
|
+
"optional": true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"module": "fesm2022/onecx-shell-auth.mjs",
|
|
28
|
+
"typings": "types/onecx-shell-auth.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./package.json": {
|
|
31
|
+
"default": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./types/onecx-shell-auth.d.ts",
|
|
35
|
+
"default": "./fesm2022/onecx-shell-auth.mjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"tslib": "^2.3.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Config } from '@onecx/integration-interface';
|
|
2
|
+
import { CONFIG_KEY } from '@onecx/angular-integration-interface';
|
|
3
|
+
import { KeycloakServerConfig } from 'keycloak-js';
|
|
4
|
+
import * as i0 from '@angular/core';
|
|
5
|
+
|
|
6
|
+
interface AuthService {
|
|
7
|
+
init(config?: Record<string, unknown>): Promise<boolean>;
|
|
8
|
+
getHeaderValues(): Record<string, string>;
|
|
9
|
+
logout(): void;
|
|
10
|
+
updateTokenIfNeeded(): Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
declare enum Injectables {
|
|
13
|
+
KEYCLOAK_AUTH_SERVICE = "KEYCLOAK_AUTH_SERVICE",
|
|
14
|
+
CONFIG = "CONFIG"
|
|
15
|
+
}
|
|
16
|
+
type AuthServiceFactory = (injectorFunction: (injectable: Injectables) => Promise<unknown> | unknown) => AuthService | Promise<AuthService>;
|
|
17
|
+
|
|
18
|
+
declare class KeycloakAuthService implements AuthService {
|
|
19
|
+
private readonly logger;
|
|
20
|
+
private configService;
|
|
21
|
+
private keycloak;
|
|
22
|
+
private readonly updateTokenSemaphore;
|
|
23
|
+
config?: Record<string, unknown>;
|
|
24
|
+
init(config?: Record<string, unknown>): Promise<boolean>;
|
|
25
|
+
protected getValidKCConfig(): Promise<KeycloakServerConfig>;
|
|
26
|
+
private setupEventListener;
|
|
27
|
+
private updateLocalStorage;
|
|
28
|
+
private clearKCStateFromLocalstorage;
|
|
29
|
+
private getSilentSSOUrl;
|
|
30
|
+
getIdToken(): string | null;
|
|
31
|
+
getAccessToken(): string | null;
|
|
32
|
+
logout(): void;
|
|
33
|
+
updateTokenIfNeeded(): Promise<boolean>;
|
|
34
|
+
getAuthProviderName(): string;
|
|
35
|
+
hasRole(_role: string): boolean;
|
|
36
|
+
getUserRoles(): string[];
|
|
37
|
+
getHeaderValues(): Record<string, string>;
|
|
38
|
+
getConfigValueNumberOrUndefined(configKey: CONFIG_KEY): Promise<number | undefined>;
|
|
39
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakAuthService, never>;
|
|
40
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakAuthService>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare global {
|
|
44
|
+
interface Window {
|
|
45
|
+
onecxAuth?: {
|
|
46
|
+
authServiceProxy?: {
|
|
47
|
+
v1?: {
|
|
48
|
+
getHeaderValues: () => Record<string, string>;
|
|
49
|
+
updateTokenIfNeeded: () => Promise<boolean>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
onecxAngularAuth?: {
|
|
54
|
+
authServiceProxy?: {
|
|
55
|
+
v1?: {
|
|
56
|
+
getHeaderValues: () => Record<string, string>;
|
|
57
|
+
updateTokenIfNeeded: () => Promise<boolean>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class AuthServiceWrapper {
|
|
65
|
+
private configService;
|
|
66
|
+
private appStateService;
|
|
67
|
+
private injector;
|
|
68
|
+
private eventsTopic$;
|
|
69
|
+
private authService;
|
|
70
|
+
constructor();
|
|
71
|
+
init(): Promise<boolean | undefined>;
|
|
72
|
+
getInitResult(): Promise<boolean | undefined>;
|
|
73
|
+
getHeaderValues(): Record<string, string>;
|
|
74
|
+
updateTokenIfNeeded(): Promise<boolean>;
|
|
75
|
+
initializeAuthService(): Promise<void>;
|
|
76
|
+
retrieveInjectables(injectable: Injectables): Promise<KeycloakAuthService | Config | undefined>;
|
|
77
|
+
getAuthServiceFactory(): Promise<AuthServiceFactory>;
|
|
78
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthServiceWrapper, never>;
|
|
79
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AuthServiceWrapper>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare class DisabledAuthService implements AuthService {
|
|
83
|
+
init(_config?: Record<string, unknown>): Promise<boolean>;
|
|
84
|
+
getIdToken(): string | null;
|
|
85
|
+
getAccessToken(): string | null;
|
|
86
|
+
logout(): void;
|
|
87
|
+
updateTokenIfNeeded(): Promise<boolean>;
|
|
88
|
+
getHeaderValues(): Record<string, string>;
|
|
89
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DisabledAuthService, never>;
|
|
90
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DisabledAuthService>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare function provideAuthService(): ((typeof DisabledAuthService | typeof AuthServiceWrapper)[] | i0.EnvironmentProviders)[];
|
|
94
|
+
|
|
95
|
+
export { AuthServiceWrapper, provideAuthService };
|