Search code examples
reactjsazure.net-coreazure-active-directory.net-core-2.1

.Net Core SPA and React - HTTP 400 after Active Directory Login


I had a problem on my machine with .Net Core SPA on React with Azure Active Directory Authentication. This happen only on my computer. On other devs machine it works.

The application has been started by using stardard template like here: https://learn.microsoft.com/en-us/aspnet/core/client-side/spa/react?view=aspnetcore-2.2&tabs=visual-studio

The thing is when I'm starting it in development mode so I'm using dev server with instruction:

spa.UseReactDevelopmentServer(npmScript: "start")

After redirection to Active Directory login in Azure and doing it successfully and then getting back to my localhost address I'm receiving HTTP 400 error.

The problem only occurs when using dev server. With normal package build with npm build and not starting the dev server application works fine and I don't get HTTP 400.

So it seems like dev server hadn't been able to load package to its memory beacuse something went wrong and don't see that and it is not able to resolve default document like index.html

I don't know if that information can be useful but sometimes trying to access on http://localhost with simple app (for example standard CRA app) also returns me 400 but always cleaning cookies helps.

For me it seems like this is something with SpaServices from .NET core or I've got something screwed with cookies in Chrome.

Version of .NET Core: 2.1.1

Any solution where the problem can be located because I tried many solution and I ran out of ideas ?

Thing which I tried and didn't help:

  1. Cleaning the whole cookies, cache, storage in Chrome
  2. Incognito mode
  3. Using http://127.0.0.1 or corporate network address
  4. Trying different browser
  5. Reinstalling whole VS

Solution

  • Ok, problem solved.

    The issue was somehow nodejs installation. Before installing Visual Studio I had already installed nodejs. I removed the whole nodejs installation and reinstall it again.

    Also I don't know if that was a problem or coincidence but previosly nodejs had been installed on D: drive. Now I installed on C: drive so on the same where I have Visual Studio.

    Hope that will help people who will encounter the same problem like I :)