Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddMicrosoftIdentityWebApi ignores missing configuration #3001

Open
andreas-valtech opened this issue Aug 30, 2024 · 0 comments
Open

AddMicrosoftIdentityWebApi ignores missing configuration #3001

andreas-valtech opened this issue Aug 30, 2024 · 0 comments

Comments

@andreas-valtech
Copy link

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

3.0.1

Web app

Sign-in users and call web APIs

Web API

Protected web APIs call downstream web APIs

Token cache serialization

In-memory caches

Description

When using the AddMicrosoftIdentityWebApi with the following code:

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(configuration, "AzureAdB2C", JwtBearerDefaults.AuthenticationScheme, false)
                .EnableTokenAcquisitionToCallDownstreamApi();

The call succeeds even if the config section is empty. We are using dotnet user-secrets and had not added a "AzureAdB2C" section in one of our developers secrets stores. The result was a misbehaving app since authentication was not setup but no other error happened right away.

Reproduction steps

  1. Add a new mvc app with dotnet new mvc -n ExampleApp
  2. Add the package Microsoft.Identity.Web 3.0.1
  3. Add the following to the Porgram.cs:
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(builder.Configuration, "AzureAdB2C", JwtBearerDefaults.AuthenticationScheme, false)
    .EnableTokenAcquisitionToCallDownstreamApi()
    .AddInMemoryTokenCaches();

and run the application. No Exception is thrown even though no configuration section for "AzureAdB2C" exists.

Error message

No response

Id Web logs

No response

Relevant code snippets

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(builder.Configuration, "AzureAdB2C", JwtBearerDefaults.AuthenticationScheme, false)
    .EnableTokenAcquisitionToCallDownstreamApi()
    .AddInMemoryTokenCaches();

Regression

No response

Expected behavior

When the "AzureAdB2C" section is missing it should crash with an exception right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant