@node-c/domain-iam 1.0.0-beta0 → 1.0.0-beta2
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/common/definitions/common.constants.d.ts +2 -1
- package/dist/common/definitions/common.constants.js +2 -1
- package/dist/common/definitions/common.constants.js.map +1 -1
- package/dist/services/authentication/iam.authentication.service.d.ts +3 -2
- package/dist/services/authentication/iam.authentication.service.js +2 -1
- package/dist/services/authentication/iam.authentication.service.js.map +1 -1
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.d.ts +3 -2
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.js +14 -13
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.js.map +1 -1
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.d.ts +3 -2
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.js +11 -10
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.js.map +1 -1
- package/dist/services/authorization/iam.authorization.service.d.ts +3 -2
- package/dist/services/authorization/iam.authorization.service.js +13 -11
- package/dist/services/authorization/iam.authorization.service.js.map +1 -1
- package/dist/services/mfa/iam.mfa.service.d.ts +3 -2
- package/dist/services/mfa/iam.mfa.service.js +2 -1
- package/dist/services/mfa/iam.mfa.service.js.map +1 -1
- package/dist/services/tokenManager/iam.tokenManager.service.d.ts +3 -2
- package/dist/services/tokenManager/iam.tokenManager.service.js +7 -6
- package/dist/services/tokenManager/iam.tokenManager.service.js.map +1 -1
- package/dist/services/userManager/iam.userManager.service.d.ts +3 -2
- package/dist/services/userManager/iam.userManager.service.js +13 -12
- package/dist/services/userManager/iam.userManager.service.js.map +1 -1
- package/package.json +3 -2
- package/src/common/definitions/common.constants.ts +3 -1
- package/src/services/authentication/iam.authentication.service.ts +3 -1
- package/src/services/authenticationOAuth2/iam.authenticationOAuth2.definitions.ts +3 -2
- package/src/services/authenticationOAuth2/iam.authenticationOAuth2.service.ts +14 -12
- package/src/services/authenticationUserLocal/iam.authenticationUserLocal.service.ts +12 -10
- package/src/services/authorization/iam.authorization.service.ts +13 -10
- package/src/services/mfa/iam.mfa.service.ts +3 -1
- package/src/services/tokenManager/iam.tokenManager.service.ts +8 -6
- package/src/services/userManager/iam.userManager.service.ts +14 -12
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
DomainCreateResult,
|
|
8
8
|
DomainEntityService,
|
|
9
9
|
GenericObject,
|
|
10
|
+
LoggerService,
|
|
10
11
|
setNested
|
|
11
12
|
} from '@node-c/core';
|
|
12
13
|
|
|
@@ -29,7 +30,6 @@ import { IAMAuthenticationService, IAMAuthenticationType } from '../authenticati
|
|
|
29
30
|
import { IAMAuthenticationOAuth2Service } from '../authenticationOAuth2';
|
|
30
31
|
import { IAMAuthenticationUserLocalService } from '../authenticationUserLocal';
|
|
31
32
|
|
|
32
|
-
// TODO: console.error -> logger
|
|
33
33
|
/*
|
|
34
34
|
* Service for managing local access and refresh JWTs.
|
|
35
35
|
*/
|
|
@@ -50,6 +50,8 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
50
50
|
DataEntityService<TokenEntity<TokenEntityFields>>
|
|
51
51
|
>,
|
|
52
52
|
// eslint-disable-next-line no-unused-vars
|
|
53
|
+
protected logger: LoggerService,
|
|
54
|
+
// eslint-disable-next-line no-unused-vars
|
|
53
55
|
protected moduleName: string
|
|
54
56
|
) {}
|
|
55
57
|
|
|
@@ -57,7 +59,7 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
57
59
|
data: TokenManagerCreateData<TokenEntityFields>,
|
|
58
60
|
options: TokenManagerCreateOptions
|
|
59
61
|
): Promise<DomainCreateResult<TokenEntity<TokenEntityFields>>> {
|
|
60
|
-
const { configProvider, moduleName, domainTokensEntityService } = this;
|
|
62
|
+
const { configProvider, logger, moduleName, domainTokensEntityService } = this;
|
|
61
63
|
const moduleConfig = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
62
64
|
const { type, ...tokenData } = data;
|
|
63
65
|
const { expiresInMinutes, identifierDataField, persist, purgeOldFromData, tokenContentOnlyFields } = options;
|
|
@@ -84,7 +86,7 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
84
86
|
const token = await new Promise<string>((resolve, reject) => {
|
|
85
87
|
jwt.sign({ data }, secret, signOptions, (err, token) => {
|
|
86
88
|
if (err) {
|
|
87
|
-
|
|
89
|
+
logger.error(err);
|
|
88
90
|
reject(new ApplicationError('Failed to sign token.'));
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
@@ -121,7 +123,7 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
121
123
|
token: string,
|
|
122
124
|
options?: VerifyAccessTokenOptions
|
|
123
125
|
): Promise<VerifyAccessTokenReturnData<TokenEntityFields>> {
|
|
124
|
-
const { configProvider,
|
|
126
|
+
const { configProvider, domainTokensEntityService, logger, moduleName } = this;
|
|
125
127
|
const moduleConfig = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
126
128
|
const {
|
|
127
129
|
deleteFromStoreIfExpired,
|
|
@@ -217,7 +219,7 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
217
219
|
throwError = false;
|
|
218
220
|
}
|
|
219
221
|
if (throwError) {
|
|
220
|
-
|
|
222
|
+
logger.error(errorMessageToLog);
|
|
221
223
|
throw new ApplicationError('Expired access token.');
|
|
222
224
|
}
|
|
223
225
|
// renewal
|
|
@@ -235,7 +237,7 @@ export class IAMTokenManagerService<TokenEntityFields extends object> {
|
|
|
235
237
|
});
|
|
236
238
|
if (externalAccessTokenRenewalResult.error) {
|
|
237
239
|
// TODO: delete from store
|
|
238
|
-
|
|
240
|
+
logger.error(errorMessageToLog);
|
|
239
241
|
throw new ApplicationError('Expired access token.');
|
|
240
242
|
}
|
|
241
243
|
// TODO: save the new refresh token, if such exists
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
DomainEntityService,
|
|
10
10
|
DomainEntityServiceDefaultData,
|
|
11
11
|
GenericObject,
|
|
12
|
+
LoggerService,
|
|
12
13
|
getNested,
|
|
13
14
|
setNested
|
|
14
15
|
} from '@node-c/core';
|
|
@@ -44,7 +45,6 @@ import { IAMTokenManagerService, TokenType } from '../tokenManager';
|
|
|
44
45
|
// TODO: create user (signup); this should include password hashing
|
|
45
46
|
// TODO: update password (incl. hashing)
|
|
46
47
|
// TODO: reset password
|
|
47
|
-
// TODO: console.info -> logger
|
|
48
48
|
// TODO: periodic checking of external access tokens and their revoking
|
|
49
49
|
export class IAMUserManagerService<
|
|
50
50
|
User extends object,
|
|
@@ -69,6 +69,8 @@ export class IAMUserManagerService<
|
|
|
69
69
|
Record<string, DataEntityService<Partial<User>, DataDefaultData<object>>> | undefined
|
|
70
70
|
>,
|
|
71
71
|
// eslint-disable-next-line no-unused-vars
|
|
72
|
+
protected logger: LoggerService,
|
|
73
|
+
// eslint-disable-next-line no-unused-vars
|
|
72
74
|
protected moduleName: string,
|
|
73
75
|
// eslint-disable-next-line no-unused-vars
|
|
74
76
|
protected tokenManager: IAMTokenManagerService<IAMUserManagerUserTokenEnityFields>
|
|
@@ -79,7 +81,7 @@ export class IAMUserManagerService<
|
|
|
79
81
|
async createAccessToken<AuthData = unknown>(
|
|
80
82
|
options: IAMUserManagerCreateAccessTokenOptions<AuthData>
|
|
81
83
|
): Promise<IAMUserManagerCreateAccessTokenReturnData<User>> {
|
|
82
|
-
const { configProvider, moduleName } = this;
|
|
84
|
+
const { configProvider, logger, moduleName } = this;
|
|
83
85
|
const moduleConfig = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
84
86
|
const { accessTokenExpiryTimeInMinutes, defaultUserIdentifierField, refreshTokenExpiryTimeInMinutes } =
|
|
85
87
|
moduleConfig;
|
|
@@ -87,13 +89,13 @@ export class IAMUserManagerService<
|
|
|
87
89
|
auth: { type: authType },
|
|
88
90
|
rememberUser
|
|
89
91
|
} = options;
|
|
90
|
-
|
|
92
|
+
logger.info(
|
|
91
93
|
`[Domain.${moduleName}.UserManager]: Login attempt started${options.step ? ` for step ${options.step}` : ''}.`
|
|
92
94
|
);
|
|
93
95
|
// 1. Make sure the auth service actually exists - local, oauth2, etc.
|
|
94
96
|
const authService = this.authServices[authType] as IAMAuthenticationService<object, object>;
|
|
95
97
|
if (!authService) {
|
|
96
|
-
|
|
98
|
+
logger.info(`[Domain.${moduleName}.UserManager]: No authService ${authType} found.`);
|
|
97
99
|
throw new ApplicationError('Authentication failed.');
|
|
98
100
|
}
|
|
99
101
|
// 2. Get the user-specific configuration from the authService.
|
|
@@ -150,7 +152,7 @@ export class IAMUserManagerService<
|
|
|
150
152
|
if ('useReturnedTokens' in stepConfig && stepConfig.useReturnedTokens && stepConfig.authReturnsTokens) {
|
|
151
153
|
// Make sure we have an accessToken in the response and set the access and refresh tokens in variables for later use.
|
|
152
154
|
if (!actualStepResult.accessToken) {
|
|
153
|
-
|
|
155
|
+
logger.info(
|
|
154
156
|
`[Domain.${moduleName}.UserManager]: Login attempt failed for ${userFilterField} ${userFilterValue} - no accessToken returned from the authService and useReturnedTokens is set to true.`
|
|
155
157
|
);
|
|
156
158
|
throw new ApplicationError('Authentication failed.');
|
|
@@ -163,7 +165,7 @@ export class IAMUserManagerService<
|
|
|
163
165
|
// 6. Token management. In this case, we will definitely have the user, or will be force to create it.
|
|
164
166
|
if (issueTokens) {
|
|
165
167
|
if (!user) {
|
|
166
|
-
|
|
168
|
+
logger.info(
|
|
167
169
|
`[Domain.${moduleName}.UserManager]: Login attempt failed at step ${step} - user is required when issueTokens is set to true.`
|
|
168
170
|
);
|
|
169
171
|
throw new ApplicationError('Authentication failed.');
|
|
@@ -227,7 +229,7 @@ export class IAMUserManagerService<
|
|
|
227
229
|
tokenContentOnlyFields: ['externalToken', 'refreshToken', 'user']
|
|
228
230
|
}
|
|
229
231
|
);
|
|
230
|
-
|
|
232
|
+
logger.info(
|
|
231
233
|
`[Domain.${moduleName}.UserManager]: Login attempt successful for ${userFilterField} ${userFilterValue}.`
|
|
232
234
|
);
|
|
233
235
|
return { accessToken, refreshToken, user };
|
|
@@ -249,7 +251,7 @@ export class IAMUserManagerService<
|
|
|
249
251
|
data: IAMUserManagerExecuteStepData<AuthData>,
|
|
250
252
|
options: IAMUserManagerExecuteStepOptions<User>
|
|
251
253
|
): Promise<IAMUserManagerExecuteStepResult<User>> {
|
|
252
|
-
const { configProvider, domainUsersEntityService, moduleName } = this;
|
|
254
|
+
const { configProvider, domainUsersEntityService, logger, moduleName } = this;
|
|
253
255
|
const { defaultUserIdentifierField } = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
254
256
|
const {
|
|
255
257
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
@@ -267,14 +269,14 @@ export class IAMUserManagerService<
|
|
|
267
269
|
// 1. Find the user based on the provided filters, if enabled.
|
|
268
270
|
if (findUser && findUserBeforeAuth) {
|
|
269
271
|
if (!hasFilters) {
|
|
270
|
-
|
|
272
|
+
logger.info(`[Domain.${moduleName}.UserManager]: No filters provided for findUserBeforeToken=true.`);
|
|
271
273
|
throw new ApplicationError('Authentication failed.');
|
|
272
274
|
}
|
|
273
275
|
userFilterField = mainFilterField;
|
|
274
276
|
userFilterValue = userFilters[userFilterField];
|
|
275
277
|
user = await this.getUserForStepExecution({ filters: userFilters, mainFilterField: userFilterField });
|
|
276
278
|
if (!user) {
|
|
277
|
-
|
|
279
|
+
logger.info(
|
|
278
280
|
`[Domain.${moduleName}.UserManager]: Login attempt failed for ${userFilterField} ${userFilterValue} - user not found.`
|
|
279
281
|
);
|
|
280
282
|
throw new ApplicationError('Authentication failed.');
|
|
@@ -320,7 +322,7 @@ export class IAMUserManagerService<
|
|
|
320
322
|
);
|
|
321
323
|
// 4. Process the step result
|
|
322
324
|
if (!stepResult.valid || (stepResult.mfaUsed && !stepResult.mfaValid)) {
|
|
323
|
-
|
|
325
|
+
logger.info(`[Domain.${moduleName}.UserManager]: Bad step result:`, stepResult);
|
|
324
326
|
throw new ApplicationError('Authentication failed.');
|
|
325
327
|
}
|
|
326
328
|
// 5. If the step returns tokens and decoding is enabled, decode the reutrned tokens for payloads
|
|
@@ -381,7 +383,7 @@ export class IAMUserManagerService<
|
|
|
381
383
|
}
|
|
382
384
|
}
|
|
383
385
|
if (validWithoutUser !== true && !user) {
|
|
384
|
-
|
|
386
|
+
logger.info(
|
|
385
387
|
`[Domain.${moduleName}.UserManager]: Login attempt failed ${userFilterField && userFilterValue ? `for ${userFilterField} ${userFilterValue} ` : ''}- user not found.`
|
|
386
388
|
);
|
|
387
389
|
throw new ApplicationError('Authentication failed.');
|