Skip to content

Commit

Permalink
[#171839291] Refresh of IDP Metadata on interval (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnedMarshal authored Mar 19, 2020
1 parent a054776 commit d5f5873
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Those are all Environment variables needed by the application:
| IDP_METADATA_URL | Url to download SPID IDPs metadata from | string |
| SPID_TESTENV_URL | Url to SPID Testenv 2 | string |
| SPID_VALIDATOR_URL | Url to SPID Validator | string |
| IDP_METADATA_REFRESH_INTERVAL_SECONDS | The number of seconds when the IDPs Metadata are refreshed | int |
| CACHE_MAX_AGE_SECONDS | The value in seconds for duration of in-memory api cache | int |
| APICACHE_DEBUG | When is `true` enable the apicache debug mode | boolean |
| ALLOW_MULTIPLE_SESSIONS | When is `true` allow multiple sessions for an user (default `false`) | boolean |
Expand Down
17 changes: 17 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
endpointOrConnectionString,
getClientProfileRedirectionUrl,
hubName,
IDP_METADATA_REFRESH_INTERVAL_SECONDS,
PAGOPA_CLIENT,
REDIS_CLIENT,
samlConfig,
Expand Down Expand Up @@ -254,6 +255,22 @@ export function newApp(
IDP_METADATA_CONTROLLER
)
);
return _;
})
.map(_ => {
// Schedule automatic idpMetadataRefresher
const startIdpMetadataRefreshTimer = setInterval(
() =>
_.idpMetadataRefresher()
.run()
.catch(e => {
log.error("loadSpidStrategyOptions|error:%s", e);
}),
IDP_METADATA_REFRESH_INTERVAL_SECONDS * 1000
);
_.app.on("server:stop", () =>
clearInterval(startIdpMetadataRefreshTimer)
);
return _.app;
})
.map(_ => {
Expand Down
11 changes: 11 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ const maybeSpidTestenvOption = fromNullable(SPID_TESTENV_URL).map(_ => ({
[_]: true
}));

// Set default idp metadata refresh time to 7 days
export const DEFAULT_IDP_METADATA_REFRESH_INTERVAL_SECONDS = 3600 * 24 * 7;
export const IDP_METADATA_REFRESH_INTERVAL_SECONDS: number = process.env
.IDP_METADATA_REFRESH_INTERVAL_SECONDS
? parseInt(process.env.IDP_METADATA_REFRESH_INTERVAL_SECONDS, 10)
: DEFAULT_IDP_METADATA_REFRESH_INTERVAL_SECONDS;
log.info(
"IDP metadata refresh interval set to %s seconds",
IDP_METADATA_REFRESH_INTERVAL_SECONDS
);

export const serviceProviderConfig: IServiceProviderConfig = {
IDPMetadataUrl: IDP_METADATA_URL,
organization: {
Expand Down

0 comments on commit d5f5873

Please sign in to comment.