@node-c/domain-iam 1.0.0-beta6 → 1.0.0-beta8
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 +13 -9
- package/dist/common/definitions/common.constants.js +13 -10
- package/dist/common/definitions/common.constants.js.map +1 -1
- package/dist/services/authentication/iam.authentication.definitions.d.ts +11 -2
- package/dist/services/authentication/iam.authentication.definitions.js +1 -1
- package/dist/services/authentication/iam.authentication.service.d.ts +9 -4
- package/dist/services/authentication/iam.authentication.service.js +95 -4
- package/dist/services/authentication/iam.authentication.service.js.map +1 -1
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.definitions.d.ts +15 -0
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.definitions.js +3 -0
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.definitions.js.map +1 -0
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.service.d.ts +12 -0
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.service.js +135 -0
- package/dist/services/authenticationConsumer/iam.authenticationConsumer.service.js.map +1 -0
- package/dist/services/authenticationConsumer/index.d.ts +2 -0
- package/dist/services/authenticationConsumer/index.js +19 -0
- package/dist/services/authenticationConsumer/index.js.map +1 -0
- package/dist/services/{userManager/iam.userManager.definitions.d.ts → authenticationManager/iam.authenticationManager.definitions.d.ts} +11 -15
- package/dist/services/authenticationManager/iam.authenticationManager.definitions.js +8 -0
- package/dist/services/authenticationManager/iam.authenticationManager.definitions.js.map +1 -0
- package/dist/services/authenticationManager/iam.authenticationManager.service.d.ts +33 -0
- package/dist/services/{userManager/iam.userManager.service.js → authenticationManager/iam.authenticationManager.service.js} +140 -72
- package/dist/services/authenticationManager/iam.authenticationManager.service.js.map +1 -0
- package/dist/services/authenticationManager/index.d.ts +2 -0
- package/dist/services/authenticationManager/index.js +19 -0
- package/dist/services/authenticationManager/index.js.map +1 -0
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.definitions.d.ts +5 -2
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.d.ts +2 -14
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.js +53 -95
- package/dist/services/authenticationOAuth2/iam.authenticationOAuth2.service.js.map +1 -1
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.definitions.d.ts +19 -0
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.definitions.js +3 -0
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.definitions.js.map +1 -0
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.service.d.ts +11 -0
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.service.js +69 -0
- package/dist/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.service.js.map +1 -0
- package/dist/services/authenticationOAuth2Consumer/index.d.ts +2 -0
- package/dist/services/authenticationOAuth2Consumer/index.js +19 -0
- package/dist/services/authenticationOAuth2Consumer/index.js.map +1 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.definitions.d.ts +14 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.definitions.js +3 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.definitions.js.map +1 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.service.d.ts +9 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.service.js +70 -0
- package/dist/services/authenticationPassthrough/iam.authenticationPassthrough.service.js.map +1 -0
- package/dist/services/authenticationPassthrough/index.d.ts +2 -0
- package/dist/services/authenticationPassthrough/index.js +19 -0
- package/dist/services/authenticationPassthrough/index.js.map +1 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.definitions.d.ts +18 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.definitions.js +3 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.definitions.js.map +1 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.service.d.ts +10 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.service.js +68 -0
- package/dist/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.service.js.map +1 -0
- package/dist/services/authenticationPassthroughConsumer/index.d.ts +2 -0
- package/dist/services/authenticationPassthroughConsumer/index.js +19 -0
- package/dist/services/authenticationPassthroughConsumer/index.js.map +1 -0
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.definitions.d.ts +2 -2
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.d.ts +2 -6
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.js +4 -8
- package/dist/services/authenticationUserLocal/iam.authenticationUserLocal.service.js.map +1 -1
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.definitions.d.ts +8 -0
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.definitions.js +3 -0
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.definitions.js.map +1 -0
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.service.d.ts +8 -0
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.service.js +36 -0
- package/dist/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.service.js.map +1 -0
- package/dist/services/authenticationUserLocalConsumer/index.d.ts +2 -0
- package/dist/services/authenticationUserLocalConsumer/index.js +19 -0
- package/dist/services/authenticationUserLocalConsumer/index.js.map +1 -0
- package/dist/services/authorization/iam.authorization.definitions.d.ts +24 -24
- package/dist/services/authorization/iam.authorization.definitions.js +7 -7
- package/dist/services/authorization/iam.authorization.definitions.js.map +1 -1
- package/dist/services/authorization/iam.authorization.service.d.ts +8 -11
- package/dist/services/authorization/iam.authorization.service.js +26 -30
- package/dist/services/authorization/iam.authorization.service.js.map +1 -1
- package/dist/services/index.d.ts +7 -1
- package/dist/services/index.js +7 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/tokenManager/iam.tokenManager.definitions.d.ts +4 -1
- package/dist/services/tokenManager/iam.tokenManager.definitions.js.map +1 -1
- package/dist/services/tokenManager/iam.tokenManager.service.d.ts +2 -2
- package/dist/services/tokenManager/iam.tokenManager.service.js +73 -35
- package/dist/services/tokenManager/iam.tokenManager.service.js.map +1 -1
- package/dist/services/users/index.d.ts +2 -0
- package/dist/services/{userManager → users}/index.js +2 -2
- package/dist/services/users/index.js.map +1 -0
- package/dist/services/users/users.definitions.d.ts +7 -0
- package/dist/services/users/users.definitions.js +3 -0
- package/dist/services/users/users.definitions.js.map +1 -0
- package/dist/services/users/users.service.d.ts +6 -0
- package/dist/services/users/users.service.js +39 -0
- package/dist/services/users/users.service.js.map +1 -0
- package/package.json +2 -2
- package/src/common/definitions/common.constants.ts +13 -16
- package/src/services/authentication/iam.authentication.definitions.ts +11 -4
- package/src/services/authentication/iam.authentication.service.ts +79 -15
- package/src/services/authenticationConsumer/iam.authenticationConsumer.definitions.ts +43 -0
- package/src/services/authenticationConsumer/iam.authenticationConsumer.service.ts +192 -0
- package/src/services/authenticationConsumer/index.ts +2 -0
- package/src/services/{userManager/iam.userManager.definitions.ts → authenticationManager/iam.authenticationManager.definitions.ts} +11 -19
- package/src/services/{userManager/iam.userManager.service.ts → authenticationManager/iam.authenticationManager.service.ts} +174 -111
- package/src/services/authenticationManager/index.ts +2 -0
- package/src/services/authenticationOAuth2/iam.authenticationOAuth2.definitions.ts +6 -3
- package/src/services/authenticationOAuth2/iam.authenticationOAuth2.service.ts +97 -85
- package/src/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.definitions.ts +56 -0
- package/src/services/authenticationOAuth2Consumer/iam.authenticationOAuth2Consumer.service.ts +93 -0
- package/src/services/authenticationOAuth2Consumer/index.ts +2 -0
- package/src/services/authenticationPassthrough/iam.authenticationPassthrough.definitions.ts +32 -0
- package/src/services/authenticationPassthrough/iam.authenticationPassthrough.service.ts +100 -0
- package/src/services/authenticationPassthrough/index.ts +2 -0
- package/src/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.definitions.ts +52 -0
- package/src/services/authenticationPassthroughConsumer/iam.authenticationPassthroughConsumer.service.ts +96 -0
- package/src/services/authenticationPassthroughConsumer/index.ts +2 -0
- package/src/services/authenticationUserLocal/iam.authenticationUserLocal.definitions.ts +3 -3
- package/src/services/authenticationUserLocal/iam.authenticationUserLocal.service.ts +17 -12
- package/src/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.definitions.ts +29 -0
- package/src/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.service.ts +40 -0
- package/src/services/authenticationUserLocalConsumer/index.ts +2 -0
- package/src/services/authorization/iam.authorization.definitions.ts +26 -27
- package/src/services/authorization/iam.authorization.service.ts +40 -65
- package/src/services/index.ts +7 -1
- package/src/services/tokenManager/iam.tokenManager.definitions.ts +4 -1
- package/src/services/tokenManager/iam.tokenManager.service.ts +98 -45
- package/src/services/users/index.ts +2 -0
- package/src/services/users/users.definitions.ts +11 -0
- package/src/services/users/users.service.ts +46 -0
- package/dist/services/userManager/iam.userManager.definitions.js +0 -8
- package/dist/services/userManager/iam.userManager.definitions.js.map +0 -1
- package/dist/services/userManager/iam.userManager.service.d.ts +0 -33
- package/dist/services/userManager/iam.userManager.service.js.map +0 -1
- package/dist/services/userManager/index.d.ts +0 -2
- package/dist/services/userManager/index.js.map +0 -1
- package/src/services/userManager/index.ts +0 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppConfigDomainIAM,
|
|
3
|
+
AppConfigDomainIAMAuthenticationStep,
|
|
4
|
+
ApplicationError,
|
|
5
|
+
ConfigProviderService,
|
|
6
|
+
LoggerService
|
|
7
|
+
} from '@node-c/core';
|
|
8
|
+
|
|
9
|
+
import ld from 'lodash';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
IAMAuthenticationPassthroughConsumerCompleteData,
|
|
13
|
+
IAMAuthenticationPassthroughConsumerCompleteOptions,
|
|
14
|
+
IAMAuthenticationPassthroughConsumerCompleteResult,
|
|
15
|
+
IAMAuthenticationPassthroughConsumerGetUserAuthenticationConfigResult,
|
|
16
|
+
IAMAuthenticationPassthroughConsumerInitiateData,
|
|
17
|
+
IAMAuthenticationPassthroughConsumerInitiateOptions,
|
|
18
|
+
IAMAuthenticationPassthroughConsumerInitiateResult,
|
|
19
|
+
IAMAuthenticationPassthroughConsumerRefreshExternalAccessTokenData,
|
|
20
|
+
IAMAuthenticationPassthroughConsumerRefreshExternalAccessTokenResult
|
|
21
|
+
} from './iam.authenticationPassthroughConsumer.definitions';
|
|
22
|
+
|
|
23
|
+
import { IAMAuthenticationConsumerService } from '../authenticationConsumer';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A service for integrating Passthrough authentication via other Node-C Apps as a consumer.
|
|
27
|
+
*
|
|
28
|
+
* This service is intended for use by the consumer environment.
|
|
29
|
+
*/
|
|
30
|
+
export class IAMAuthenticationPassthroughConsumerService<
|
|
31
|
+
CompleteContext extends object,
|
|
32
|
+
InitiateContext extends object
|
|
33
|
+
> extends IAMAuthenticationConsumerService<CompleteContext, InitiateContext> {
|
|
34
|
+
constructor(configProvider: ConfigProviderService, logger: LoggerService, moduleName: string, serviceName: string) {
|
|
35
|
+
super(configProvider, logger, moduleName, serviceName);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async complete(
|
|
39
|
+
data: IAMAuthenticationPassthroughConsumerCompleteData,
|
|
40
|
+
options: IAMAuthenticationPassthroughConsumerCompleteOptions<CompleteContext>
|
|
41
|
+
): Promise<IAMAuthenticationPassthroughConsumerCompleteResult> {
|
|
42
|
+
return super.complete(data, options) as Promise<IAMAuthenticationPassthroughConsumerCompleteResult>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* This config is intended for use by the consumer environment.
|
|
47
|
+
*
|
|
48
|
+
* User data from: provider
|
|
49
|
+
*
|
|
50
|
+
* Internal tokens from: provider
|
|
51
|
+
*
|
|
52
|
+
* External tokens from: consumer (optional)
|
|
53
|
+
*
|
|
54
|
+
* Authentication happens in: consumer
|
|
55
|
+
*/
|
|
56
|
+
getUserAuthenticationConfig(): IAMAuthenticationPassthroughConsumerGetUserAuthenticationConfigResult {
|
|
57
|
+
const { configProvider, moduleName, serviceName } = this;
|
|
58
|
+
const moduleConfig = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
59
|
+
const { steps } = moduleConfig.authServiceSettings![serviceName];
|
|
60
|
+
const defaultConfig: IAMAuthenticationPassthroughConsumerGetUserAuthenticationConfigResult = {
|
|
61
|
+
[AppConfigDomainIAMAuthenticationStep.Complete]: {
|
|
62
|
+
authReturnsTokens: true,
|
|
63
|
+
decodeReturnedTokens: true,
|
|
64
|
+
findUser: true,
|
|
65
|
+
findUserBeforeAuth: false,
|
|
66
|
+
findUserInExternalTokenPayloads: true,
|
|
67
|
+
useReturnedTokens: true,
|
|
68
|
+
useReturnedTokensAsLocal: false,
|
|
69
|
+
validWithoutUser: false
|
|
70
|
+
},
|
|
71
|
+
// this step simply does nothing
|
|
72
|
+
[AppConfigDomainIAMAuthenticationStep.Initiate]: {
|
|
73
|
+
findUser: false,
|
|
74
|
+
validWithoutUser: true
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return ld.merge(defaultConfig, steps || {});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async initiate(
|
|
81
|
+
data: IAMAuthenticationPassthroughConsumerInitiateData,
|
|
82
|
+
options: IAMAuthenticationPassthroughConsumerInitiateOptions<InitiateContext>
|
|
83
|
+
): Promise<IAMAuthenticationPassthroughConsumerInitiateResult> {
|
|
84
|
+
return super.initiate(data, options) as Promise<IAMAuthenticationPassthroughConsumerInitiateResult>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// This method must be implemented in the child class, since the external access tokens come from the consumer.
|
|
88
|
+
async refreshExternalAccessToken(
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
+
_data: IAMAuthenticationPassthroughConsumerRefreshExternalAccessTokenData
|
|
91
|
+
): Promise<IAMAuthenticationPassthroughConsumerRefreshExternalAccessTokenResult> {
|
|
92
|
+
throw new ApplicationError(
|
|
93
|
+
`[${this.moduleName}][${this.serviceName}}]: Method "refreshExternalAccessToken" not implemented.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
IAMAuthenticationCompleteData,
|
|
3
3
|
IAMAuthenticationCompleteOptions,
|
|
4
4
|
IAMAuthenticationCompleteResult,
|
|
5
|
-
|
|
5
|
+
IAMAuthenticationGetUserAuthenticationConfigResult,
|
|
6
6
|
IAMAuthenticationInitiateData,
|
|
7
7
|
IAMAuthenticationInitiateOptions,
|
|
8
8
|
IAMAuthenticationInitiateResult
|
|
@@ -15,8 +15,8 @@ export type IAMAuthenticationUserLocalCompleteOptions<Context extends object> =
|
|
|
15
15
|
|
|
16
16
|
export type IAMAuthenticationUserLocalCompleteResult = IAMAuthenticationCompleteResult;
|
|
17
17
|
|
|
18
|
-
export type
|
|
19
|
-
|
|
18
|
+
export type IAMAuthenticationUserLocalGetUserAuthenticationConfigResult =
|
|
19
|
+
IAMAuthenticationGetUserAuthenticationConfigResult;
|
|
20
20
|
|
|
21
21
|
export interface IAMAuthenticationUserLocalInitiateData extends IAMAuthenticationInitiateData {
|
|
22
22
|
password: string;
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
IAMAuthenticationUserLocalCompleteData,
|
|
15
15
|
IAMAuthenticationUserLocalCompleteOptions,
|
|
16
16
|
IAMAuthenticationUserLocalCompleteResult,
|
|
17
|
-
|
|
17
|
+
IAMAuthenticationUserLocalGetUserAuthenticationConfigResult,
|
|
18
18
|
IAMAuthenticationUserLocalInitiateData,
|
|
19
19
|
IAMAuthenticationUserLocalInitiateOptions,
|
|
20
20
|
IAMAuthenticationUserLocalInitiateResult
|
|
@@ -23,21 +23,24 @@ import {
|
|
|
23
23
|
import { IAMAuthenticationService } from '../authentication';
|
|
24
24
|
import { IAMMFAService, IAMMFAType } from '../mfa';
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A service for authentication using a local user and password.
|
|
28
|
+
*
|
|
29
|
+
* This service is intended for use by the consumer environment.
|
|
30
|
+
*/
|
|
27
31
|
export class IAMAuthenticationUserLocalService<
|
|
28
32
|
CompleteContext extends object,
|
|
29
33
|
InitiateContext extends object
|
|
30
34
|
> extends IAMAuthenticationService<CompleteContext, InitiateContext> {
|
|
31
35
|
constructor(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
protected serviceName: string,
|
|
36
|
+
configProvider: ConfigProviderService,
|
|
37
|
+
logger: LoggerService,
|
|
38
|
+
moduleName: string,
|
|
39
|
+
serviceName: string,
|
|
37
40
|
// eslint-disable-next-line no-unused-vars
|
|
38
41
|
protected mfaServices?: Record<IAMMFAType, IAMMFAService<object, object>>
|
|
39
42
|
) {
|
|
40
|
-
super(configProvider, logger, moduleName);
|
|
43
|
+
super(configProvider, logger, moduleName, serviceName);
|
|
41
44
|
this.isLocal = true;
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -74,15 +77,16 @@ export class IAMAuthenticationUserLocalService<
|
|
|
74
77
|
return { mfaUsed, mfaValid, valid: true };
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
getUserAuthenticationConfig(): IAMAuthenticationUserLocalGetUserAuthenticationConfigResult {
|
|
78
81
|
const { configProvider, moduleName, serviceName } = this;
|
|
79
82
|
const moduleConfig = configProvider.config.domain[moduleName] as AppConfigDomainIAM;
|
|
80
83
|
const { steps } = moduleConfig.authServiceSettings![serviceName];
|
|
81
|
-
const defaultConfig:
|
|
84
|
+
const defaultConfig: IAMAuthenticationUserLocalGetUserAuthenticationConfigResult = {
|
|
82
85
|
[AppConfigDomainIAMAuthenticationStep.Complete]: {
|
|
83
86
|
cache: {
|
|
84
87
|
settings: {
|
|
85
|
-
|
|
88
|
+
// we call the user's id "state" here, since "state" is also used as the cache key for the oauth2 flow
|
|
89
|
+
cacheFieldName: 'state',
|
|
86
90
|
inputFieldName: 'options.context.id'
|
|
87
91
|
},
|
|
88
92
|
use: {
|
|
@@ -99,7 +103,8 @@ export class IAMAuthenticationUserLocalService<
|
|
|
99
103
|
options: [{ cacheFieldName: 'context', inputFieldName: 'options.context' }]
|
|
100
104
|
},
|
|
101
105
|
settings: {
|
|
102
|
-
|
|
106
|
+
// we call the user's id "state" here, since "state" is also used as the cache key for the oauth2 flow
|
|
107
|
+
cacheFieldName: 'state',
|
|
103
108
|
inputFieldName: 'options.context.id'
|
|
104
109
|
}
|
|
105
110
|
},
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAMAuthenticationConsumerCompleteResult,
|
|
3
|
+
IAMAuthenticationConsumerInitiateResult
|
|
4
|
+
} from '../authenticationConsumer';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
IAMAuthenticationUserLocalCompleteData,
|
|
8
|
+
IAMAuthenticationUserLocalCompleteOptions,
|
|
9
|
+
IAMAuthenticationUserLocalCompleteResult,
|
|
10
|
+
IAMAuthenticationUserLocalInitiateData,
|
|
11
|
+
IAMAuthenticationUserLocalInitiateOptions,
|
|
12
|
+
IAMAuthenticationUserLocalInitiateResult
|
|
13
|
+
} from '../authenticationUserLocal';
|
|
14
|
+
|
|
15
|
+
export type IAMAuthenticationUserLocalConsumerCompleteData = IAMAuthenticationUserLocalCompleteData;
|
|
16
|
+
|
|
17
|
+
export type IAMAuthenticationUserLocalConsumerCompleteOptions<Context extends object> =
|
|
18
|
+
IAMAuthenticationUserLocalCompleteOptions<Context>;
|
|
19
|
+
|
|
20
|
+
export type IAMAuthenticationUserLocalConsumerCompleteResult = IAMAuthenticationUserLocalCompleteResult &
|
|
21
|
+
IAMAuthenticationConsumerCompleteResult;
|
|
22
|
+
|
|
23
|
+
export type IAMAuthenticationUserLocalConsumerInitiateData = IAMAuthenticationUserLocalInitiateData;
|
|
24
|
+
|
|
25
|
+
export type IAMAuthenticationUserLocalConsumerInitiateOptions<Context extends object> =
|
|
26
|
+
IAMAuthenticationUserLocalInitiateOptions<Context>;
|
|
27
|
+
|
|
28
|
+
export type IAMAuthenticationUserLocalConsumerInitiateResult = IAMAuthenticationUserLocalInitiateResult &
|
|
29
|
+
IAMAuthenticationConsumerInitiateResult;
|
package/src/services/authenticationUserLocalConsumer/iam.authenticationUserLocalConsumer.service.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ConfigProviderService, LoggerService } from '@node-c/core';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
IAMAuthenticationUserLocalConsumerCompleteData,
|
|
5
|
+
IAMAuthenticationUserLocalConsumerCompleteOptions,
|
|
6
|
+
IAMAuthenticationUserLocalConsumerCompleteResult,
|
|
7
|
+
IAMAuthenticationUserLocalConsumerInitiateData,
|
|
8
|
+
IAMAuthenticationUserLocalConsumerInitiateOptions,
|
|
9
|
+
IAMAuthenticationUserLocalConsumerInitiateResult
|
|
10
|
+
} from './iam.authenticationUserLocalConsumer.definitions';
|
|
11
|
+
|
|
12
|
+
import { IAMAuthenticationConsumerService } from '../authenticationConsumer';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A service for integrating UserLocal authentication via other Node-C Apps as a consumer.
|
|
16
|
+
*
|
|
17
|
+
* This service is intended for use by the consumer environment.
|
|
18
|
+
*/
|
|
19
|
+
export class IAMAuthenticationUserLocalConsumerService<
|
|
20
|
+
CompleteContext extends object,
|
|
21
|
+
InitiateContext extends object
|
|
22
|
+
> extends IAMAuthenticationConsumerService<CompleteContext, InitiateContext> {
|
|
23
|
+
constructor(configProvider: ConfigProviderService, logger: LoggerService, moduleName: string, serviceName: string) {
|
|
24
|
+
super(configProvider, logger, moduleName, serviceName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async complete(
|
|
28
|
+
data: IAMAuthenticationUserLocalConsumerCompleteData,
|
|
29
|
+
options: IAMAuthenticationUserLocalConsumerCompleteOptions<CompleteContext>
|
|
30
|
+
): Promise<IAMAuthenticationUserLocalConsumerCompleteResult> {
|
|
31
|
+
return super.complete(data, options) as Promise<IAMAuthenticationUserLocalConsumerCompleteResult>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async initiate(
|
|
35
|
+
data: IAMAuthenticationUserLocalConsumerInitiateData,
|
|
36
|
+
options: IAMAuthenticationUserLocalConsumerInitiateOptions<InitiateContext>
|
|
37
|
+
): Promise<IAMAuthenticationUserLocalConsumerInitiateResult> {
|
|
38
|
+
return super.initiate(data, options) as Promise<IAMAuthenticationUserLocalConsumerInitiateResult>;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,55 +1,54 @@
|
|
|
1
1
|
import { GenericObject } from '@node-c/core';
|
|
2
2
|
|
|
3
|
-
export enum
|
|
3
|
+
export enum IAMAuthorizationCheckErrorCode {
|
|
4
4
|
// eslint-disable-next-line no-unused-vars
|
|
5
|
-
|
|
5
|
+
FGANoAccess = 'FGA_NO_ACCESS',
|
|
6
6
|
// eslint-disable-next-line no-unused-vars
|
|
7
7
|
RBACNoAccessToModule = 'RBAC_NO_ACCESS_TO_MODULE',
|
|
8
8
|
// eslint-disable-next-line no-unused-vars
|
|
9
9
|
RBACNoAccessToResource = 'RBAC_NO_ACCESS_TO_RESOURCE'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface
|
|
13
|
-
allowedInputData?: GenericObject;
|
|
14
|
-
allowedOutputData?: GenericObject;
|
|
15
|
-
forbiddenInputData?: GenericObject;
|
|
16
|
-
forbiddenOutputData?: GenericObject;
|
|
17
|
-
id: Id;
|
|
18
|
-
inputDataFieldName?: string;
|
|
19
|
-
moduleName: string;
|
|
20
|
-
name: string;
|
|
21
|
-
requiredStaticData?: GenericObject;
|
|
22
|
-
resources?: string[];
|
|
23
|
-
// required when resources is set
|
|
24
|
-
resourceContext?: string;
|
|
25
|
-
userFieldName?: string;
|
|
26
|
-
// userTypes: GenericObject[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface AuthorizationStaticCheckAccessOptions {
|
|
12
|
+
export interface IAMAuthorizationStaticCheckAccessOptions {
|
|
30
13
|
moduleName: string;
|
|
31
14
|
resource?: string;
|
|
32
15
|
resourceContext?: string;
|
|
33
16
|
}
|
|
34
17
|
|
|
35
|
-
export interface
|
|
36
|
-
|
|
37
|
-
errorCode?: AuthorizationCheckErrorCode;
|
|
18
|
+
export interface IAMAuthorizationStaticCheckAccessResult {
|
|
19
|
+
errorCode?: IAMAuthorizationCheckErrorCode;
|
|
38
20
|
hasAccess: boolean;
|
|
39
21
|
inputDataToBeMutated: GenericObject;
|
|
40
22
|
noMatchForResource: boolean;
|
|
23
|
+
permissions: GenericObject<IAMPermission<unknown>>;
|
|
41
24
|
}
|
|
42
25
|
|
|
43
|
-
export interface
|
|
44
|
-
|
|
26
|
+
export interface IAMAuthorizationUser<PermissionId> {
|
|
27
|
+
currentPermissions: GenericObject<IAMPermission<PermissionId>>;
|
|
45
28
|
}
|
|
46
29
|
|
|
47
|
-
export interface
|
|
30
|
+
export interface IAMAuthorizeApiKeyData {
|
|
48
31
|
apiKey: string;
|
|
49
32
|
signature?: string;
|
|
50
33
|
signatureContent?: string;
|
|
51
34
|
}
|
|
52
35
|
|
|
53
|
-
export interface
|
|
36
|
+
export interface IAMAuthorizeApiKeyOptions {
|
|
54
37
|
config: { apiKey?: string; apiSecret?: string; apiSecretAlgorithm?: string };
|
|
55
38
|
}
|
|
39
|
+
|
|
40
|
+
export interface IAMPermission<Id> {
|
|
41
|
+
allowedInputData?: GenericObject;
|
|
42
|
+
allowedOutputData?: GenericObject;
|
|
43
|
+
forbiddenInputData?: GenericObject;
|
|
44
|
+
forbiddenOutputData?: GenericObject;
|
|
45
|
+
id: Id;
|
|
46
|
+
inputDataFieldName?: string;
|
|
47
|
+
moduleName: string;
|
|
48
|
+
name: string;
|
|
49
|
+
requiredStaticData?: GenericObject;
|
|
50
|
+
resources?: string[];
|
|
51
|
+
// required when resources is set
|
|
52
|
+
resourceContext?: string;
|
|
53
|
+
userFieldName?: string;
|
|
54
|
+
}
|
|
@@ -1,55 +1,32 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
ApplicationError,
|
|
5
|
-
DataEntityService,
|
|
6
|
-
DomainEntityService,
|
|
7
|
-
DomainEntityServiceDefaultData,
|
|
8
|
-
DomainMethod,
|
|
9
|
-
GenericObject,
|
|
10
|
-
LoggerService,
|
|
11
|
-
getNested,
|
|
12
|
-
setNested
|
|
13
|
-
} from '@node-c/core';
|
|
3
|
+
import { ApplicationError, GenericObject, LoggerService, getNested, setNested } from '@node-c/core';
|
|
14
4
|
|
|
15
5
|
import ld from 'lodash';
|
|
16
6
|
|
|
17
7
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
IAMAuthorizationCheckErrorCode,
|
|
9
|
+
IAMAuthorizationStaticCheckAccessOptions,
|
|
10
|
+
IAMAuthorizationStaticCheckAccessResult,
|
|
11
|
+
IAMAuthorizationUser,
|
|
12
|
+
IAMAuthorizeApiKeyData,
|
|
13
|
+
IAMAuthorizeApiKeyOptions,
|
|
14
|
+
IAMPermission
|
|
25
15
|
} from './iam.authorization.definitions';
|
|
26
16
|
|
|
27
17
|
import { DecodedTokenContent, IAMTokenManagerService } from '../tokenManager';
|
|
28
18
|
|
|
29
19
|
export class IAMAuthorizationService<
|
|
30
|
-
AuthorizationPoint extends BaseAuthorizationPoint<unknown> = BaseAuthorizationPoint<unknown>,
|
|
31
|
-
Data extends DomainEntityServiceDefaultData<Partial<AuthorizationPoint>> = DomainEntityServiceDefaultData<
|
|
32
|
-
Partial<AuthorizationPoint>
|
|
33
|
-
>,
|
|
34
20
|
TokenManager extends IAMTokenManagerService<object> = IAMTokenManagerService<object>
|
|
35
|
-
> extends DomainEntityService<
|
|
36
|
-
AuthorizationPoint,
|
|
37
|
-
DataEntityService<AuthorizationPoint>,
|
|
38
|
-
Data,
|
|
39
|
-
Record<string, DataEntityService<Partial<AuthorizationPoint>>> | undefined
|
|
40
21
|
> {
|
|
41
22
|
constructor(
|
|
42
|
-
|
|
43
|
-
protected defaultMethods: string[] = [DomainMethod.Find],
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
44
24
|
protected logger: LoggerService,
|
|
45
|
-
protected additionalDataEntityServices?: GenericObject<DataEntityService<Partial<AuthorizationPoint>>>,
|
|
46
25
|
// eslint-disable-next-line no-unused-vars
|
|
47
26
|
protected tokenManager?: TokenManager
|
|
48
|
-
) {
|
|
49
|
-
super(dataAuthorizationPointsService, defaultMethods, logger, additionalDataEntityServices);
|
|
50
|
-
}
|
|
27
|
+
) {}
|
|
51
28
|
|
|
52
|
-
async authorizeApiKey(data:
|
|
29
|
+
async authorizeApiKey(data: IAMAuthorizeApiKeyData, options: IAMAuthorizeApiKeyOptions): Promise<{ valid: boolean }> {
|
|
53
30
|
const { logger } = this;
|
|
54
31
|
const { apiKey, signature, signatureContent } = data;
|
|
55
32
|
const {
|
|
@@ -84,8 +61,6 @@ export class IAMAuthorizationService<
|
|
|
84
61
|
return { valid: true };
|
|
85
62
|
}
|
|
86
63
|
|
|
87
|
-
// TODO: decouple from users
|
|
88
|
-
// TODO: use an idToken, rather than an accessToken, for the permissions
|
|
89
64
|
async authorizeBearer<UserTokenEnityFields = unknown>(
|
|
90
65
|
data: { authToken?: string; refreshToken?: string },
|
|
91
66
|
options?: { identifierDataField?: string }
|
|
@@ -104,7 +79,7 @@ export class IAMAuthorizationService<
|
|
|
104
79
|
return { valid: false };
|
|
105
80
|
}
|
|
106
81
|
if (!authToken) {
|
|
107
|
-
logger.error('Missing
|
|
82
|
+
logger.error('Missing authorization token.');
|
|
108
83
|
return { valid: false };
|
|
109
84
|
}
|
|
110
85
|
let newAccessToken: string | undefined;
|
|
@@ -113,12 +88,12 @@ export class IAMAuthorizationService<
|
|
|
113
88
|
let tokenContent: DecodedTokenContent<UserTokenEnityFields> | undefined;
|
|
114
89
|
try {
|
|
115
90
|
const tokenRes = await tokenManager.verifyAccessToken(authToken, {
|
|
91
|
+
accessTokenDataRefreshTokenField: 'refreshToken',
|
|
116
92
|
deleteFromStoreIfExpired: true,
|
|
117
93
|
identifierDataField,
|
|
118
94
|
persistNewToken: true,
|
|
119
95
|
purgeStoreOnRenew: true,
|
|
120
|
-
refreshToken
|
|
121
|
-
refreshTokenAccessTokenIdentifierDataField: 'accessToken'
|
|
96
|
+
refreshToken
|
|
122
97
|
});
|
|
123
98
|
tokenContent = tokenRes.content as unknown as DecodedTokenContent<UserTokenEnityFields>;
|
|
124
99
|
if (tokenRes.newAccessToken) {
|
|
@@ -143,9 +118,9 @@ export class IAMAuthorizationService<
|
|
|
143
118
|
|
|
144
119
|
static checkAccess<InputData = GenericObject>(
|
|
145
120
|
inputData: InputData,
|
|
146
|
-
user:
|
|
147
|
-
options:
|
|
148
|
-
):
|
|
121
|
+
user: IAMAuthorizationUser<unknown>,
|
|
122
|
+
options: IAMAuthorizationStaticCheckAccessOptions
|
|
123
|
+
): IAMAuthorizationStaticCheckAccessResult {
|
|
149
124
|
const { moduleName, resourceContext, resource } = options;
|
|
150
125
|
let hasResource = false;
|
|
151
126
|
if (resource) {
|
|
@@ -156,22 +131,22 @@ export class IAMAuthorizationService<
|
|
|
156
131
|
}
|
|
157
132
|
hasResource = true;
|
|
158
133
|
}
|
|
159
|
-
// check the access to the found
|
|
134
|
+
// check the access to the found permissions
|
|
160
135
|
const mutatedInputData = ld.cloneDeep(inputData);
|
|
161
|
-
const
|
|
162
|
-
const {
|
|
163
|
-
let authorizationPointsCount = 0;
|
|
164
|
-
let authorizationPointsForDifferentModules = 0;
|
|
165
|
-
let authorizationPointsForDifferentContexts = 0;
|
|
136
|
+
const usedPermissions: GenericObject<IAMPermission<unknown>> = {};
|
|
137
|
+
const { currentPermissions } = user;
|
|
166
138
|
let hasAccess = false;
|
|
167
139
|
let inputDataToBeMutated: GenericObject = {};
|
|
168
140
|
let noMatchForResource = false;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
141
|
+
let permissionsCount = 0;
|
|
142
|
+
let permissionsForDifferentModules = 0;
|
|
143
|
+
let permissionsForDifferentContexts = 0;
|
|
144
|
+
for (const apId in currentPermissions) {
|
|
145
|
+
const apData = currentPermissions[apId];
|
|
146
|
+
permissionsCount++;
|
|
172
147
|
// RBAC - check whether the user has general access to the module.
|
|
173
148
|
if (moduleName !== apData.moduleName) {
|
|
174
|
-
|
|
149
|
+
permissionsForDifferentModules++;
|
|
175
150
|
continue;
|
|
176
151
|
}
|
|
177
152
|
// RBAC - check whether the user has general access to the resource.
|
|
@@ -181,7 +156,7 @@ export class IAMAuthorizationService<
|
|
|
181
156
|
apData.resourceContext !== resourceContext ||
|
|
182
157
|
!apData.resources?.includes(resource!))
|
|
183
158
|
) {
|
|
184
|
-
|
|
159
|
+
permissionsForDifferentContexts++;
|
|
185
160
|
continue;
|
|
186
161
|
}
|
|
187
162
|
// FGA - check whether the user has access based on specific input and user fields.
|
|
@@ -264,22 +239,22 @@ export class IAMAuthorizationService<
|
|
|
264
239
|
}
|
|
265
240
|
}
|
|
266
241
|
inputDataToBeMutated = ld.merge(inputDataToBeMutated, innerInputDataToBeMutated);
|
|
267
|
-
|
|
242
|
+
usedPermissions[apId] = apData;
|
|
268
243
|
break;
|
|
269
244
|
}
|
|
270
|
-
const returnData:
|
|
271
|
-
authorizationPoints: usedAuthorizationPoints,
|
|
245
|
+
const returnData: IAMAuthorizationStaticCheckAccessResult = {
|
|
272
246
|
hasAccess,
|
|
273
247
|
inputDataToBeMutated,
|
|
274
|
-
noMatchForResource
|
|
248
|
+
noMatchForResource,
|
|
249
|
+
permissions: usedPermissions
|
|
275
250
|
};
|
|
276
251
|
if (!hasAccess) {
|
|
277
|
-
if (
|
|
278
|
-
returnData.errorCode =
|
|
279
|
-
} else if (
|
|
280
|
-
returnData.errorCode =
|
|
252
|
+
if (!permissionsCount || permissionsForDifferentModules === permissionsCount) {
|
|
253
|
+
returnData.errorCode = IAMAuthorizationCheckErrorCode.RBACNoAccessToModule;
|
|
254
|
+
} else if (permissionsForDifferentContexts === permissionsCount) {
|
|
255
|
+
returnData.errorCode = IAMAuthorizationCheckErrorCode.RBACNoAccessToResource;
|
|
281
256
|
} else {
|
|
282
|
-
returnData.errorCode =
|
|
257
|
+
returnData.errorCode = IAMAuthorizationCheckErrorCode.FGANoAccess;
|
|
283
258
|
}
|
|
284
259
|
}
|
|
285
260
|
return returnData;
|
|
@@ -338,15 +313,15 @@ export class IAMAuthorizationService<
|
|
|
338
313
|
}
|
|
339
314
|
|
|
340
315
|
static processOutputData(
|
|
341
|
-
|
|
316
|
+
permissions: { [id: number]: IAMPermission<unknown> },
|
|
342
317
|
outputData: GenericObject
|
|
343
318
|
): {
|
|
344
319
|
outputDataToBeMutated: GenericObject;
|
|
345
320
|
} {
|
|
346
321
|
const mutatedOutputData = ld.cloneDeep(outputData);
|
|
347
322
|
let outputDataToBeMutated: GenericObject = {};
|
|
348
|
-
for (const apId in
|
|
349
|
-
const apData =
|
|
323
|
+
for (const apId in permissions) {
|
|
324
|
+
const apData = permissions[apId];
|
|
350
325
|
const { allowedOutputData, forbiddenOutputData } = apData;
|
|
351
326
|
const innerMutatedOutputData = ld.cloneDeep(mutatedOutputData);
|
|
352
327
|
const innerOutputDataToBeMutated: GenericObject = {};
|
package/src/services/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export * from './authentication';
|
|
2
|
+
export * from './authenticationConsumer';
|
|
3
|
+
export * from './authenticationManager';
|
|
2
4
|
export * from './authenticationOAuth2';
|
|
5
|
+
export * from './authenticationOAuth2Consumer';
|
|
6
|
+
export * from './authenticationPassthrough';
|
|
7
|
+
export * from './authenticationPassthroughConsumer';
|
|
3
8
|
export * from './authenticationUserLocal';
|
|
9
|
+
export * from './authenticationUserLocalConsumer';
|
|
4
10
|
export * from './authorization';
|
|
5
11
|
export * from './mfa';
|
|
6
12
|
export * from './tokenManager';
|
|
7
|
-
export * from './
|
|
13
|
+
export * from './users';
|
|
@@ -8,8 +8,10 @@ export interface BaseTokenEntityFields {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export type DecodedTokenContent<TokenEntityFields> = {
|
|
11
|
+
aud: string;
|
|
11
12
|
exp?: number;
|
|
12
13
|
iat: number;
|
|
14
|
+
iss: string;
|
|
13
15
|
data?: TokenEntityFields & BaseTokenEntityFields;
|
|
14
16
|
};
|
|
15
17
|
|
|
@@ -30,6 +32,7 @@ export type TokenManagerCreateOptions = {
|
|
|
30
32
|
purgeOldFromData?: boolean;
|
|
31
33
|
tokenContentOnlyFields?: string[];
|
|
32
34
|
ttl?: number;
|
|
35
|
+
useExternalTokenAsLocal?: boolean;
|
|
33
36
|
} & DomainCreateOptions;
|
|
34
37
|
|
|
35
38
|
export enum TokenType {
|
|
@@ -48,13 +51,13 @@ export interface TokenManagerVerifyResult<TokenEntityFields> {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
export interface VerifyAccessTokenOptions {
|
|
54
|
+
accessTokenDataRefreshTokenField?: string;
|
|
51
55
|
deleteFromStoreIfExpired?: boolean;
|
|
52
56
|
identifierDataField?: string;
|
|
53
57
|
newAccessTokenExpiresInMinutes?: number;
|
|
54
58
|
persistNewToken?: boolean;
|
|
55
59
|
purgeStoreOnRenew?: boolean;
|
|
56
60
|
refreshToken?: string;
|
|
57
|
-
refreshTokenAccessTokenIdentifierDataField?: string;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export interface VerifyAccessTokenReturnData<TokenEntityFields> {
|