We are using passport-azure-ad
to allow users in our domain to log into an internal node app with their Microsoft AD credentials. I had this system working previously with just 1 node app, but now we are trying a new system where we have 2 separate apps running locally with PM2 and serving them up through IIS under the same URL but you access each app like this:
mywebsite.com/app1 OR mywebsite.com/app2
Only the second app needs authentication. The issue I am running into is when you hit login, the passport.authenticate
method seems to be trying to redirect to a relative authorization link:
mywebsite.com/{tenant}/oauth2/v2.0/authorize
, rather than the actual authorization endpoint which is:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
Does anyone know why this may be and what I could do to stop passport from treating the auth endpoint like a relative link? This causes a 404 every time a user hits /login because /{tenant}/oauth2/v2.0/authorize route doesn't exist.
RIP to anyone finding this in the future.
For me, the solution was as follows:
app.use(express.urlencoded({ extended: true }));
, as well as updating the redirect URLs in your authentication routes. Azure will also need to know your redirect URIs.