@friggframework/core 2.0.0--canary.678.58db4b2.0 → 2.0.0--canary.680.b3ca7f1.0
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 +11 -0
- package/CLAUDE.md +0 -2
- package/README.md +0 -57
- package/application/commands/integration-commands.js +18 -8
- package/application/index.js +6 -2
- package/database/encryption/README.md +2 -0
- package/database/encryption/encryption-schema-registry.js +35 -12
- package/database/encryption/field-encryption-service.js +30 -3
- package/database/encryption/test-support/fake-ciphertext.js +15 -0
- package/handlers/app-definition-loader.js +16 -13
- package/handlers/backend-utils.js +31 -25
- package/handlers/routers/health.js +1 -4
- package/handlers/workers/integration-defined-workers.js +5 -2
- package/index.js +4 -2
- package/integrations/index.js +0 -4
- package/integrations/integration-router.js +16 -29
- package/integrations/utils/map-integration-dto.js +1 -15
- package/management-api/openapi/components.js +7 -1
- package/management-api/openapi/v2-operations.js +4 -0
- package/management-api/v2/dependencies.js +23 -13
- package/modules/entity-type-registry.js +311 -0
- package/modules/index.js +6 -0
- package/modules/use-cases/entity-types.js +36 -12
- package/package.json +5 -6
- package/types/index.d.ts +1 -1
- package/types/modules/index.d.ts +58 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +122 -109
- package/user/use-cases/get-user-from-x-frigg-headers.js +51 -29
- package/user/user.js +0 -11
- package/types/user/index.d.ts +0 -67
- package/user/adopter-jwt-config.js +0 -177
- package/user/adopter-jwt-errors.js +0 -65
- package/user/adopter-token-verifier.js +0 -122
- package/user/app-user-helpers.js +0 -73
- package/user/tests/doubles/adopter-jwt-fixtures.js +0 -130
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.680.b3ca7f1.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"express-async-handler": "^1.2.0",
|
|
29
29
|
"form-data": "^4.0.6",
|
|
30
30
|
"fs-extra": "^11.2.0",
|
|
31
|
-
"jose": "^5.10.0",
|
|
32
31
|
"lodash": "4.18.1",
|
|
33
32
|
"lodash.get": "^4.4.2",
|
|
34
33
|
"node-fetch": "^2.6.7",
|
|
@@ -48,9 +47,9 @@
|
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
52
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
53
|
-
"@friggframework/test": "2.0.0--canary.
|
|
50
|
+
"@friggframework/eslint-config": "2.0.0--canary.680.b3ca7f1.0",
|
|
51
|
+
"@friggframework/prettier-config": "2.0.0--canary.680.b3ca7f1.0",
|
|
52
|
+
"@friggframework/test": "2.0.0--canary.680.b3ca7f1.0",
|
|
54
53
|
"@prisma/client": "^6.19.3",
|
|
55
54
|
"@types/lodash": "4.17.15",
|
|
56
55
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -90,5 +89,5 @@
|
|
|
90
89
|
"publishConfig": {
|
|
91
90
|
"access": "public"
|
|
92
91
|
},
|
|
93
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "b3ca7f1295d79b4d0cb5fb9fb4ec41093033ba4d"
|
|
94
93
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare module "@friggframework/core" {
|
|
2
|
+
/** Where an entity type comes from: the app's `entities` map or an integration binding it. */
|
|
3
|
+
export type EntityTypeSource =
|
|
4
|
+
| { kind: "app" }
|
|
5
|
+
| { kind: "integration"; name: string };
|
|
6
|
+
|
|
7
|
+
export type EntityScope = "individual" | "organization" | "global";
|
|
8
|
+
|
|
9
|
+
/** App-level settings carried from the `entities` entry; empty for an inferred-only type. */
|
|
10
|
+
export interface EntityTypeSettings {
|
|
11
|
+
scope?: EntityScope | { default?: EntityScope; allow?: EntityScope[] };
|
|
12
|
+
proxy?: Record<string, unknown>;
|
|
13
|
+
display?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface EntityTypeEntry {
|
|
17
|
+
/** The API module definition. */
|
|
18
|
+
definition: any;
|
|
19
|
+
/** Frozen. `{ kind: 'app' }` first when registered, then each binding integration. */
|
|
20
|
+
sources: readonly EntityTypeSource[];
|
|
21
|
+
/** Frozen. */
|
|
22
|
+
settings: Readonly<EntityTypeSettings>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Entity type name (the definition's moduleName) to its entry. */
|
|
26
|
+
export type EntityTypeRegistry = Map<string, EntityTypeEntry>;
|
|
27
|
+
|
|
28
|
+
/** One `appDefinition.entities` entry. The key must equal the definition's moduleName (and getName() when defined). */
|
|
29
|
+
export interface EntityRegistration extends EntityTypeSettings {
|
|
30
|
+
definition: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AppDefinitionEntities {
|
|
34
|
+
/** false turns inference off: every module an integration binds must be registered. Default true. */
|
|
35
|
+
$infer?: boolean;
|
|
36
|
+
[entityType: string]: EntityRegistration | boolean | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AppDefinition {
|
|
40
|
+
integrations: any[];
|
|
41
|
+
/** App-level entity type registry (ADR-059). */
|
|
42
|
+
entities?: AppDefinitionEntities;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Builds the registry from `entities` plus the modules integrations bind.
|
|
48
|
+
* Throws EntityRegistryError on an invalid registry.
|
|
49
|
+
*/
|
|
50
|
+
export function getEntityTypeRegistry(
|
|
51
|
+
appDefinition?: Pick<AppDefinition, "entities" | "integrations">
|
|
52
|
+
): EntityTypeRegistry;
|
|
53
|
+
|
|
54
|
+
/** Invalid `entities` registry. `code` is always `ENTITY_REGISTRY_INVALID`. */
|
|
55
|
+
export class EntityRegistryError extends Error {
|
|
56
|
+
code: "ENTITY_REGISTRY_INVALID";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,136 +1,149 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { fail } = require('../adopter-jwt-errors');
|
|
3
|
-
const {
|
|
4
|
-
findAppUsers,
|
|
5
|
-
createMissingAppUsers,
|
|
6
|
-
buildUser,
|
|
7
|
-
wantsOrganization,
|
|
8
|
-
} = require('../app-user-helpers');
|
|
9
|
-
|
|
10
|
-
const log = getLogger('frigg.user.adopter_jwt');
|
|
11
|
-
|
|
12
|
-
const idFromClaim = (value) => {
|
|
13
|
-
if (typeof value === 'string' && value.trim() !== '') return value;
|
|
14
|
-
if (typeof value === 'number' && Number.isFinite(value))
|
|
15
|
-
return String(value);
|
|
16
|
-
return null;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const hasOrganization = (individual) => {
|
|
20
|
-
const id = individual?.organizationId;
|
|
21
|
-
return id !== undefined && id !== null && id !== '';
|
|
22
|
-
};
|
|
1
|
+
const Boom = require('@hapi/boom');
|
|
23
2
|
|
|
24
3
|
/**
|
|
25
|
-
*
|
|
26
|
-
* one organization. Callers run this before creating anything, so a refused
|
|
27
|
-
* request leaves no new organization behind.
|
|
4
|
+
* STUB: Use case for retrieving a user from adopter-provided JWT token.
|
|
28
5
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Authenticates a request by a token issued by the adopter's own identity
|
|
50
|
-
* system (ADR-056 §2): verifies it, then finds or creates the individual and
|
|
51
|
-
* organization users it names.
|
|
6
|
+
* This is a stub implementation for future JWT authentication support.
|
|
7
|
+
* When implemented, this will allow adopters to use their own JWT tokens
|
|
8
|
+
* for authentication instead of Frigg's native token system.
|
|
9
|
+
*
|
|
10
|
+
* FUTURE IMPLEMENTATION REQUIREMENTS:
|
|
11
|
+
* - Validate JWT signature using jwtConfig.secret from app definition
|
|
12
|
+
* - Support configurable signing algorithms (HS256, HS384, HS512, RS256, RS384, RS512)
|
|
13
|
+
* - Extract user identifiers from JWT claims based on jwtConfig.userIdClaim and jwtConfig.orgIdClaim
|
|
14
|
+
* - Find or create user based on extracted claim values
|
|
15
|
+
* - Handle token expiration and validation errors
|
|
16
|
+
* - Support refresh tokens (optional)
|
|
17
|
+
* - Validate user ID conflicts if both individual and org IDs present in JWT
|
|
18
|
+
*
|
|
19
|
+
* RECOMMENDED IMPLEMENTATION:
|
|
20
|
+
* - Use 'jsonwebtoken' package for JWT parsing and validation
|
|
21
|
+
* - Cache JWT public keys for RS* algorithms
|
|
22
|
+
* - Add comprehensive error handling for invalid tokens
|
|
23
|
+
* - Log authentication attempts for security auditing
|
|
52
24
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
25
|
+
* @todo Implement JWT validation with jsonwebtoken package
|
|
26
|
+
* @todo Add unit tests for JWT parsing and claim extraction
|
|
27
|
+
* @todo Document adopter JWT integration guide in Frigg docs
|
|
28
|
+
* @todo Add support for JWT refresh tokens
|
|
29
|
+
* @todo Implement JWT public key caching for RS* algorithms
|
|
56
30
|
*
|
|
57
31
|
* @class GetUserFromAdopterJwt
|
|
58
32
|
*/
|
|
59
33
|
class GetUserFromAdopterJwt {
|
|
60
34
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {
|
|
35
|
+
* Creates a new GetUserFromAdopterJwt instance.
|
|
36
|
+
* @param {Object} params - Configuration parameters.
|
|
37
|
+
* @param {import('../repositories/user-repository-interface').UserRepositoryInterface} params.userRepository - Repository for user data operations.
|
|
63
38
|
* @param {Object} params.userConfig - The user config in the app definition.
|
|
64
|
-
* @param {{verify: Function, claimNames: Object}} params.tokenVerifier -
|
|
65
|
-
* from `createAdopterTokenVerifier`.
|
|
66
39
|
*/
|
|
67
|
-
constructor({ userRepository, userConfig
|
|
40
|
+
constructor({ userRepository, userConfig }) {
|
|
68
41
|
this.userRepository = userRepository;
|
|
69
42
|
this.userConfig = userConfig;
|
|
70
|
-
this.tokenVerifier = tokenVerifier;
|
|
71
43
|
}
|
|
72
44
|
|
|
73
45
|
/**
|
|
46
|
+
* Executes the use case.
|
|
74
47
|
* @async
|
|
75
|
-
* @param {string}
|
|
76
|
-
* @returns {Promise<import('../user').User>}
|
|
77
|
-
* @throws {Boom}
|
|
78
|
-
* (including `token_missing_user_claim`).
|
|
79
|
-
* @throws {Boom} 403 `multi_org_unsupported`.
|
|
80
|
-
* @throws {Boom} 503 `jwks_unavailable`, 500 `jwt_config_invalid` (from the verifier).
|
|
48
|
+
* @param {string} jwtToken - The JWT token from the Authorization header.
|
|
49
|
+
* @returns {Promise<import('../user').User>} The authenticated user object.
|
|
50
|
+
* @throws {Boom} 501 Not Implemented - This feature is not yet available.
|
|
81
51
|
*/
|
|
82
|
-
async execute(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
async execute(jwtToken) {
|
|
53
|
+
throw Boom.notImplemented(
|
|
54
|
+
'Adopter JWT authentication is not yet implemented. ' +
|
|
55
|
+
'This feature is planned for a future Frigg release. ' +
|
|
56
|
+
'Please use one of the supported authentication modes instead: ' +
|
|
57
|
+
'friggToken (native bearer token) or xFriggHeaders (backend-to-backend with x-frigg-appUserId/appOrgId headers).'
|
|
58
|
+
);
|
|
86
59
|
|
|
87
|
-
|
|
88
|
-
if (!appUserId) throw fail('token_missing_user_claim');
|
|
60
|
+
/* FUTURE IMPLEMENTATION PSEUDOCODE:
|
|
89
61
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
const jwt = require('jsonwebtoken');
|
|
63
|
+
|
|
64
|
+
// Validate JWT configuration exists
|
|
65
|
+
if (!this.userConfig.jwtConfig || !this.userConfig.jwtConfig.secret) {
|
|
66
|
+
throw Boom.badImplementation('JWT configuration is required when adopterJwt auth mode is enabled');
|
|
94
67
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
log.debug('Adopter token accepted', {
|
|
101
|
-
eventName: `${log.name}.accepted`,
|
|
102
|
-
hasOrganization: Boolean(user.getOrganizationUser()),
|
|
103
|
-
});
|
|
104
|
-
return user;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async _findOrCreateUser(appUserId, appOrgId) {
|
|
108
|
-
const cfg = this.userConfig;
|
|
109
|
-
const found = await findAppUsers(this.userRepository, cfg, {
|
|
110
|
-
appUserId,
|
|
111
|
-
appOrgId,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (wantsOrganization(cfg, appOrgId)) {
|
|
115
|
-
assertSingleOrganization(found.individual, found.organization);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const { individual: createdIndividual, organization } =
|
|
119
|
-
await createMissingAppUsers(this.userRepository, cfg, {
|
|
120
|
-
appUserId,
|
|
121
|
-
appOrgId,
|
|
122
|
-
...found,
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
// Verify and decode JWT
|
|
71
|
+
const decoded = jwt.verify(jwtToken, this.userConfig.jwtConfig.secret, {
|
|
72
|
+
algorithms: [this.userConfig.jwtConfig.algorithm || 'HS256']
|
|
123
73
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
74
|
+
|
|
75
|
+
// Extract user identifiers from claims
|
|
76
|
+
const appUserId = decoded[this.userConfig.jwtConfig.userIdClaim || 'sub'];
|
|
77
|
+
const appOrgId = decoded[this.userConfig.jwtConfig.orgIdClaim || 'org_id'];
|
|
78
|
+
|
|
79
|
+
// At least one identifier required
|
|
80
|
+
if (!appUserId && !appOrgId) {
|
|
81
|
+
throw Boom.badRequest('JWT must contain user or organization identifier claims');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Find existing users
|
|
85
|
+
let individualUserData = null;
|
|
86
|
+
let organizationUserData = null;
|
|
87
|
+
|
|
88
|
+
if (appUserId) {
|
|
89
|
+
individualUserData = await this.userRepository.findIndividualUserByAppUserId(appUserId);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (appOrgId) {
|
|
93
|
+
organizationUserData = await this.userRepository.findOrganizationUserByAppOrgId(appOrgId);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Validate no conflicts if both IDs present
|
|
97
|
+
if (appUserId && appOrgId && individualUserData && organizationUserData) {
|
|
98
|
+
const individualOrgId = individualUserData.organizationUser?.toString();
|
|
99
|
+
const expectedOrgId = organizationUserData.id?.toString();
|
|
100
|
+
|
|
101
|
+
if (individualOrgId !== expectedOrgId) {
|
|
102
|
+
throw Boom.badRequest(
|
|
103
|
+
'User ID mismatch: JWT claims refer to different users. ' +
|
|
104
|
+
'Individual and organization IDs must belong to the same user.'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Auto-create if not found
|
|
110
|
+
if (!individualUserData && !organizationUserData) {
|
|
111
|
+
if (appUserId) {
|
|
112
|
+
individualUserData = await this.userRepository.createIndividualUser({
|
|
113
|
+
appUserId,
|
|
114
|
+
username: `jwt-user-${appUserId}`,
|
|
115
|
+
email: decoded.email || `${appUserId}@jwt.local`,
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
organizationUserData = await this.userRepository.createOrganizationUser({
|
|
119
|
+
appOrgId,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return new User(
|
|
125
|
+
individualUserData,
|
|
126
|
+
organizationUserData,
|
|
127
|
+
this.userConfig.usePassword,
|
|
128
|
+
this.userConfig.primary,
|
|
129
|
+
this.userConfig.individualUserRequired,
|
|
130
|
+
this.userConfig.organizationUserRequired
|
|
130
131
|
);
|
|
132
|
+
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error.name === 'TokenExpiredError') {
|
|
135
|
+
throw Boom.unauthorized('JWT token has expired');
|
|
136
|
+
} else if (error.name === 'JsonWebTokenError') {
|
|
137
|
+
throw Boom.unauthorized('Invalid JWT token');
|
|
138
|
+
} else if (error.isBoom) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
throw Boom.unauthorized('JWT authentication failed');
|
|
131
142
|
}
|
|
132
|
-
|
|
143
|
+
*/
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
|
|
136
|
-
module.exports = { GetUserFromAdopterJwt
|
|
147
|
+
module.exports = { GetUserFromAdopterJwt };
|
|
148
|
+
|
|
149
|
+
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const Boom = require('@hapi/boom');
|
|
2
|
-
const {
|
|
3
|
-
findAppUsers,
|
|
4
|
-
createMissingAppUsers,
|
|
5
|
-
buildUser,
|
|
6
|
-
} = require('../app-user-helpers');
|
|
2
|
+
const { User } = require('../user');
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Use case for retrieving or creating a user from x-frigg header identifiers.
|
|
@@ -40,11 +36,22 @@ class GetUserFromXFriggHeaders {
|
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
// Find users by both IDs if both are provided
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
let individualUserData = null;
|
|
40
|
+
let organizationUserData = null;
|
|
41
|
+
|
|
42
|
+
if (appUserId && this.userConfig.individualUserRequired !== false) {
|
|
43
|
+
individualUserData =
|
|
44
|
+
await this.userRepository.findIndividualUserByAppUserId(
|
|
45
|
+
appUserId
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (appOrgId && this.userConfig.organizationUserRequired) {
|
|
50
|
+
organizationUserData =
|
|
51
|
+
await this.userRepository.findOrganizationUserByAppOrgId(
|
|
52
|
+
appOrgId
|
|
53
|
+
);
|
|
54
|
+
}
|
|
48
55
|
|
|
49
56
|
// VALIDATION/AUTO-LINKING: If both IDs provided and both users exist, handle mismatch
|
|
50
57
|
if (
|
|
@@ -77,33 +84,48 @@ class GetUserFromXFriggHeaders {
|
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
// Auto-create users independently if they don't exist and are required
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
appOrgId,
|
|
86
|
-
individual: individualUserData,
|
|
87
|
-
organization: organizationUserData,
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
individualUserData = created.individual;
|
|
91
|
-
organizationUserData = created.organization;
|
|
92
|
-
|
|
93
|
-
// Link individual user to newly created org user if individual exists
|
|
94
|
-
if (created.createdOrganization && individualUserData) {
|
|
87
|
+
if (
|
|
88
|
+
!individualUserData &&
|
|
89
|
+
appUserId &&
|
|
90
|
+
this.userConfig.individualUserRequired !== false
|
|
91
|
+
) {
|
|
95
92
|
individualUserData =
|
|
96
|
-
await this.userRepository.
|
|
93
|
+
await this.userRepository.createIndividualUser({
|
|
94
|
+
appUserId,
|
|
95
|
+
username: `app-user-${appUserId}`,
|
|
96
|
+
email: `${appUserId}@app.local`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
!organizationUserData &&
|
|
102
|
+
appOrgId &&
|
|
103
|
+
this.userConfig.organizationUserRequired
|
|
104
|
+
) {
|
|
105
|
+
organizationUserData =
|
|
106
|
+
await this.userRepository.createOrganizationUser({
|
|
107
|
+
appOrgId,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Link individual user to newly created org user if individual exists
|
|
111
|
+
if (individualUserData && organizationUserData) {
|
|
112
|
+
individualUserData = await this.userRepository.linkIndividualToOrganization(
|
|
97
113
|
individualUserData.id,
|
|
98
114
|
organizationUserData.id
|
|
99
115
|
);
|
|
116
|
+
}
|
|
100
117
|
}
|
|
101
118
|
|
|
102
|
-
|
|
103
|
-
this.userConfig,
|
|
119
|
+
const user = new User(
|
|
104
120
|
individualUserData,
|
|
105
|
-
organizationUserData
|
|
121
|
+
organizationUserData,
|
|
122
|
+
this.userConfig.usePassword,
|
|
123
|
+
this.userConfig.primary,
|
|
124
|
+
this.userConfig.individualUserRequired,
|
|
125
|
+
this.userConfig.organizationUserRequired
|
|
106
126
|
);
|
|
127
|
+
|
|
128
|
+
return user;
|
|
107
129
|
}
|
|
108
130
|
}
|
|
109
131
|
|
package/user/user.js
CHANGED
|
@@ -18,9 +18,6 @@ class User {
|
|
|
18
18
|
this.individualUser = individualUser;
|
|
19
19
|
this.organizationUser = organizationUser;
|
|
20
20
|
this.usePassword = usePassword;
|
|
21
|
-
// Organization role from an adopter token claim (ADR-056 §2). Read-only
|
|
22
|
-
// for now: nothing persists it until the membership package lands.
|
|
23
|
-
this.orgRole = null;
|
|
24
21
|
|
|
25
22
|
this.config = {
|
|
26
23
|
primary,
|
|
@@ -68,14 +65,6 @@ class User {
|
|
|
68
65
|
return this.config.individualUserRequired;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
getOrgRole() {
|
|
72
|
-
return this.orgRole;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setOrgRole(orgRole) {
|
|
76
|
-
this.orgRole = orgRole ?? null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
68
|
getIndividualUser() {
|
|
80
69
|
return this.individualUser;
|
|
81
70
|
}
|
package/types/user/index.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
declare module "@friggframework/core/user" {
|
|
2
|
-
export type AdopterJwtAlgorithm =
|
|
3
|
-
| "ES256"
|
|
4
|
-
| "ES384"
|
|
5
|
-
| "RS256"
|
|
6
|
-
| "RS384"
|
|
7
|
-
| "RS512"
|
|
8
|
-
| "HS256"
|
|
9
|
-
| "HS384"
|
|
10
|
-
| "HS512";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Verification of tokens issued by the adopter's identity system
|
|
14
|
-
* (`authModes.adopterJwt`, ADR-056 §2). Set exactly one of `jwksUri` or `secret`.
|
|
15
|
-
*/
|
|
16
|
-
export interface AdopterJwtConfig {
|
|
17
|
-
/** https URL of the issuer's JWKS (http only for localhost, 127.0.0.0/8, ::1). */
|
|
18
|
-
jwksUri?: string;
|
|
19
|
-
/** Shared HMAC secret for HS* tokens. */
|
|
20
|
-
secret?: string;
|
|
21
|
-
/** Required `iss`. With `jwksUri`, a startup warning is logged when unset. */
|
|
22
|
-
issuer?: string;
|
|
23
|
-
/** Accepted `aud`. Required with `jwksUri`. */
|
|
24
|
-
audience?: string | string[];
|
|
25
|
-
/** Allow-list. Default ES256 and RS256 with `jwksUri`, HS256 with `secret`. */
|
|
26
|
-
algorithms?: AdopterJwtAlgorithm[];
|
|
27
|
-
/** @deprecated Use `algorithms`. Setting both is an error. */
|
|
28
|
-
algorithm?: AdopterJwtAlgorithm;
|
|
29
|
-
/** Skew allowed on `exp` and `nbf`. Default 30. */
|
|
30
|
-
clockToleranceSec?: number;
|
|
31
|
-
/** Default `sub`. */
|
|
32
|
-
userIdClaim?: string;
|
|
33
|
-
/** Default `org_id`. */
|
|
34
|
-
orgIdClaim?: string;
|
|
35
|
-
/** Default `org_role`. Exposed as `User#getOrgRole()`; not stored. */
|
|
36
|
-
roleClaim?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface UserAuthModes {
|
|
40
|
-
friggToken?: boolean;
|
|
41
|
-
sharedSecret?: boolean;
|
|
42
|
-
adopterJwt?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** The `user` block of the app definition. */
|
|
46
|
-
export interface UserConfig {
|
|
47
|
-
usePassword?: boolean;
|
|
48
|
-
primary?: "individual" | "organization";
|
|
49
|
-
individualUserRequired?: boolean;
|
|
50
|
-
organizationUserRequired?: boolean;
|
|
51
|
-
strictUserValidation?: boolean;
|
|
52
|
-
authModes?: UserAuthModes;
|
|
53
|
-
jwtConfig?: AdopterJwtConfig;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class User {
|
|
57
|
-
getId(): string | undefined;
|
|
58
|
-
getAppUserId(): string | null;
|
|
59
|
-
getAppOrgId(): string | null;
|
|
60
|
-
getIndividualUser(): any;
|
|
61
|
-
getOrganizationUser(): any;
|
|
62
|
-
getPrimaryUser(): any;
|
|
63
|
-
/** The organization role from the adopter token, or null. */
|
|
64
|
-
getOrgRole(): string | null;
|
|
65
|
-
setOrgRole(orgRole: string | null): void;
|
|
66
|
-
}
|
|
67
|
-
}
|