2024-11-18 23:38:52 +02:00
|
|
|
const Errors = {
|
|
|
|
INVALID_OIDC_CONFIGURATION: {
|
|
|
|
invalidOidcConfiguration: 'Invalid OIDC configuration',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-10-17 19:18:19 +02:00
|
|
|
module.exports = {
|
2024-11-18 23:38:52 +02:00
|
|
|
exits: {
|
|
|
|
invalidOidcConfiguration: {
|
|
|
|
responseType: 'serverError',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async fn() {
|
2023-10-19 16:05:34 +02:00
|
|
|
let oidc = null;
|
|
|
|
if (sails.hooks.oidc.isActive()) {
|
2024-11-18 23:38:52 +02:00
|
|
|
let oidcClient;
|
|
|
|
try {
|
|
|
|
oidcClient = await sails.hooks.oidc.getClient();
|
|
|
|
} catch (error) {
|
|
|
|
sails.log.warn(`Error while initializing OIDC client: ${error}`);
|
|
|
|
throw Errors.INVALID_OIDC_CONFIGURATION;
|
|
|
|
}
|
2023-10-19 16:05:34 +02:00
|
|
|
|
2024-07-16 12:33:38 +02:00
|
|
|
const authorizationUrlParams = {
|
2024-07-16 12:19:27 +02:00
|
|
|
scope: sails.config.custom.oidcScopes,
|
2024-07-16 12:33:38 +02:00
|
|
|
};
|
2024-07-16 12:19:27 +02:00
|
|
|
|
2024-07-16 12:33:38 +02:00
|
|
|
if (!sails.config.custom.oidcUseDefaultResponseMode) {
|
|
|
|
authorizationUrlParams.response_mode = sails.config.custom.oidcResponseMode;
|
2024-07-16 12:19:27 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 16:05:34 +02:00
|
|
|
oidc = {
|
2024-07-16 12:33:38 +02:00
|
|
|
authorizationUrl: oidcClient.authorizationUrl(authorizationUrlParams),
|
2023-10-19 16:05:34 +02:00
|
|
|
endSessionUrl: oidcClient.issuer.end_session_endpoint ? oidcClient.endSessionUrl({}) : null,
|
2024-02-01 00:31:15 +01:00
|
|
|
isEnforced: sails.config.custom.oidcEnforced,
|
2023-10-19 16:05:34 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-17 19:18:19 +02:00
|
|
|
return {
|
|
|
|
item: {
|
2023-10-19 16:05:34 +02:00
|
|
|
oidc,
|
2024-06-14 16:38:06 +02:00
|
|
|
allowAllToCreateProjects: sails.config.custom.allowAllToCreateProjects,
|
2023-10-17 19:18:19 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|