Skip to content

Commit 804989b

Browse files
francescopersicogunzip
authored andcommitted
Enable custom acceptedClockSkewMs using an environment variable (#241)
1 parent da211a9 commit 804989b

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ REDIS_PASSWORD=put_the_azure_redis_password_here
99
TOKEN_DURATION_IN_SECONDS=3600
1010
SAML_CALLBACK_URL="https://italia-backend/assertionConsumerService"
1111
SAML_ISSUER="http://italia-backend"
12+
SAML_ACCEPTED_CLOCK_SKEW_MS=0
1213
SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX=1
1314
PRE_SHARED_KEY="12345"
1415
ALLOW_NOTIFY_IP_SOURCE_RANGE="::ffff:ac13:1/112"

src/container.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ const SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX: number = parseInt(
9494
DEFAULT_SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX,
9595
10
9696
);
97+
const DEFAULT_SAML_ACCEPTED_CLOCK_SKEW_MS = "-1";
98+
const SAML_ACCEPTED_CLOCK_SKEW_MS = parseInt(
99+
process.env.SAML_ACCEPTED_CLOCK_SKEW_MS ||
100+
DEFAULT_SAML_ACCEPTED_CLOCK_SKEW_MS,
101+
10
102+
);
97103
container.register({
104+
samlAcceptedClockSkewMs: awilix.asValue(SAML_ACCEPTED_CLOCK_SKEW_MS),
98105
samlAttributeConsumingServiceIndex: awilix.asValue(
99106
SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX
100107
),

src/controllers/__tests__/authenticationController.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ nCnxP/vK5rgVHU3nQfq+e/B6FVWZ
7676
`;
7777
const samlCallbackUrl = "http://italia-backend/assertionConsumerService";
7878
const samlIssuer = "http://italia-backend";
79+
const samlAcceptedClockSkewMs = -1;
7980
const samlAttributeConsumingServiceIndex = 0;
8081

8182
// user constant
@@ -184,6 +185,7 @@ const spidStrategyInstance = spidStrategy(
184185
samlKey,
185186
samlCallbackUrl,
186187
samlIssuer,
188+
samlAcceptedClockSkewMs,
187189
samlAttributeConsumingServiceIndex
188190
);
189191
spidStrategyInstance.logout = jest.fn();

src/strategies/spidStrategy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const spidStrategy = (
1111
samlKey: string,
1212
samlCallbackUrl: string,
1313
samlIssuer: string,
14+
samlAcceptedClockSkewMs: number,
1415
samlAttributeConsumingServiceIndex: number
1516
) => {
1617
return new SpidStrategy(
@@ -70,6 +71,7 @@ const spidStrategy = (
7071
}
7172
},
7273
sp: {
74+
acceptedClockSkewMs: samlAcceptedClockSkewMs,
7375
attributeConsumingServiceIndex: samlAttributeConsumingServiceIndex,
7476
attributes: {
7577
attributes: ["fiscalNumber", "name", "familyName", "email"],

0 commit comments

Comments
 (0)