Update AddMicrosoftIdentityWebApp without restarting application

Amit Singh Rawat 731 Reputation points
2024-09-01T18:27:16.7933333+00:00

I have used AddMicrosoftIdentityWebApp in my program.cs class for Microsoft Authentication.

builder.Services.AddAuthentication(opts =>
{
    opts.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    opts.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddMicrosoftIdentityWebApp(opts =>
{
    var azureOptions = builder.Services.BuildServiceProvider().GetRequiredService<IOptionsMonitor<AzureAppOptions>>().CurrentValue;

    opts.Instance = azureOptions.Instance;
    opts.TenantId = azureOptions.TenantId;
    opts.ClientId = azureOptions.ClientId;
    opts.CallbackPath = azureOptions.CallbackPath;
}, openIdConnectScheme: OpenIdConnectDefaults.AuthenticationScheme);

If I have to update Azure App details then, I have to restart my application because AddMicrosoftIdentityWebApp only runs at start up.

Is it possible to modify AddMicrosoftIdentityWebApp so that it start using new app details without restarting the application.

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
276 questions
Developer technologies | ASP.NET | ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,236 Reputation points Volunteer Moderator
    2024-09-03T18:34:34.3433333+00:00

    if you review the source:

    https://github.com/AzureAD/microsoft-identity-web/blob/c8ba0ce096f103baab417bac7fb2e9a40582a7af/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs#L43

    you will see it does not directly support configuration reload. you may be able to add a sentinel key, and manually update the injected authentication options on key change.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.