@vc-shell/framework 1.0.81 → 1.0.82
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 +4 -0
- package/core/api/platform.ts +188 -67
- package/core/composables/useUser/index.ts +46 -142
- package/dist/core/api/platform.d.ts +36 -5
- package/dist/core/api/platform.d.ts.map +1 -1
- package/dist/core/composables/useUser/index.d.ts +5 -18
- package/dist/core/composables/useUser/index.d.ts.map +1 -1
- package/dist/framework.mjs +13256 -13760
- package/dist/index.css +1 -1
- package/dist/shared/pages/LoginPage/components/login/Login.vue.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/shared/pages/LoginPage/components/login/Login.vue +29 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, Ref, ref, ComputedRef
|
|
1
|
+
import { computed, Ref, ref, ComputedRef } from "vue";
|
|
2
2
|
import ClientOAuth2 from "client-oauth2";
|
|
3
3
|
import {
|
|
4
4
|
UserDetail,
|
|
@@ -7,10 +7,12 @@ import {
|
|
|
7
7
|
SecurityResult,
|
|
8
8
|
ValidatePasswordResetTokenRequest,
|
|
9
9
|
IdentityResult,
|
|
10
|
+
ExternalSignInClient,
|
|
11
|
+
ChangePasswordRequest,
|
|
12
|
+
LoginType,
|
|
13
|
+
ExternalSignInProviderInfo,
|
|
10
14
|
} from "./../../api";
|
|
11
15
|
import { AuthData, RequestPasswordResult, SignInResults } from "./../../types";
|
|
12
|
-
import * as _ from "lodash-es";
|
|
13
|
-
import fetchIntercept from "fetch-intercept";
|
|
14
16
|
import { useLocalStorage } from "@vueuse/core";
|
|
15
17
|
//The Platform Manager uses the same key to store authorization data in the
|
|
16
18
|
//local storage, so we can exchange authorization data between the Platform Manager
|
|
@@ -24,24 +26,12 @@ const authClient = new ClientOAuth2({
|
|
|
24
26
|
accessTokenUri: `/connect/token`,
|
|
25
27
|
scopes: ["offline_access"],
|
|
26
28
|
});
|
|
27
|
-
const activeAuthenticationType = ref();
|
|
28
29
|
const securityClient = new SecurityClient();
|
|
29
|
-
|
|
30
|
-
export interface LoginTypes {
|
|
31
|
-
enabled?: boolean;
|
|
32
|
-
hasLoginForm?: boolean;
|
|
33
|
-
authenticationType?: string;
|
|
34
|
-
priority?: number;
|
|
35
|
-
}
|
|
36
|
-
export interface LoginProviders {
|
|
37
|
-
authenticationType?: string;
|
|
38
|
-
displayName?: string;
|
|
39
|
-
}
|
|
30
|
+
const externalSecurityClient = new ExternalSignInClient();
|
|
40
31
|
|
|
41
32
|
interface IUseUser {
|
|
42
33
|
user: ComputedRef<UserDetail | null>;
|
|
43
34
|
loading: ComputedRef<boolean>;
|
|
44
|
-
isExternalSignedIn: Ref<boolean>;
|
|
45
35
|
getAccessToken: () => Promise<string | null>;
|
|
46
36
|
loadUser: () => Promise<UserDetail>;
|
|
47
37
|
signIn: (username: string, password: string) => Promise<SignInResults>;
|
|
@@ -51,29 +41,18 @@ interface IUseUser {
|
|
|
51
41
|
resetPasswordByToken: (userId: string, password: string, token: string) => Promise<SecurityResult>;
|
|
52
42
|
requestPasswordReset: (loginOrEmail: string) => Promise<RequestPasswordResult>;
|
|
53
43
|
changeUserPassword: (oldPassword: string, newPassword: string) => Promise<SecurityResult>;
|
|
54
|
-
getExternalLoginProviders: () => Promise<
|
|
44
|
+
getExternalLoginProviders: () => Promise<ExternalSignInProviderInfo[]>;
|
|
55
45
|
externalSignIn: (authenticationType?: string | undefined, returnUrl?: string | undefined) => void;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
isAzureAdAuthAvailable: () => Promise<boolean>;
|
|
59
|
-
getAzureAdAuthCaption: () => Promise<string>;
|
|
46
|
+
getLoginType: () => Promise<LoginType[]>;
|
|
47
|
+
isAuthenticated: () => Promise<boolean>;
|
|
60
48
|
}
|
|
61
49
|
|
|
62
50
|
export function useUser(): IUseUser {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(newVal) => {
|
|
69
|
-
if (newVal.value) {
|
|
70
|
-
initInterceptor();
|
|
71
|
-
} else {
|
|
72
|
-
fetchIntercept.clear();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
{ immediate: true }
|
|
76
|
-
);
|
|
51
|
+
const externalSignInStorage = useLocalStorage<{ providerType: string }>("externalSignIn", null);
|
|
52
|
+
|
|
53
|
+
const isAuthenticated = async () => {
|
|
54
|
+
return !!((externalSignInStorage.value && externalSignInStorage.value.providerType) ?? (await getAccessToken()));
|
|
55
|
+
};
|
|
77
56
|
|
|
78
57
|
async function validateToken(userId: string, token: string): Promise<boolean> {
|
|
79
58
|
let result = false;
|
|
@@ -124,7 +103,6 @@ export function useUser(): IUseUser {
|
|
|
124
103
|
console.log("[useUser]: an access token has been obtained successfully", authData.value);
|
|
125
104
|
|
|
126
105
|
storeAuthData(authData.value);
|
|
127
|
-
isExternalSignedIn.value = false;
|
|
128
106
|
}
|
|
129
107
|
await loadUser();
|
|
130
108
|
return { succeeded: true };
|
|
@@ -133,13 +111,14 @@ export function useUser(): IUseUser {
|
|
|
133
111
|
async function signOut(): Promise<void> {
|
|
134
112
|
console.debug(`[@vc-shell/framework#useUser:signOut] - Entry point`);
|
|
135
113
|
|
|
136
|
-
if (
|
|
114
|
+
if (externalSignInStorage.value && externalSignInStorage.value.providerType) {
|
|
115
|
+
externalSignOut(externalSignInStorage.value.providerType);
|
|
116
|
+
storeAuthData({});
|
|
117
|
+
externalSignInStorage.value = null;
|
|
118
|
+
} else {
|
|
137
119
|
user.value = undefined;
|
|
138
120
|
authData.value = undefined;
|
|
139
121
|
storeAuthData({});
|
|
140
|
-
} else {
|
|
141
|
-
externalSignOut(activeAuthenticationType.value);
|
|
142
|
-
activeAuthenticationType.value = undefined;
|
|
143
122
|
}
|
|
144
123
|
}
|
|
145
124
|
|
|
@@ -201,6 +180,7 @@ export function useUser(): IUseUser {
|
|
|
201
180
|
function storeAuthData(authData: AuthData) {
|
|
202
181
|
localStorage.setItem(VC_AUTH_DATA_KEY, JSON.stringify({ ...(authData || {}) }));
|
|
203
182
|
}
|
|
183
|
+
|
|
204
184
|
async function readAuthData(): Promise<AuthData> {
|
|
205
185
|
return (await JSON.parse(localStorage.getItem(VC_AUTH_DATA_KEY) || "{}")) as AuthData;
|
|
206
186
|
}
|
|
@@ -226,27 +206,15 @@ export function useUser(): IUseUser {
|
|
|
226
206
|
const token = await getAccessToken();
|
|
227
207
|
let result;
|
|
228
208
|
|
|
229
|
-
// TODO it's temporary workaround to get valid errors
|
|
230
209
|
if (token) {
|
|
231
210
|
try {
|
|
232
211
|
loading.value = true;
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
"Content-Type": "application/json-patch+json",
|
|
237
|
-
Accept: "text/plain",
|
|
238
|
-
authorization: `Bearer ${token}`,
|
|
239
|
-
},
|
|
240
|
-
body: JSON.stringify({
|
|
241
|
-
oldPassword,
|
|
242
|
-
newPassword,
|
|
243
|
-
}),
|
|
212
|
+
const command = new ChangePasswordRequest({
|
|
213
|
+
oldPassword,
|
|
214
|
+
newPassword,
|
|
244
215
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return JSON.parse(response);
|
|
248
|
-
});
|
|
249
|
-
}
|
|
216
|
+
|
|
217
|
+
result = await securityClient.changeCurrentUserPassword(command);
|
|
250
218
|
} catch (e) {
|
|
251
219
|
return { succeeded: false, errors: [e.message] } as SecurityResult;
|
|
252
220
|
} finally {
|
|
@@ -254,54 +222,42 @@ export function useUser(): IUseUser {
|
|
|
254
222
|
}
|
|
255
223
|
}
|
|
256
224
|
|
|
257
|
-
return result
|
|
225
|
+
return result;
|
|
258
226
|
}
|
|
259
227
|
|
|
260
|
-
async function
|
|
261
|
-
let result = null as
|
|
228
|
+
async function getLoginType(): Promise<LoginType[]> {
|
|
229
|
+
let result = null as LoginType[];
|
|
262
230
|
try {
|
|
263
|
-
|
|
264
|
-
method: "GET",
|
|
265
|
-
headers: {},
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const response = await fetchResult.text();
|
|
269
|
-
if (response && response.trim()) {
|
|
270
|
-
result = JSON.parse(response) as LoginTypes[];
|
|
271
|
-
}
|
|
231
|
+
result = await securityClient.getLoginTypes();
|
|
272
232
|
} catch (e) {
|
|
273
233
|
console.error(e);
|
|
274
|
-
|
|
275
234
|
throw e;
|
|
276
235
|
}
|
|
277
236
|
|
|
278
237
|
return result;
|
|
279
238
|
}
|
|
280
239
|
|
|
281
|
-
async function getExternalLoginProviders(): Promise<
|
|
282
|
-
let result = null as
|
|
240
|
+
async function getExternalLoginProviders(): Promise<ExternalSignInProviderInfo[]> {
|
|
241
|
+
let result = null as ExternalSignInProviderInfo[];
|
|
283
242
|
try {
|
|
284
|
-
|
|
285
|
-
method: "GET",
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
const response = await fetchResult.text();
|
|
289
|
-
if (response && response.trim()) {
|
|
290
|
-
result = JSON.parse(response) as LoginProviders[];
|
|
291
|
-
}
|
|
243
|
+
result = await externalSecurityClient.getExternalLoginProviders();
|
|
292
244
|
} catch (e) {
|
|
293
245
|
console.error(e);
|
|
294
|
-
|
|
295
|
-
throw e;
|
|
296
246
|
}
|
|
297
247
|
|
|
298
248
|
return result;
|
|
299
249
|
}
|
|
300
250
|
|
|
301
|
-
async function externalSignIn(authenticationType
|
|
302
|
-
activeAuthenticationType.value = authenticationType;
|
|
251
|
+
async function externalSignIn(authenticationType: string | undefined, returnUrl: string | undefined) {
|
|
303
252
|
try {
|
|
304
|
-
let url_ =
|
|
253
|
+
let url_ = "externalsignin?";
|
|
254
|
+
|
|
255
|
+
const signInData = {
|
|
256
|
+
providerType: authenticationType,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
externalSignInStorage.value = signInData;
|
|
260
|
+
|
|
305
261
|
if (authenticationType === null) throw new Error("The parameter 'authenticationType' cannot be null.");
|
|
306
262
|
else {
|
|
307
263
|
if (authenticationType !== undefined)
|
|
@@ -309,78 +265,29 @@ export function useUser(): IUseUser {
|
|
|
309
265
|
if (returnUrl !== undefined) url_ += "returnUrl=" + encodeURIComponent("" + returnUrl) + "&";
|
|
310
266
|
}
|
|
311
267
|
url_ = url_.replace(/[?&]$/, "");
|
|
312
|
-
isExternalSignedIn.value = true;
|
|
313
268
|
|
|
314
269
|
window.location.href = url_;
|
|
315
270
|
} catch (e) {
|
|
316
|
-
isExternalSignedIn.value = false;
|
|
317
271
|
console.error(e);
|
|
318
272
|
|
|
319
273
|
throw e;
|
|
320
274
|
}
|
|
321
275
|
}
|
|
322
276
|
|
|
323
|
-
async function externalSignOut(authenticationType
|
|
277
|
+
async function externalSignOut(authenticationType: string | undefined): Promise<void> {
|
|
324
278
|
try {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
else {
|
|
328
|
-
if (authenticationType !== undefined)
|
|
329
|
-
url_ += "authenticationType=" + encodeURIComponent("" + authenticationType) + "&";
|
|
330
|
-
}
|
|
331
|
-
url_ = url_.replace(/[?&]$/, "");
|
|
332
|
-
|
|
333
|
-
await fetch(url_, {
|
|
334
|
-
method: "GET",
|
|
335
|
-
headers: {},
|
|
336
|
-
});
|
|
279
|
+
const url = "externalsignin/signout?authenticationType=" + authenticationType;
|
|
280
|
+
window.location.href = url;
|
|
337
281
|
} catch (e) {
|
|
338
282
|
console.error(e);
|
|
339
|
-
|
|
340
283
|
throw e;
|
|
341
284
|
}
|
|
342
|
-
isExternalSignedIn.value = false;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
async function isAzureAdAuthAvailable(): Promise<boolean> {
|
|
346
|
-
const loginTypes = await getLoginTypes();
|
|
347
|
-
if (loginTypes) {
|
|
348
|
-
return (
|
|
349
|
-
loginTypes.filter((x) => x.authenticationType === "AzureAD").length > 0 &&
|
|
350
|
-
loginTypes.find((x) => x.authenticationType === "AzureAD").enabled
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
async function getAzureAdAuthCaption(): Promise<string> {
|
|
357
|
-
const loginProviders = await getExternalLoginProviders();
|
|
358
|
-
if (loginProviders) {
|
|
359
|
-
return loginProviders.find((x) => x.authenticationType === "AzureAD").displayName;
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/* Intercepting requests to explicitly remove auth token when we use AzureAd authentication */
|
|
365
|
-
function initInterceptor() {
|
|
366
|
-
console.log("[@vc-shell/framework#useUser:initInterceptor]: Entry point");
|
|
367
|
-
// store external login in localStorage
|
|
368
|
-
return fetchIntercept.register({
|
|
369
|
-
request: function (_url, config) {
|
|
370
|
-
if (isExternalSignedIn.value) {
|
|
371
|
-
const edited = _.omit(config.headers, "authorization");
|
|
372
|
-
config.headers = edited;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return [_url, config];
|
|
376
|
-
},
|
|
377
|
-
});
|
|
378
285
|
}
|
|
379
286
|
|
|
380
287
|
return {
|
|
381
288
|
user: computed(() => user.value),
|
|
382
289
|
loading: computed(() => loading.value),
|
|
383
|
-
|
|
290
|
+
isAuthenticated,
|
|
384
291
|
getAccessToken,
|
|
385
292
|
loadUser,
|
|
386
293
|
signIn,
|
|
@@ -392,9 +299,6 @@ export function useUser(): IUseUser {
|
|
|
392
299
|
changeUserPassword,
|
|
393
300
|
getExternalLoginProviders,
|
|
394
301
|
externalSignIn,
|
|
395
|
-
|
|
396
|
-
getLoginTypes,
|
|
397
|
-
isAzureAdAuthAvailable,
|
|
398
|
-
getAzureAdAuthCaption,
|
|
302
|
+
getLoginType,
|
|
399
303
|
};
|
|
400
304
|
}
|
|
@@ -27,9 +27,10 @@ export declare class ExternalSignInClient extends AuthApiBase {
|
|
|
27
27
|
});
|
|
28
28
|
/**
|
|
29
29
|
* @param authenticationType (optional)
|
|
30
|
+
* @param returnUrl (optional)
|
|
30
31
|
* @return Success
|
|
31
32
|
*/
|
|
32
|
-
signIn(authenticationType?: string | undefined): Promise<void>;
|
|
33
|
+
signIn(authenticationType?: string | undefined, returnUrl?: string | undefined): Promise<void>;
|
|
33
34
|
protected processSignIn(response: Response): Promise<void>;
|
|
34
35
|
/**
|
|
35
36
|
* @param authenticationType (optional)
|
|
@@ -46,8 +47,8 @@ export declare class ExternalSignInClient extends AuthApiBase {
|
|
|
46
47
|
/**
|
|
47
48
|
* @return Success
|
|
48
49
|
*/
|
|
49
|
-
getExternalLoginProviders(): Promise<
|
|
50
|
-
protected processGetExternalLoginProviders(response: Response): Promise<
|
|
50
|
+
getExternalLoginProviders(): Promise<ExternalSignInProviderInfo[]>;
|
|
51
|
+
protected processGetExternalLoginProviders(response: Response): Promise<ExternalSignInProviderInfo[]>;
|
|
51
52
|
}
|
|
52
53
|
export declare class AppsClient extends AuthApiBase {
|
|
53
54
|
private http;
|
|
@@ -503,8 +504,8 @@ export declare class SecurityClient extends AuthApiBase {
|
|
|
503
504
|
/**
|
|
504
505
|
* @return Success
|
|
505
506
|
*/
|
|
506
|
-
getLoginTypes(): Promise<
|
|
507
|
-
protected processGetLoginTypes(response: Response): Promise<
|
|
507
|
+
getLoginTypes(): Promise<LoginType[]>;
|
|
508
|
+
protected processGetLoginTypes(response: Response): Promise<LoginType[]>;
|
|
508
509
|
/**
|
|
509
510
|
* @return Success
|
|
510
511
|
*/
|
|
@@ -625,6 +626,7 @@ export declare class ApplicationUser implements IApplicationUser {
|
|
|
625
626
|
passwordExpired?: boolean;
|
|
626
627
|
lastPasswordChangedDate?: Date | undefined;
|
|
627
628
|
lastPasswordChangeRequestDate?: Date | undefined;
|
|
629
|
+
lastLoginDate?: Date | undefined;
|
|
628
630
|
id?: string | undefined;
|
|
629
631
|
userName?: string | undefined;
|
|
630
632
|
normalizedUserName?: string | undefined;
|
|
@@ -665,6 +667,7 @@ export interface IApplicationUser {
|
|
|
665
667
|
passwordExpired?: boolean;
|
|
666
668
|
lastPasswordChangedDate?: Date | undefined;
|
|
667
669
|
lastPasswordChangeRequestDate?: Date | undefined;
|
|
670
|
+
lastLoginDate?: Date | undefined;
|
|
668
671
|
id?: string | undefined;
|
|
669
672
|
userName?: string | undefined;
|
|
670
673
|
normalizedUserName?: string | undefined;
|
|
@@ -1109,6 +1112,18 @@ export declare enum EntryState {
|
|
|
1109
1112
|
Deleted = "Deleted",
|
|
1110
1113
|
Modified = "Modified"
|
|
1111
1114
|
}
|
|
1115
|
+
export declare class ExternalSignInProviderInfo implements IExternalSignInProviderInfo {
|
|
1116
|
+
authenticationType?: string | undefined;
|
|
1117
|
+
displayName?: string | undefined;
|
|
1118
|
+
constructor(data?: IExternalSignInProviderInfo);
|
|
1119
|
+
init(_data?: any): void;
|
|
1120
|
+
static fromJS(data: any): ExternalSignInProviderInfo;
|
|
1121
|
+
toJSON(data?: any): any;
|
|
1122
|
+
}
|
|
1123
|
+
export interface IExternalSignInProviderInfo {
|
|
1124
|
+
authenticationType?: string | undefined;
|
|
1125
|
+
displayName?: string | undefined;
|
|
1126
|
+
}
|
|
1112
1127
|
export declare class IdentityError implements IIdentityError {
|
|
1113
1128
|
code?: string | undefined;
|
|
1114
1129
|
description?: string | undefined;
|
|
@@ -1211,6 +1226,22 @@ export interface ILoginRequest {
|
|
|
1211
1226
|
password?: string | undefined;
|
|
1212
1227
|
rememberMe?: boolean;
|
|
1213
1228
|
}
|
|
1229
|
+
export declare class LoginType implements ILoginType {
|
|
1230
|
+
enabled?: boolean;
|
|
1231
|
+
hasLoginForm?: boolean;
|
|
1232
|
+
authenticationType?: string | undefined;
|
|
1233
|
+
priority?: number;
|
|
1234
|
+
constructor(data?: ILoginType);
|
|
1235
|
+
init(_data?: any): void;
|
|
1236
|
+
static fromJS(data: any): LoginType;
|
|
1237
|
+
toJSON(data?: any): any;
|
|
1238
|
+
}
|
|
1239
|
+
export interface ILoginType {
|
|
1240
|
+
enabled?: boolean;
|
|
1241
|
+
hasLoginForm?: boolean;
|
|
1242
|
+
authenticationType?: string | undefined;
|
|
1243
|
+
priority?: number;
|
|
1244
|
+
}
|
|
1214
1245
|
export declare class ModuleAutoInstallPushNotification implements IModuleAutoInstallPushNotification {
|
|
1215
1246
|
started?: Date | undefined;
|
|
1216
1247
|
finished?: Date | undefined;
|