mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
681541f41b
adds possibilities to cap authenticated requests and execution seconds of actions on a defined intervall
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { ensureSetting } from './ensure';
|
|
import { API } from './types';
|
|
|
|
export function ensureOIDCSettingsSet(
|
|
api: API,
|
|
accessTokenLifetime: number,
|
|
idTokenLifetime: number,
|
|
refreshTokenExpiration: number,
|
|
refreshTokenIdleExpiration: number,
|
|
) {
|
|
return ensureSetting(
|
|
api,
|
|
`${api.adminBaseURL}/settings/oidc`,
|
|
(body: any) => {
|
|
const result = {
|
|
sequence: body.settings?.details?.sequence,
|
|
id: body.settings.id,
|
|
entity: null,
|
|
};
|
|
|
|
if (
|
|
body.settings &&
|
|
body.settings.accessTokenLifetime === hoursToDuration(accessTokenLifetime) &&
|
|
body.settings.idTokenLifetime === hoursToDuration(idTokenLifetime) &&
|
|
body.settings.refreshTokenExpiration === daysToDuration(refreshTokenExpiration) &&
|
|
body.settings.refreshTokenIdleExpiration === daysToDuration(refreshTokenIdleExpiration)
|
|
) {
|
|
return { ...result, entity: body.settings };
|
|
}
|
|
return result;
|
|
},
|
|
`${api.adminBaseURL}/settings/oidc`,
|
|
{
|
|
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);
|
|
}
|