[Bug] 'Scheme already exists: Bearer' when trying to setup both AAD and AAD B2C auth
See original GitHub issueWhich version of Microsoft Identity Web are you using? 0.2.3-preview
Where is the issue?
I’m trying to make my ASP.NET Core Web API compatible with both AAD tokens issued on behalf of applications as well as AAD B2C tokens issued on behalf of users, but run into errors when trying to configure both entries in my appsettings.json file. If I only initialize AddMicrosoftWebApi
once, then I get issues verifying JWT signature when the token is generated using the identity provider that was left out.
Is this a new or an existing app? c. This is a new app
Repro
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftWebApi(this.Configuration, "AzureAd")
.AddMicrosoftWebApi(this.Configuration, "AzureAdB2C")
Expected behavior ASP.NET Core app is setup to validate tokens issued from both identity providers.
Actual behavior
Error during startup: InvalidOperationException: 'Scheme already exists: Bearer'
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:23 (7 by maintainers)
Top GitHub Comments
Thanks everyone for feedback. A fix is in PR #475 (which will be included in the next release). Also added a small section to the wiki related to this.
@AzureAD/azure-ad-app-content-authors
You added twice the same authentication scheme. You’d need to use a different name for the
jwtBearerScheme
parameter in one of your calls. for instance:BTW, the default one will be “Bearer” (JwtBearerDefaults.AuthenticationScheme).