'Microsoft auth doesn't redirect after successful login

I am integrating Microsoft's login using Django Microsoft Authentication Backend. I have managed to to get a successful response and create a new "Microsoft" user and am able to see it in the admin site if I login to the admin site as a local superuser.

enter image description here

enter image description here

When I login using Microsoft, the pop up window to Microsoft opens, authenticates, and it doesn't redirect to anywhere. enter image description here

But, with a local non-Microsoft user, it can successfully redirects to the admin panel.

enter image description here

I don't understand why this is so, it doesn't make sense. I have a frontpage constructed that I would like this login page to redirect to after successful login. I have included

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'

in the settings.py file but that does not change anything.



Solution 1:[1]

Real weird when trying to use Microsoft authentication with localhost. I installed ngrok, added the ngrok https URL as callback URL in Azure AD, added ngrok URL to ALLOWED_HOSTS in settings.py then tried logging in through admin page, it logs in to admin panel fine now.

To use redirects, I added a "Sign in with Microsoft" image in the default login.html page that django's default authentication provides. That then redirects to "/microsoft/to-auth-redirect/". To make use of this, the callback URL in Azure AD must be "/microsoft/from-auth-redirect/". Now you can make use of LOGIN_REDIRECT_URL and LOGOUT_REDIRECT_URL in settings.py.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Subhaac