@openhi/constructs 0.0.92 → 0.0.93
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/lib/index.d.mts +28 -5
- package/lib/index.d.ts +28 -5
- package/lib/index.js +34 -5
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +34 -5
- package/lib/index.mjs.map +1 -1
- package/lib/pre-token-generation.handler.d.mts +0 -7
- package/lib/pre-token-generation.handler.d.ts +0 -7
- package/lib/pre-token-generation.handler.js +885 -11
- package/lib/pre-token-generation.handler.js.map +1 -1
- package/lib/pre-token-generation.handler.mjs +87 -11
- package/lib/pre-token-generation.handler.mjs.map +1 -1
- package/package.json +3 -3
package/lib/index.mjs
CHANGED
|
@@ -744,12 +744,15 @@ function resolveHandlerEntry3(dirname) {
|
|
|
744
744
|
return fromLib;
|
|
745
745
|
}
|
|
746
746
|
var PreTokenGenerationLambda = class extends Construct3 {
|
|
747
|
-
constructor(scope) {
|
|
747
|
+
constructor(scope, props) {
|
|
748
748
|
super(scope, "pre-token-generation-lambda");
|
|
749
749
|
this.lambda = new NodejsFunction3(this, "handler", {
|
|
750
750
|
entry: resolveHandlerEntry3(__dirname),
|
|
751
751
|
runtime: Runtime3.NODEJS_LATEST,
|
|
752
|
-
memorySize: 1024
|
|
752
|
+
memorySize: 1024,
|
|
753
|
+
environment: {
|
|
754
|
+
DYNAMO_TABLE_NAME: props.dynamoTableName
|
|
755
|
+
}
|
|
753
756
|
});
|
|
754
757
|
}
|
|
755
758
|
};
|
|
@@ -1358,6 +1361,7 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1358
1361
|
this.postAuthenticationLambda = this.createPostAuthenticationLambda();
|
|
1359
1362
|
this.postConfirmationLambda = this.createPostConfirmationLambda();
|
|
1360
1363
|
this.userPool = this.createUserPool();
|
|
1364
|
+
this.grantPreTokenGenerationPermissions();
|
|
1361
1365
|
this.grantPostAuthenticationPermissions();
|
|
1362
1366
|
this.grantPostConfirmationPermissions();
|
|
1363
1367
|
this.userPoolClient = this.createUserPoolClient();
|
|
@@ -1450,11 +1454,15 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1450
1454
|
return key;
|
|
1451
1455
|
}
|
|
1452
1456
|
/**
|
|
1453
|
-
* Creates the Pre Token Generation Lambda (Cognito trigger).
|
|
1454
|
-
*
|
|
1457
|
+
* Creates the Pre Token Generation Lambda (Cognito trigger). On every
|
|
1458
|
+
* sign-in and token refresh the Lambda resolves the User by Cognito `sub`
|
|
1459
|
+
* (GSI2) and injects `ohi_tid`, `ohi_wid`, `ohi_uid`, `ohi_uname` into
|
|
1460
|
+
* both the ID token and the access token (ADR 2026-03-17-01).
|
|
1455
1461
|
*/
|
|
1456
1462
|
createPreTokenGenerationLambda() {
|
|
1457
|
-
const construct = new PreTokenGenerationLambda(this
|
|
1463
|
+
const construct = new PreTokenGenerationLambda(this, {
|
|
1464
|
+
dynamoTableName: this.dataStoreTable().tableName
|
|
1465
|
+
});
|
|
1458
1466
|
return construct.lambda;
|
|
1459
1467
|
}
|
|
1460
1468
|
/**
|
|
@@ -1515,6 +1523,27 @@ var _OpenHiAuthService = class _OpenHiAuthService extends OpenHiService {
|
|
|
1515
1523
|
});
|
|
1516
1524
|
return userPool;
|
|
1517
1525
|
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Grants the Pre Token Generation Lambda read-only access on the data
|
|
1528
|
+
* store table and its GSIs. The Lambda only needs:
|
|
1529
|
+
* - `Query` on GSI2 to resolve a User by Cognito `sub`
|
|
1530
|
+
* - `GetItem` on the base table for direct User reads
|
|
1531
|
+
*
|
|
1532
|
+
* No write or scan access: a User missing `currentTenant`/`currentWorkspace`
|
|
1533
|
+
* falls into the absent-claims path; repair belongs in a separate backfill.
|
|
1534
|
+
*/
|
|
1535
|
+
grantPreTokenGenerationPermissions() {
|
|
1536
|
+
const dataStoreTable = this.dataStoreTable();
|
|
1537
|
+
const dynamoActions = ["dynamodb:GetItem", "dynamodb:Query"];
|
|
1538
|
+
dataStoreTable.grant(this.preTokenGenerationLambda, ...dynamoActions);
|
|
1539
|
+
this.preTokenGenerationLambda.addToRolePolicy(
|
|
1540
|
+
new PolicyStatement({
|
|
1541
|
+
effect: Effect.ALLOW,
|
|
1542
|
+
actions: [...dynamoActions],
|
|
1543
|
+
resources: [`${dataStoreTable.tableArn}/index/*`]
|
|
1544
|
+
})
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1518
1547
|
/**
|
|
1519
1548
|
* Grants the Post Authentication Lambda permission to call
|
|
1520
1549
|
* `cognito-idp:AdminUserGlobalSignOut`.
|