Skip to content

Commit 5a34235

Browse files
committed
Disable sso hook if it is not configured.
1 parent 0e67737 commit 5a34235

File tree

1 file changed

+12
-3
lines changed
  • ee/bulk-operations-dashboard/api/hooks/entra-sso

1 file changed

+12
-3
lines changed

ee/bulk-operations-dashboard/api/hooks/entra-sso/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ module.exports = function (sails) {
7878

7979
routes: {
8080
before: {
81-
'/login': async (req, res) => {
81+
'/login': async (req, res, next) => {
82+
if (!sails.config.custom.entraClientId) {
83+
return next();
84+
}
8285
// Get the sso login url and redirect the user
8386
// [?]: https://learn.microsoft.com/en-us/javascript/api/%40azure/msal-node/confidentialclientapplication?view=msal-js-latest#@azure-msal-node-confidentialclientapplication-getauthcodeurl
8487
let entraAuthorizationUrl = await entraSSOClient.getAuthCodeUrl({
@@ -88,7 +91,10 @@ module.exports = function (sails) {
8891
// Redirect the user to the SSO login url.
8992
res.redirect(entraAuthorizationUrl);
9093
},
91-
'/authorization-code/callback': async (req, res) => {
94+
'/authorization-code/callback': async (req, res, next) => {
95+
if (!sails.config.custom.entraClientId) {
96+
return next();
97+
}
9298
// Make sure there is a code query string.
9399
let codeToGetToken = req.query.code;
94100
if(!codeToGetToken){
@@ -107,7 +113,10 @@ module.exports = function (sails) {
107113
// Redirect the user to the signup-sso-user-or-redirect endpoint.
108114
res.redirect('/entrance/signup-sso-user-or-redirect'); // Note: This action handles signing in/up users who authenticate through Microsoft Entra.
109115
},
110-
'/logout': async(req, res)=>{
116+
'/logout': async(req, res, next)=>{
117+
if (!sails.config.custom.entraClientId) {
118+
return next();
119+
}
111120
let logoutUri = `https://login.microsoftonline.com/${sails.config.custom.entraTenantId}/oauth2/v2.0/logout?post_logout_redirect_uri=${sails.config.custom.baseUrl}/`;
112121
delete req.session.userId;
113122
res.redirect(logoutUri);

0 commit comments

Comments
 (0)