Skip to content

[Bug] 'Scheme already exists: Bearer' when trying to setup both AAD and AAD B2C auth #429

@pheuter

Description

@pheuter

Which 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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions