question

MichaelVanderpool-7539 avatar image
2 Votes"
MichaelVanderpool-7539 asked JamesTran-MSFT edited

Azure AD B2C Always redirected to login

I have a new Blazor Server application in .Net 5.0. Using the setup wizard, I entered the necessary information to connect to a new Azure AD B2C , and created the project. I set up the Azure AD using the following document (as well as the additional steps in the nav bar):

https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant

For information that I followed during the setup of the Blazor project, I used these articles:

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/azure-ad-b2c?view=aspnetcore-5.0
https://medium.com/marcus-tee-anytime/azure-ad-b2c-quickstart-with-visual-studio-blazor-563efdff6fdd

With no additional changes to the project or the AD, I ran the Blazor project. Upon running the project, I am redirected to the login screen for the AD instead of the index page with the ability to login. Once logging in, everything works as expected (unless you log off). I verified there are no Authorized tags on the Blazor pages or components. What am I doing wrong?

Thanks,
Michael

azure-ad-msal
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ADefWebserver avatar image
1 Vote"
ADefWebserver answered MichaelVanderpool-7539 commented

Make sure you do not have .RequireAuthorization(); in your Startup.cs file.

In this Server-Side Blazor app: https://blazorsimplesurvey.azurewebsites.net/ you do not have to log in (unless you want to).
The code for the app is here: https://github.com/ADefWebserver/BlazorSimpleSurvey
You can compare that code to your own.

Also see: Blazor and Azure B2C: The Big Picture





· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Okay, so you definitely helped me get the answer! The answer was in the Startup.cs. This auto-generated code is the source of the issue, it seems:

services.AddAuthorization(options =>
{
// By default, all incoming requests will be authorized according to the default policy
options.FallbackPolicy = options.DefaultPolicy;
});

Commenting out the options for the policy resolves the issue, it would seem!

2 Votes 2 ·