2022-10-11 15:29:23 +02:00
|
|
|
import { ensureSetting } from './ensure';
|
|
|
|
import { API } from './types';
|
2022-09-27 11:53:49 +01:00
|
|
|
|
|
|
|
export function ensureOIDCSettingsSet(
|
2022-10-11 15:29:23 +02:00
|
|
|
api: API,
|
|
|
|
accessTokenLifetime: number,
|
|
|
|
idTokenLifetime: number,
|
|
|
|
refreshTokenExpiration: number,
|
2022-09-27 11:53:49 +01:00
|
|
|
refreshTokenIdleExpiration: number,
|
2023-02-15 02:52:11 +01:00
|
|
|
) {
|
2022-10-11 15:29:23 +02:00
|
|
|
return ensureSetting(
|
2022-09-27 11:53:49 +01:00
|
|
|
api,
|
2022-10-11 15:29:23 +02:00
|
|
|
`${api.adminBaseURL}/settings/oidc`,
|
|
|
|
(body: any) => {
|
|
|
|
const result = {
|
|
|
|
sequence: body.settings?.details?.sequence,
|
|
|
|
id: body.settings.id,
|
|
|
|
entity: null,
|
|
|
|
};
|
|
|
|
|
2022-09-27 11:53:49 +01:00
|
|
|
if (
|
2022-10-11 15:29:23 +02:00
|
|
|
body.settings &&
|
|
|
|
body.settings.accessTokenLifetime === hoursToDuration(accessTokenLifetime) &&
|
|
|
|
body.settings.idTokenLifetime === hoursToDuration(idTokenLifetime) &&
|
|
|
|
body.settings.refreshTokenExpiration === daysToDuration(refreshTokenExpiration) &&
|
|
|
|
body.settings.refreshTokenIdleExpiration === daysToDuration(refreshTokenIdleExpiration)
|
2022-09-27 11:53:49 +01:00
|
|
|
) {
|
2022-10-11 15:29:23 +02:00
|
|
|
return { ...result, entity: body.settings };
|
2022-09-27 11:53:49 +01:00
|
|
|
}
|
2022-10-11 15:29:23 +02:00
|
|
|
return result;
|
2022-09-27 11:53:49 +01:00
|
|
|
},
|
2022-10-11 15:29:23 +02:00
|
|
|
`${api.adminBaseURL}/settings/oidc`,
|
2022-09-27 11:53:49 +01:00
|
|
|
{
|
|
|
|
accessTokenLifetime: hoursToDuration(accessTokenLifetime),
|
|
|
|
idTokenLifetime: hoursToDuration(idTokenLifetime),
|
|
|
|
refreshTokenExpiration: daysToDuration(refreshTokenExpiration),
|
|
|
|
refreshTokenIdleExpiration: daysToDuration(refreshTokenIdleExpiration),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hoursToDuration(hours: number): string {
|
|
|
|
return (hours * 3600).toString() + 's';
|
|
|
|
}
|
|
|
|
function daysToDuration(days: number): string {
|
|
|
|
return hoursToDuration(24 * days);
|
|
|
|
}
|