We are trying to configure 2 different Authorization Servers for one API application. However when we use the “Okta.AspNetCore” nuget package and try to register each Authorization Server we receive the following error: “Scheme already exists: Bearer”. We believe this is because we can’t name the scheme. Is there a way to configure 2 different Authorization Servers in .net core? Below is a code example of what I’m doing in the Startup.cs configuration.
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
.AddOktaWebApi(new OktaWebApiOptions { OktaDomain = $"{oktaConfig.Domain}", Audience = $"{oktaConfig.Audience}", AuthorizationServerId = $"{oktaConfig.AuthorizationServerId}" })
.AddOktaWebApi(new OktaWebApiOptions /Not sure how to change the scheme name here from bearer/
{ OktaDomain = $"{oktaConfig.Domain}",
Audience = $"{oktaConfig.MobileAudience}",
AuthorizationServerId = $"{oktaConfig.MobileAuthorizationServerId}" });
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.AddAuthenticationSchemes(“Bearer”)
.Build();
options.AddPolicy(“UpdatedPolicy”,
policy =>
{
policy.RequireAuthenticatedUser()
.AddAuthenticationSchemes(“Bearer”) /should we be able to reference a different scheme name here?/
.Build();
});
});