I have just completed a new Client-side Blazor app with Server, using Azure B2C for auth.
Everything works perfectly on localhost, but when I published the server to a new Azure Web App, the login popup refers to the HTTP (not HTTPS) localhost URL (see image) and fails to find that page (of course). No idea why localhost is targeted, as the only reference to that URL is in the launchsettings.json
used for Visual Studio startup of the app.
I have search all project files and settings I can think of, but cannot find where the problem is. Yes, I have configured the B2C Authentication redirect URLs for the return trip to the Azure hosted server.
Any ideas? This is my first Azure deployment of a Blazor app, so it may just be something simple I am not aware of (yet).
Web redirect settings in Azure B2C below:
I also just inspected a local copy of the entire set of publish files and cannot find anything that refers to the localhost URL
After cleaning out unused App Registrations and their redirect URLs, I narrowed it down to this error being returned in the URL when running locally:
http://localhost/signin-oidc#error=redirect_uri_mismatch&error_description=AADB2C90006:+The+redirect+URI+'https://localhost:7164/authentication/login-callback'+provided+in+the+request+is+not+registered+for+the+client+id+'{xxxx}'.
After changing that redirect to authentication/login-callback
(it was /signin-oidc
) it still shows the same error, so there is definitely caching going on in the AzureB2C server.
From the deployed server the error is similar.
http://localhost/authentication/signin-oidc#error=redirect_uri_mismatch&error_description=AADB2C90006:+The+redirect+URI+'https://xxxxxx.azurewebsites.net/authentication/login-callback'+provided+in+the+request+is+not+registered+for+the+client+id+'{xxxx}'.
It appears to fallback to another redirect when the required redirect is missing. Maybe the last successful/cached one?
Another note. When you spin up a Blazor app with Azure B2C, it creates 2 separate App registrations. One for the server auth and one for the client auth. It may be the required for each are different endpoints, so any copying of "fixes" may keep breaking client or server, with caching obfuscating the problem. I will spin up a fresh templated Blazor app with Auth and record the exact URLs it creates in each AzureB2C App registration.
http://localhost:xxxx/authentication/login-callback
/signin-oidc
, but server side login is not actually used.Okay dokay. So after a huge amount of trial and experimentation, I have it working on the deployed website.
Effectively I did nothing but fix some redirect URLs and "wait for it to become active". Everything else was a red herring.
You could also solve this problem by creating a new App registration, configure all URLs in advance of use, and use that new ClientId from AzureB2C. Then there is no chance of caching.
It appears that AzureB2c caches return URLs and if any redirect URL is invalid, it seems to pick up the last valid one it used. I will add further details if it reoccurs.
Thanks to @Harshitha for their suggestions. Every little thing helps to focus on the problem.
So as part of my testing I removed all localhost
redirects from the App registration. When I added them back, to run it locally again, the immediate effect was a redirect to the previous Azure cloud version I successfully used! Definitely a caching/update issue.
After checking every 5 minutes, it appears there is a 30 minute delay before any new redirect URLs become active.