Patrick
Patrick

Reputation: 5846

Azure AD redirects to wrong location (localhost) after authentication

I have code working in development that authorizes against Azure AD in a multi-tenant setup using the MSAL library (with the Microsoft Angular wrapper for MSAL).

This code all works as expected when I am running it against localhost:5001.

My configuration contains a redirectUri for https://localhost:5001 and my application in Azure AD has its "Redirect URI" value set to the same.

However, when I move this to production, it is continuing to try to redirect me to localhost:5001 on a successful AD authentication, even though I have changed my redirectUri in my configuration, as well as the Azure B2C application "Redirect URI", to now be the production site at:

https://[mysite].azurewebsites.net

Where is it still getting localhost:5001 from? I searched my code/configuration and this value does not exist. It is not currently in Azure AD for the Application. I have stopped and restarted my App Service to no avail.

The redirection it is trying to make is to:

https://localhost:5001/#id_token=eyJ0eXAiOiJKV1Qi ...

Upvotes: 4

Views: 6076

Answers (3)

Akbar
Akbar

Reputation: 81

No need to delete and register a new application. Simply update the replyUrlsWithType attribute on the Azure Active Directory app manifest file to point to the new domain, url or location:

"replyUrlsWithType": [
   {
      "url": "https://localhost:4400/services/office365/redirectTarget.html",
      "type": "InstalledClient"
   }
],

See this link for more information: https://learn.microsoft.com/en-gb/azure/active-directory/develop/reference-app-manifest?WT.mc_id=Portal-Microsoft_AAD_RegisteredApps

Upvotes: 1

Patrick
Patrick

Reputation: 5846

I was able to work around this issue by deleting the Azure AD App Registration and creating a new one from scratch with the proper endpoints.

For some reason, it was not "holding" the change when the endpoint URLs were edited and saved. It showed the correct endpoints in the Azure AD control panel for the App Registration, but it was still redirecting to localhost.

When I deleted and re-created, it properly forwarded the replies to the production site.

I am unsure at this time if this is an issue on Microsoft's side or not, but this conclusively resolved the issue.

Upvotes: 4

Tony Ju
Tony Ju

Reputation: 15619

Registering a new application solved this issue.

Upvotes: 0

Related Questions