Search code examples
c#authenticationasp.net-coreidentityserver4

Change Authority when using IdentityServerAuthentication


I use IdentityServerAuthentication:

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = "some_url";
                ...
            });

But my authorization server can change, and I`ll get the new configuration.

How can I change Authority during runtime?


Solution

  • I've decided my problem using IOptionsMonitorCache<IdentityServerAuthenticationOptions>. I call "Clear" method and then it call configuration code again in

                .AddIdentityServerAuthentication(options =>
            {
               // this code will be called again. I use setting provider here. 
            });