@genesislcap/foundation-auth 14.71.1-auth-mf.3 → 14.71.1-auth-mf.4
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/dist/dts/dto/EVENT_LOGIN_DETAILS_ACK.d.ts +7 -0
- package/dist/dts/dto/EVENT_LOGIN_DETAILS_ACK.d.ts.map +1 -0
- package/dist/dts/dto/index.d.ts +1 -0
- package/dist/dts/dto/index.d.ts.map +1 -1
- package/dist/dts/entity/index.d.ts +1 -0
- package/dist/dts/entity/index.d.ts.map +1 -1
- package/dist/dts/entity/loginDetailsAck.d.ts +7 -0
- package/dist/dts/entity/loginDetailsAck.d.ts.map +1 -0
- package/dist/dts/machine/machine.d.ts +12 -1
- package/dist/dts/machine/machine.d.ts.map +1 -1
- package/dist/dts/machine/types.d.ts +3 -5
- package/dist/dts/machine/types.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +14 -4
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/mapper/loginMapper.d.ts +16 -4
- package/dist/dts/mapper/loginMapper.d.ts.map +1 -1
- package/dist/dts/routes/base.d.ts +6 -15
- package/dist/dts/routes/base.d.ts.map +1 -1
- package/dist/dts/routes/config.d.ts.map +1 -1
- package/dist/dts/routes/login/login.d.ts +5 -5
- package/dist/dts/routes/login/login.d.ts.map +1 -1
- package/dist/dts/routes/login/login.template.d.ts.map +1 -1
- package/dist/dts/store/auth.d.ts +2 -1
- package/dist/dts/store/auth.d.ts.map +1 -1
- package/dist/dts/store/authFormEntry.d.ts +3 -0
- package/dist/dts/store/authFormEntry.d.ts.map +1 -1
- package/dist/esm/dto/EVENT_LOGIN_DETAILS_ACK.js +1 -0
- package/dist/esm/entity/index.js +1 -0
- package/dist/esm/entity/loginDetailsAck.js +1 -0
- package/dist/esm/machine/machine.js +135 -169
- package/dist/esm/main/main.js +42 -6
- package/dist/esm/mapper/loginMapper.js +17 -1
- package/dist/esm/routes/base.js +3 -30
- package/dist/esm/routes/config.js +0 -2
- package/dist/esm/routes/login/login.js +44 -61
- package/dist/esm/routes/login/login.template.js +4 -5
- package/dist/esm/store/auth.js +1 -0
- package/dist/esm/store/authFormEntry.js +1 -3
- package/dist/foundation-auth.api.json +550 -19
- package/dist/foundation-auth.d.ts +64 -26
- package/docs/api/foundation-auth.auth.loginwithcookies.md +15 -0
- package/docs/api/foundation-auth.auth.loginwithcredentials.md +22 -0
- package/docs/api/{foundation-auth.auth.store.md → foundation-auth.auth.logout.md} +7 -3
- package/docs/api/foundation-auth.auth.md +6 -4
- package/docs/api/foundation-auth.autheventmap.md +0 -1
- package/docs/api/foundation-auth.authformentryeventmap.md +1 -0
- package/docs/api/foundation-auth.authformentrystore.md +1 -0
- package/docs/api/foundation-auth.authformentrystore.onautofillform.md +22 -0
- package/docs/api/foundation-auth.authmachinecontext.authdto.md +1 -1
- package/docs/api/foundation-auth.authmachinecontext.authentity.md +1 -1
- package/docs/api/foundation-auth.authmachinecontext.credentials.md +1 -1
- package/docs/api/foundation-auth.authmachinecontext.md +2 -2
- package/docs/api/foundation-auth.authmachineevent.md +0 -2
- package/docs/api/foundation-auth.authstore.md +1 -0
- package/docs/api/foundation-auth.authstore.onlogindetails.md +22 -0
- package/docs/api/foundation-auth.defaultauthformentrystore.md +1 -0
- package/docs/api/foundation-auth.defaultauthformentrystore.onautofillform.md +11 -0
- package/docs/api/foundation-auth.defaultauthmachine.addloginevents.md +23 -0
- package/docs/api/foundation-auth.defaultauthmachine.createfetchmachineevent.md +23 -0
- package/docs/api/foundation-auth.defaultauthmachine.md +2 -0
- package/docs/api/foundation-auth.defaultauthstore.md +1 -0
- package/docs/api/foundation-auth.defaultauthstore.onlogindetails.md +11 -0
- package/docs/api/foundation-auth.event_login_details_ack.md +14 -0
- package/docs/api/foundation-auth.islogindetailsackdto.md +24 -0
- package/docs/api/foundation-auth.islogindetailsackentity.md +24 -0
- package/docs/api/foundation-auth.logindetailsack.md +14 -0
- package/docs/api/foundation-auth.logindto.md +2 -2
- package/docs/api/foundation-auth.loginentity.md +2 -2
- package/docs/api/foundation-auth.md +4 -0
- package/docs/api-report.md +54 -13
- package/package.json +11 -11
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __param } from "tslib";
|
|
2
2
|
import { Connect, CredentialManager, MessageBuilder } from '@genesislcap/foundation-comms';
|
|
3
|
-
import { AbstractMachine, createErrorStateNode, FetchMachine, isDoneInvokeEvent, isErrorEvent, MappingError, setError, } from '@genesislcap/foundation-state-machine';
|
|
3
|
+
import { AbstractMachine, createErrorStateNode, FetchMachine, isDoneInvokeEvent, isErrorEvent, isUnauthorizedError, MappingError, setError, } from '@genesislcap/foundation-state-machine';
|
|
4
4
|
import { UUID } from '@genesislcap/foundation-utils';
|
|
5
5
|
import { DI } from '@microsoft/fast-foundation';
|
|
6
|
-
import { and, assign, createMachine, fromPromise, not, sendTo } from 'xstate';
|
|
6
|
+
import { and, assign, createMachine, fromPromise, not, or, sendTo } from 'xstate';
|
|
7
7
|
import { User } from '../entity';
|
|
8
|
-
import { LOGIN_DETAILS_URL,
|
|
8
|
+
import { LOGIN_DETAILS_URL, LOGIN_URL, LOGOUT_URL, SOCKET_URL } from '../env';
|
|
9
9
|
import { AuthConfig } from '../main/config';
|
|
10
|
-
import { isLoginAckEntity, isLoginNackEntity, isLogoutAckEntity, isLogoutNackEntity, LoginMapper, LogoutMapper, } from '../mapper';
|
|
10
|
+
import { isLoginAckEntity, isLoginDetailsAckEntity, isLoginNackEntity, isLogoutAckEntity, isLogoutNackEntity, LoginMapper, LogoutMapper, } from '../mapper';
|
|
11
11
|
import { logger } from '../utils';
|
|
12
12
|
import { isAuthError } from './errors';
|
|
13
13
|
import { defaultAuthMachineContext } from './types';
|
|
@@ -30,8 +30,18 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
30
30
|
this.machine = createMachine({
|
|
31
31
|
id: 'authMachine',
|
|
32
32
|
context: ({ input }) => (Object.assign({}, input)),
|
|
33
|
-
initial: '
|
|
33
|
+
initial: 'idle',
|
|
34
34
|
states: {
|
|
35
|
+
/**
|
|
36
|
+
* Idle, waiting for event
|
|
37
|
+
*/
|
|
38
|
+
idle: {
|
|
39
|
+
tags: ['idle'],
|
|
40
|
+
on: Object.assign({}, this.addLoginEvents()),
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Check authentication status
|
|
44
|
+
*/
|
|
35
45
|
authCheck: {
|
|
36
46
|
tags: ['authCheck', 'pending'],
|
|
37
47
|
meta: {
|
|
@@ -47,125 +57,109 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
47
57
|
},
|
|
48
58
|
],
|
|
49
59
|
},
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Attempt silent login via cookies (this returns the same user information as login when authorised)
|
|
62
|
+
*/
|
|
63
|
+
loginDetails: {
|
|
64
|
+
tags: ['loginDetails', 'pending'],
|
|
52
65
|
meta: {
|
|
53
|
-
content: '
|
|
66
|
+
content: 'Getting login details, please wait.',
|
|
54
67
|
},
|
|
55
68
|
invoke: {
|
|
56
|
-
id: '
|
|
69
|
+
id: 'loginDetailsFetcher',
|
|
57
70
|
src: fetchMachine.machine,
|
|
58
71
|
onDone: {
|
|
59
72
|
actions: ['setAuthDTO'],
|
|
60
73
|
target: 'mapAuthEntity',
|
|
61
74
|
},
|
|
62
|
-
onError:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
onError: [
|
|
76
|
+
{
|
|
77
|
+
guard: 'isUnauthorizedError',
|
|
78
|
+
target: 'loggedOut',
|
|
66
79
|
},
|
|
67
|
-
|
|
80
|
+
{
|
|
81
|
+
target: 'error.loginDetails',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
68
84
|
},
|
|
69
85
|
entry: [
|
|
70
86
|
'setLoginMapper',
|
|
71
|
-
sendTo('
|
|
72
|
-
const { credentials } = context;
|
|
73
|
-
const message = this.messageBuilder.createLoginMessage(credentials);
|
|
74
|
-
return {
|
|
75
|
-
type: 'fetch',
|
|
76
|
-
params: {
|
|
77
|
-
url: LOGIN_URL,
|
|
78
|
-
requestInit: {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
body: JSON.stringify(message),
|
|
81
|
-
headers: this.messageBuilder.createHTTPHeadersFromMessage(message),
|
|
82
|
-
credentials: 'include',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}),
|
|
87
|
+
sendTo('loginDetailsFetcher', this.createFetchMachineEvent(LOGIN_DETAILS_URL)),
|
|
87
88
|
],
|
|
88
89
|
},
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Login with user credentials or tokens
|
|
92
|
+
*/
|
|
93
|
+
loggingIn: {
|
|
94
|
+
tags: ['loggingIn', 'pending'],
|
|
91
95
|
meta: {
|
|
92
|
-
content: '
|
|
96
|
+
content: 'Logging in, please wait.',
|
|
93
97
|
},
|
|
94
98
|
invoke: {
|
|
95
|
-
id: '
|
|
99
|
+
id: 'loginFetcher',
|
|
96
100
|
src: fetchMachine.machine,
|
|
97
101
|
onDone: {
|
|
98
102
|
actions: ['setAuthDTO'],
|
|
99
103
|
target: 'mapAuthEntity',
|
|
100
104
|
},
|
|
101
|
-
onError: 'error.
|
|
105
|
+
onError: 'error.login',
|
|
102
106
|
},
|
|
103
107
|
entry: [
|
|
104
108
|
'setLoginMapper',
|
|
105
|
-
sendTo('
|
|
106
|
-
const message = {
|
|
107
|
-
SOURCE_REF: this.uuid.createId(),
|
|
108
|
-
// SESSION_AUTH_TOKEN: this.session.getSessionStorageItem('authToken'),
|
|
109
|
-
// MESSAGE_TYPE: EventMessageType.EVENT_LOGIN_AUTH,
|
|
110
|
-
// DETAILS: {
|
|
111
|
-
// REFRESH_AUTH_TOKEN: this.session.getSessionStorageItem('refreshToken'),
|
|
112
|
-
// },
|
|
113
|
-
};
|
|
114
|
-
return {
|
|
115
|
-
type: 'fetch',
|
|
116
|
-
params: {
|
|
117
|
-
url: LOGIN_REFRESH_URL,
|
|
118
|
-
requestInit: {
|
|
119
|
-
method: 'POST',
|
|
120
|
-
body: JSON.stringify(message),
|
|
121
|
-
headers: this.messageBuilder.createHTTPHeadersFromMessage(message),
|
|
122
|
-
credentials: 'include',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}),
|
|
109
|
+
sendTo('loginFetcher', ({ context }) => this.createFetchMachineEvent(LOGIN_URL, this.messageBuilder.createLoginMessage(context.credentials))),
|
|
127
110
|
],
|
|
128
111
|
},
|
|
129
|
-
|
|
130
|
-
tags: ['
|
|
112
|
+
loggedIn: {
|
|
113
|
+
tags: ['loggedIn'],
|
|
131
114
|
meta: {
|
|
132
|
-
content: '
|
|
115
|
+
content: 'Logged in.',
|
|
116
|
+
},
|
|
117
|
+
entry: ['storeCredentials', 'loggedInCallback', 'routeToRedirectUrl'],
|
|
118
|
+
on: {
|
|
119
|
+
logout: {
|
|
120
|
+
target: '#authMachine.loggingOut',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Logout
|
|
126
|
+
*/
|
|
127
|
+
loggingOut: {
|
|
128
|
+
tags: ['loggingOut', 'pending'],
|
|
129
|
+
meta: {
|
|
130
|
+
content: 'Logging out, please wait.',
|
|
133
131
|
},
|
|
134
132
|
invoke: {
|
|
135
|
-
id: '
|
|
133
|
+
id: 'logoutFetcher',
|
|
136
134
|
src: fetchMachine.machine,
|
|
137
135
|
onDone: {
|
|
138
136
|
actions: ['setAuthDTO'],
|
|
139
137
|
target: 'mapAuthEntity',
|
|
140
138
|
},
|
|
141
|
-
onError: 'error.
|
|
139
|
+
onError: 'error.logout',
|
|
142
140
|
},
|
|
143
141
|
entry: [
|
|
144
|
-
'
|
|
145
|
-
sendTo('
|
|
146
|
-
const message = {
|
|
147
|
-
SOURCE_REF: this.uuid.createId(),
|
|
148
|
-
// SESSION_AUTH_TOKEN: this.session.getSessionStorageItem('authToken'),
|
|
149
|
-
// MESSAGE_TYPE: EventMessageType.EVENT_LOGIN_AUTH,
|
|
150
|
-
// DETAILS: {
|
|
151
|
-
// REFRESH_AUTH_TOKEN: this.session.getSessionStorageItem('refreshToken'),
|
|
152
|
-
// },
|
|
153
|
-
};
|
|
154
|
-
return {
|
|
155
|
-
type: 'fetch',
|
|
156
|
-
params: {
|
|
157
|
-
url: LOGIN_DETAILS_URL,
|
|
158
|
-
requestInit: {
|
|
159
|
-
method: 'POST',
|
|
160
|
-
body: JSON.stringify(message),
|
|
161
|
-
headers: this.messageBuilder.createHTTPHeadersFromMessage(message),
|
|
162
|
-
credentials: 'include',
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}),
|
|
142
|
+
'setLogoutMapper',
|
|
143
|
+
sendTo('logoutFetcher', this.createFetchMachineEvent(LOGOUT_URL)),
|
|
167
144
|
],
|
|
168
145
|
},
|
|
146
|
+
loggedOut: {
|
|
147
|
+
tags: ['loggedOut'],
|
|
148
|
+
meta: {
|
|
149
|
+
content: 'Logged out.',
|
|
150
|
+
},
|
|
151
|
+
entry: [
|
|
152
|
+
'unsetUser',
|
|
153
|
+
'trackUserPath',
|
|
154
|
+
'preventSilentAccess',
|
|
155
|
+
'loggedOutCallback',
|
|
156
|
+
'routeToRootUrl',
|
|
157
|
+
],
|
|
158
|
+
on: Object.assign({}, this.addLoginEvents()),
|
|
159
|
+
},
|
|
160
|
+
/**
|
|
161
|
+
* Map the server responses to entities
|
|
162
|
+
*/
|
|
169
163
|
mapAuthEntity: {
|
|
170
164
|
tags: ['mapAuthEntity', 'pending'],
|
|
171
165
|
meta: {
|
|
@@ -184,6 +178,24 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
184
178
|
onError: '#authMachine.error.mapping',
|
|
185
179
|
},
|
|
186
180
|
},
|
|
181
|
+
/**
|
|
182
|
+
* Check entity types and drive next step
|
|
183
|
+
*/
|
|
184
|
+
loginNackCheck: {
|
|
185
|
+
tags: ['loginNackCheck', 'pending'],
|
|
186
|
+
meta: {
|
|
187
|
+
content: 'Login nack, check details, please wait.',
|
|
188
|
+
},
|
|
189
|
+
always: [
|
|
190
|
+
{
|
|
191
|
+
guard: 'isMFARequired',
|
|
192
|
+
target: '#authMachine.error.mfaRequired',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
target: '#authMachine.error.login',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
187
199
|
entityCheck: {
|
|
188
200
|
tags: ['entityCheck', 'pending'],
|
|
189
201
|
meta: {
|
|
@@ -191,7 +203,7 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
191
203
|
},
|
|
192
204
|
always: [
|
|
193
205
|
{
|
|
194
|
-
guard: 'isLoginAckEntity',
|
|
206
|
+
guard: or(['isLoginAckEntity', 'isLoginDetailsAckEntity']),
|
|
195
207
|
actions: ['setUser'],
|
|
196
208
|
target: '#authMachine.authCheck',
|
|
197
209
|
},
|
|
@@ -213,21 +225,9 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
213
225
|
},
|
|
214
226
|
],
|
|
215
227
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
content: 'Login nack, check details, please wait.',
|
|
220
|
-
},
|
|
221
|
-
always: [
|
|
222
|
-
{
|
|
223
|
-
guard: 'isMFARequired',
|
|
224
|
-
target: '#authMachine.error.mfaRequired',
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
target: '#authMachine.error.login',
|
|
228
|
-
},
|
|
229
|
-
],
|
|
230
|
-
},
|
|
228
|
+
/**
|
|
229
|
+
* Testing states (most will go)
|
|
230
|
+
*/
|
|
231
231
|
connectionCheck: {
|
|
232
232
|
tags: ['connectionCheck', 'pending'],
|
|
233
233
|
meta: {
|
|
@@ -255,48 +255,6 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
255
255
|
content: 'Disconnected (NEEDS TO MOVE OUT).',
|
|
256
256
|
},
|
|
257
257
|
},
|
|
258
|
-
loggedIn: {
|
|
259
|
-
tags: ['loggedIn'],
|
|
260
|
-
meta: {
|
|
261
|
-
content: 'Logged in.',
|
|
262
|
-
},
|
|
263
|
-
entry: ['storeCredentials', 'loggedInCallback', 'routeToRedirectUrl'],
|
|
264
|
-
},
|
|
265
|
-
loggingOut: {
|
|
266
|
-
tags: ['loggingOut', 'pending'],
|
|
267
|
-
meta: {
|
|
268
|
-
content: 'Logging out, please wait.',
|
|
269
|
-
},
|
|
270
|
-
invoke: {
|
|
271
|
-
id: 'logoutViaFetch',
|
|
272
|
-
src: fetchMachine.machine,
|
|
273
|
-
onDone: {
|
|
274
|
-
actions: ['setAuthDTO'],
|
|
275
|
-
target: 'mapAuthEntity',
|
|
276
|
-
},
|
|
277
|
-
onError: 'error.logout',
|
|
278
|
-
},
|
|
279
|
-
entry: [
|
|
280
|
-
'setLogoutMapper',
|
|
281
|
-
sendTo('logoutViaFetch', ({ context }) => {
|
|
282
|
-
const headers = {
|
|
283
|
-
'Content-type': 'application/json; charset=UTF-8',
|
|
284
|
-
SOURCE_REF: this.uuid.createId(),
|
|
285
|
-
};
|
|
286
|
-
return {
|
|
287
|
-
type: 'fetch',
|
|
288
|
-
params: {
|
|
289
|
-
url: LOGOUT_URL,
|
|
290
|
-
requestInit: {
|
|
291
|
-
method: 'POST',
|
|
292
|
-
headers,
|
|
293
|
-
credentials: 'include',
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}),
|
|
298
|
-
],
|
|
299
|
-
},
|
|
300
258
|
openSocketTest: {
|
|
301
259
|
tags: ['openSocketTest', 'pending'],
|
|
302
260
|
meta: {
|
|
@@ -341,46 +299,26 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
341
299
|
// }
|
|
342
300
|
// }
|
|
343
301
|
},
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
content: 'Logged out.',
|
|
348
|
-
},
|
|
349
|
-
/**
|
|
350
|
-
* clear up data points...
|
|
351
|
-
*/
|
|
352
|
-
entry: ['trackUserPath', 'preventSilentAccess', 'loggedOutCallback', 'routeToRootUrl'],
|
|
353
|
-
},
|
|
302
|
+
/**
|
|
303
|
+
* Error states
|
|
304
|
+
*/
|
|
354
305
|
error: {
|
|
355
306
|
initial: 'unknown',
|
|
356
307
|
entry: ['setError', 'errorCallback'],
|
|
357
308
|
states: {
|
|
358
309
|
unknown: createErrorStateNode('unknown', 'Unknown error.'),
|
|
359
310
|
login: createErrorStateNode('login', 'Login error.'),
|
|
360
|
-
refresh: createErrorStateNode('refresh', 'Refresh error.'),
|
|
361
311
|
loginDetails: createErrorStateNode('login-details', 'Getting login details error.'),
|
|
362
312
|
mfaRequired: createErrorStateNode('mfa-required', 'MFA required error.'),
|
|
363
313
|
logout: createErrorStateNode('logout', 'Logout error.'),
|
|
364
314
|
mapping: createErrorStateNode('mapping', 'Mapping error.'),
|
|
365
315
|
connect: createErrorStateNode('connect', 'Connection error.'),
|
|
366
316
|
disconnect: createErrorStateNode('disconnect', 'Disconnection error.'),
|
|
317
|
+
auth: createErrorStateNode('Auth', 'Auth error.'),
|
|
367
318
|
},
|
|
368
319
|
},
|
|
369
320
|
},
|
|
370
321
|
on: {
|
|
371
|
-
login: {
|
|
372
|
-
actions: ['resetContext', 'setCredentials'],
|
|
373
|
-
target: '#authMachine.loggingIn',
|
|
374
|
-
},
|
|
375
|
-
refresh: {
|
|
376
|
-
target: '#authMachine.refreshing',
|
|
377
|
-
},
|
|
378
|
-
['login-details']: {
|
|
379
|
-
target: '#authMachine.loginDetails',
|
|
380
|
-
},
|
|
381
|
-
logout: {
|
|
382
|
-
target: '#authMachine.loggingOut',
|
|
383
|
-
},
|
|
384
322
|
openSocket: {
|
|
385
323
|
target: '#authMachine.openSocketTest',
|
|
386
324
|
},
|
|
@@ -411,7 +349,6 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
411
349
|
throw new MappingError(dto); // < what about stack?
|
|
412
350
|
}
|
|
413
351
|
})),
|
|
414
|
-
// socket: fromObservable(() => {})
|
|
415
352
|
connect: fromPromise(({ input }) => __awaiter(this, void 0, void 0, function* () { return this.connect.connect(SOCKET_URL); })),
|
|
416
353
|
disconnect: fromPromise(({ input }) => __awaiter(this, void 0, void 0, function* () { return this.connect.disconnect(); })),
|
|
417
354
|
},
|
|
@@ -465,7 +402,8 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
465
402
|
yield this.credentialManager.preventSilentAccess();
|
|
466
403
|
}),
|
|
467
404
|
storeCredentials: ({ context }) => {
|
|
468
|
-
|
|
405
|
+
var _a;
|
|
406
|
+
if (((_a = context.credentials) === null || _a === void 0 ? void 0 : _a.type) === 'BASIC') {
|
|
469
407
|
this.credentialManager.storeCredentials({
|
|
470
408
|
id: context.credentials.username,
|
|
471
409
|
name: context.credentials.username,
|
|
@@ -506,9 +444,11 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
506
444
|
},
|
|
507
445
|
guards: {
|
|
508
446
|
isAuthError: ({ event }) => (isErrorEvent(event) ? isAuthError(event.data) : false),
|
|
447
|
+
isUnauthorizedError: ({ event }) => isErrorEvent(event) ? isUnauthorizedError(event.data) : false,
|
|
509
448
|
isAuthenticated: ({ context }) => { var _a; return (_a = context.user) === null || _a === void 0 ? void 0 : _a.isAuthenticated(); },
|
|
510
449
|
isBanned: ({ context }) => { var _a; return (_a = context.user) === null || _a === void 0 ? void 0 : _a.isBanned(); },
|
|
511
450
|
isLoginAckEntity: ({ event }) => isDoneInvokeEvent(event) ? isLoginAckEntity(event.output) : false,
|
|
451
|
+
isLoginDetailsAckEntity: ({ event }) => isDoneInvokeEvent(event) ? isLoginDetailsAckEntity(event.output) : false,
|
|
512
452
|
isLoginNackEntity: ({ event }) => isDoneInvokeEvent(event) ? isLoginNackEntity(event.output) : false,
|
|
513
453
|
isMFARequired: ({ event }) => isDoneInvokeEvent(event)
|
|
514
454
|
? isLoginNackEntity(event.output) && event.output.isMFARequired
|
|
@@ -531,6 +471,32 @@ let DefaultAuthMachine = class DefaultAuthMachine extends AbstractMachine {
|
|
|
531
471
|
getFromContainer() {
|
|
532
472
|
return this.container.get(AuthMachine);
|
|
533
473
|
}
|
|
474
|
+
createFetchMachineEvent(url, msg = {}) {
|
|
475
|
+
const message = Object.assign({ SOURCE_REF: this.uuid.createId() }, msg);
|
|
476
|
+
return {
|
|
477
|
+
type: 'fetch',
|
|
478
|
+
params: {
|
|
479
|
+
url,
|
|
480
|
+
requestInit: {
|
|
481
|
+
method: 'POST',
|
|
482
|
+
body: JSON.stringify(message),
|
|
483
|
+
headers: this.messageBuilder.createHTTPHeadersFromMessage(message),
|
|
484
|
+
credentials: 'include',
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
addLoginEvents() {
|
|
490
|
+
return {
|
|
491
|
+
login: {
|
|
492
|
+
actions: ['resetContext', 'setCredentials'],
|
|
493
|
+
target: '#authMachine.loggingIn',
|
|
494
|
+
},
|
|
495
|
+
['login-details']: {
|
|
496
|
+
target: '#authMachine.loginDetails',
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
}
|
|
534
500
|
};
|
|
535
501
|
DefaultAuthMachine = __decorate([
|
|
536
502
|
__param(0, User),
|
package/dist/esm/main/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter, __decorate } from "tslib";
|
|
2
|
-
import { ConnectConfig, defaultConnectConfig, Session } from '@genesislcap/foundation-comms';
|
|
2
|
+
import { ConnectConfig, CredentialManager, defaultConnectConfig, Session, } from '@genesislcap/foundation-comms';
|
|
3
3
|
import { EventEmitter } from '@genesislcap/foundation-events';
|
|
4
4
|
import { customElement, FASTElement, observable } from '@microsoft/fast-element';
|
|
5
5
|
import { Container, inject, Registration } from '@microsoft/fast-foundation';
|
|
@@ -7,6 +7,7 @@ import { DefaultRouteRecognizer } from '@microsoft/fast-router';
|
|
|
7
7
|
import * as Components from '../components';
|
|
8
8
|
import { MainRouterConfig } from '../routes';
|
|
9
9
|
import { AuthStore } from '../store';
|
|
10
|
+
import { logger } from '../utils';
|
|
10
11
|
import { definition, standaloneDefinition } from './main.definition';
|
|
11
12
|
/**
|
|
12
13
|
* @public
|
|
@@ -32,8 +33,8 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
32
33
|
_super.connectedCallback.call(this);
|
|
33
34
|
this.addEventListeners();
|
|
34
35
|
yield this.registerCommonComponents();
|
|
35
|
-
this.checkForSSOToken();
|
|
36
36
|
this.readyStore();
|
|
37
|
+
this.actionQueryParams();
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -44,7 +45,7 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
44
45
|
this.removeEventListeners();
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
* Used to forward the user onto a logged-in session during an SSO
|
|
48
|
+
* Used to forward the user onto a logged-in session during an SSO and MFA journeys
|
|
48
49
|
*
|
|
49
50
|
* @remarks
|
|
50
51
|
*
|
|
@@ -65,7 +66,7 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
65
66
|
*
|
|
66
67
|
* @internal
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
+
actionQueryParams() {
|
|
69
70
|
const queryParams = new URLSearchParams(window.location.search);
|
|
70
71
|
const ssoToken = queryParams.get('SSO_TOKEN');
|
|
71
72
|
if (ssoToken) {
|
|
@@ -75,9 +76,32 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
75
76
|
window.close();
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
|
-
this.
|
|
79
|
+
const ssoCredentials = this.cm.createSSOCredentials({
|
|
80
|
+
ssoToken,
|
|
81
|
+
});
|
|
82
|
+
if (this.cm.validateSSOCredentials(ssoCredentials)) {
|
|
83
|
+
logger.debug(`Attempting to login with SSO.`);
|
|
84
|
+
this.loginWithCredentials(ssoCredentials);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
}
|
|
89
|
+
const mfaToken = queryParams.get('MFA_CODE');
|
|
90
|
+
if (mfaToken) {
|
|
91
|
+
const mfaCredentials = this.cm.createMFACredentials({
|
|
92
|
+
/**
|
|
93
|
+
* I think `token` is better as it's system gen vs code a user entered
|
|
94
|
+
* TODO: Get server guys to update query param to MFA_TOKEN
|
|
95
|
+
*/
|
|
96
|
+
mfaToken,
|
|
97
|
+
});
|
|
98
|
+
if (this.cm.validateMFACredentials(mfaCredentials)) {
|
|
99
|
+
logger.debug(`Attempting to login with mfa credentials.`);
|
|
100
|
+
this.loginWithCredentials(mfaCredentials);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.loginWithCookies();
|
|
81
105
|
}
|
|
82
106
|
/**
|
|
83
107
|
* Called from the connectedCallback
|
|
@@ -94,7 +118,7 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
94
118
|
*
|
|
95
119
|
* await new Promise(resolve => setTimeout(resolve, 3000));
|
|
96
120
|
*/
|
|
97
|
-
this.ready = true;
|
|
121
|
+
this.ready = true; // < machine not pending?
|
|
98
122
|
});
|
|
99
123
|
}
|
|
100
124
|
/**
|
|
@@ -127,10 +151,22 @@ let Auth = class Auth extends EventEmitter(FASTElement) {
|
|
|
127
151
|
this.$emit('store-connected', this);
|
|
128
152
|
this.$emit('store-ready', true);
|
|
129
153
|
}
|
|
154
|
+
loginWithCredentials(credentials) {
|
|
155
|
+
this.$emit('auth-login', credentials);
|
|
156
|
+
}
|
|
157
|
+
loginWithCookies() {
|
|
158
|
+
this.$emit('auth-login-details');
|
|
159
|
+
}
|
|
160
|
+
logout() {
|
|
161
|
+
this.$emit('auth-logout');
|
|
162
|
+
}
|
|
130
163
|
};
|
|
131
164
|
__decorate([
|
|
132
165
|
AuthStore
|
|
133
166
|
], Auth.prototype, "store", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
CredentialManager
|
|
169
|
+
], Auth.prototype, "cm", void 0);
|
|
134
170
|
__decorate([
|
|
135
171
|
inject(MainRouterConfig)
|
|
136
172
|
], Auth.prototype, "config", void 0);
|
|
@@ -10,6 +10,14 @@ import { fromDTOAck, fromDTONack, fromDTOStringArray, hasDTOErrorWarningCode } f
|
|
|
10
10
|
export function isLoginAckDTO(dto) {
|
|
11
11
|
return (dto === null || dto === void 0 ? void 0 : dto.MESSAGE_TYPE) === 'EVENT_LOGIN_AUTH_ACK';
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* isLoginDetailsAckDTO.
|
|
15
|
+
* @param dto - Potential DTO.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export function isLoginDetailsAckDTO(dto) {
|
|
19
|
+
return (dto === null || dto === void 0 ? void 0 : dto.MESSAGE_TYPE) === 'EVENT_LOGIN_DETAILS_ACK';
|
|
20
|
+
}
|
|
13
21
|
/**
|
|
14
22
|
* isLoginNackDTO.
|
|
15
23
|
* @param dto - Potential DTO.
|
|
@@ -26,6 +34,14 @@ export function isLoginNackDTO(dto) {
|
|
|
26
34
|
export function isLoginAckEntity(entity) {
|
|
27
35
|
return (entity === null || entity === void 0 ? void 0 : entity.messageType) === 'EVENT_LOGIN_AUTH_ACK';
|
|
28
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* isLoginDetailsAckEntity.
|
|
39
|
+
* @param entity - Potential entity.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export function isLoginDetailsAckEntity(entity) {
|
|
43
|
+
return (entity === null || entity === void 0 ? void 0 : entity.messageType) === 'EVENT_LOGIN_DETAILS_ACK';
|
|
44
|
+
}
|
|
29
45
|
/**
|
|
30
46
|
* isLoginNackEntity.
|
|
31
47
|
* @param entity - Potential entity.
|
|
@@ -45,7 +61,7 @@ export class DefaultLoginMapper {
|
|
|
45
61
|
*/
|
|
46
62
|
this.toEntity = (dto) => __awaiter(this, void 0, void 0, function* () {
|
|
47
63
|
try {
|
|
48
|
-
if (isLoginAckDTO(dto)) {
|
|
64
|
+
if (isLoginAckDTO(dto) || isLoginDetailsAckDTO(dto)) {
|
|
49
65
|
const { DETAILS } = dto;
|
|
50
66
|
return Object.assign(Object.assign({}, fromDTOAck(dto)), { sessionAuthToken: dto.SESSION_AUTH_TOKEN, refreshAuthToken: dto.REFRESH_AUTH_TOKEN, sessionId: dto.SESSION_ID, userName: dto.USER_NAME, updateQueue: dto.UPDATE_QUEUE, zeroMqProxyModeEnabled: dto.ZERO_MQ_PROXY_MODE_ENABLED, zeroMqProxyInboundPort: dto.ZERO_MQ_PROXY_INBOUND_PORT, zeroMqProxyOutboundPort: dto.ZERO_MQ_PROXY_OUTBOUND_PORT, userKVs: dto.USER, details: DETAILS
|
|
51
67
|
? {
|
package/dist/esm/routes/base.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __decorate } from "tslib";
|
|
2
2
|
import { Auth, Connect, CredentialManager, MessageBuilder, Session, } from '@genesislcap/foundation-comms';
|
|
3
3
|
import { createInputEmitter, createSelectEmitter, EventEmitter, targetValue, } from '@genesislcap/foundation-events';
|
|
4
|
-
import { sync } from '@genesislcap/foundation-utils';
|
|
5
4
|
import { SecondaryRapidColorHEX } from '@genesislcap/foundation-zero';
|
|
6
5
|
import { attr, css, customElement, FASTElement, html, observable, when, } from '@microsoft/fast-element';
|
|
7
6
|
import { Container } from '@microsoft/fast-foundation';
|
|
@@ -76,6 +75,9 @@ export class BaseRoute extends ConfigHostElement {
|
|
|
76
75
|
// this.email = this.config.fields.email?.value;
|
|
77
76
|
// this.password = this.config.fields.password?.value;
|
|
78
77
|
}
|
|
78
|
+
enter(phase) {
|
|
79
|
+
this.navigationPhase = phase;
|
|
80
|
+
}
|
|
79
81
|
onSubmit() {
|
|
80
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
83
|
this.isSubmitting = true;
|
|
@@ -188,35 +190,6 @@ __decorate([
|
|
|
188
190
|
__decorate([
|
|
189
191
|
observable
|
|
190
192
|
], BaseRoute.prototype, "isSubmitting", void 0);
|
|
191
|
-
/**
|
|
192
|
-
* @internal
|
|
193
|
-
* @privateRemarks
|
|
194
|
-
* Potential optimisation ahead of workflow / statemachine based smart forms integration, but needs tagFor.
|
|
195
|
-
* Feels a bit at odds with the declarative nature we're aiming for, but will await review.
|
|
196
|
-
*/
|
|
197
|
-
export const configurableTextField = (name, type, autofocus = false, autocomplete = '', className = '', labelOverride = '', testIdOverride = '', required = true) => {
|
|
198
|
-
// Just pass the FieldConfig instead of name?
|
|
199
|
-
const [fieldName, valueKey] = Array.isArray(name) ? name : [name, name];
|
|
200
|
-
return html `
|
|
201
|
-
${when((x) => x.config.fields[fieldName], html `
|
|
202
|
-
<zero-text-field
|
|
203
|
-
type="${type}"
|
|
204
|
-
name="${fieldName}"
|
|
205
|
-
id="${fieldName}"
|
|
206
|
-
:value="${sync((x) => x[valueKey])}"
|
|
207
|
-
?autofocus="${() => autofocus}"
|
|
208
|
-
?required="${() => required}"
|
|
209
|
-
${autocomplete ? `autocomplete="${autocomplete}"` : ''}
|
|
210
|
-
data-test-id="${testIdOverride !== null && testIdOverride !== void 0 ? testIdOverride : fieldName}"
|
|
211
|
-
class="${className}"
|
|
212
|
-
>
|
|
213
|
-
<span class="form-title">
|
|
214
|
-
${(x) => labelOverride !== null && labelOverride !== void 0 ? labelOverride : x.config.fields[fieldName].label}
|
|
215
|
-
</span>
|
|
216
|
-
</zero-text-field>
|
|
217
|
-
`)}
|
|
218
|
-
`;
|
|
219
|
-
};
|
|
220
193
|
/**
|
|
221
194
|
* @internal
|
|
222
195
|
*/
|
|
@@ -128,8 +128,6 @@ let MainRouterConfig = class MainRouterConfig extends RouterConfiguration {
|
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* If allowAutoAuth and session is valid try to connect+auto-login
|
|
131
|
-
*
|
|
132
|
-
* todo send login refresh? should we do that from the login route?
|
|
133
131
|
*/
|
|
134
132
|
// if (this.authConfig.autoAuth && (await auth.reAuthFromSession())) {
|
|
135
133
|
// return;
|