2022-10-11 13:29:23 +00:00
|
|
|
import { ensureSetting } from './ensure';
|
|
|
|
import { API } from './types';
|
2022-09-27 10:53:49 +00:00
|
|
|
|
|
|
|
export function ensureOIDCSettingsSet(
|
2022-10-11 13:29:23 +00:00
|
|
|
api: API,
|
|
|
|
accessTokenLifetime: number,
|
|
|
|
idTokenLifetime: number,
|
|
|
|
refreshTokenExpiration: number,
|
2022-09-27 10:53:49 +00:00
|
|
|
refreshTokenIdleExpiration: number,
|
2023-02-15 01:52:11 +00:00
|
|
|
) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureSetting(
|
2022-09-27 10:53:49 +00:00
|
|
|
api,
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.adminBaseURL}/settings/oidc`,
|
|
|
|
(body: any) => {
|
|
|
|
const result = {
|
|
|
|
sequence: body.settings?.details?.sequence,
|
|
|
|
id: body.settings.id,
|
|
|
|
entity: null,
|
|
|
|
};
|
|
|
|
|
2022-09-27 10:53:49 +00:00
|
|
|
if (
|
2022-10-11 13:29:23 +00: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 10:53:49 +00:00
|
|
|
) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return { ...result, entity: body.settings };
|
2022-09-27 10:53:49 +00:00
|
|
|
}
|
2022-10-11 13:29:23 +00:00
|
|
|
return result;
|
2022-09-27 10:53:49 +00:00
|
|
|
},
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.adminBaseURL}/settings/oidc`,
|
2022-09-27 10:53:49 +00: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);
|
|
|
|
}
|