dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.44k stars 25.32k forks source link

Possibility of incomplete code snippet regarding .AddAuthentication() #30034

Open euhm opened 11 months ago

euhm commented 11 months ago

Hello,

in the sample azure-ad-b2c/sample/Program.cs you have the following code which didn't work in my scenario.

.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)

needed to be replaced with

.AddAuthentication(options => { options.DefaultAuthenticateScheme = OpenIdConnectDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }

Is the snippet incomplete or did I miss something on my end?

Kind regards,

bob


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Rick-Anderson commented 11 months ago

cc @damienbod @CamSoper

damienbod commented 11 months ago

Hi @euhm

The code snippet is part of the setup used in the configure services block, depending on how you do this. Have you set this up like in the docs (step 5)?

Kind regards Damien

euhm commented 9 months ago

Hello,

apologies for the late reply.

I indeed set it up as in step 5. But I assume the sample code 'conflicts' with other authentication configurations. ADB2C setup is done in a codebase from a CMS. The cms also configures authentication.

services.AddAuthentication(options => { options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; })

where IdentityConstants.ApplicationScheme = Identity.Application (AspNetCore Identity as well)

I resolved the issue using a policy scheme to use the correct scheme during runtime. I don't know if it can help to mention something in the docs, or if its overkill.

Thanks,

bob