@@ -78,7 +78,10 @@ module.exports = function (sails) {
78
78
79
79
routes : {
80
80
before : {
81
- '/login' : async ( req , res ) => {
81
+ '/login' : async ( req , res , next ) => {
82
+ if ( ! sails . config . custom . entraClientId ) {
83
+ return next ( ) ;
84
+ }
82
85
// Get the sso login url and redirect the user
83
86
// [?]: https://learn.microsoft.com/en-us/javascript/api/%40azure/msal-node/confidentialclientapplication?view=msal-js-latest#@azure-msal-node-confidentialclientapplication-getauthcodeurl
84
87
let entraAuthorizationUrl = await entraSSOClient . getAuthCodeUrl ( {
@@ -88,7 +91,10 @@ module.exports = function (sails) {
88
91
// Redirect the user to the SSO login url.
89
92
res . redirect ( entraAuthorizationUrl ) ;
90
93
} ,
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
+ }
92
98
// Make sure there is a code query string.
93
99
let codeToGetToken = req . query . code ;
94
100
if ( ! codeToGetToken ) {
@@ -107,7 +113,10 @@ module.exports = function (sails) {
107
113
// Redirect the user to the signup-sso-user-or-redirect endpoint.
108
114
res . redirect ( '/entrance/signup-sso-user-or-redirect' ) ; // Note: This action handles signing in/up users who authenticate through Microsoft Entra.
109
115
} ,
110
- '/logout' : async ( req , res ) => {
116
+ '/logout' : async ( req , res , next ) => {
117
+ if ( ! sails . config . custom . entraClientId ) {
118
+ return next ( ) ;
119
+ }
111
120
let logoutUri = `https://login.microsoftonline.com/${ sails . config . custom . entraTenantId } /oauth2/v2.0/logout?post_logout_redirect_uri=${ sails . config . custom . baseUrl } /` ;
112
121
delete req . session . userId ;
113
122
res . redirect ( logoutUri ) ;
0 commit comments