Base solution for your next web application
Open Closed

How can we set multiple authority for identity server 4 #11168


0
shedspotter created

What is your product version? 11.0.0

What is your product type (Angular or MVC)? Angular

What is product framework type (.net framework or .net core)? .NET 6

Hi, How can we set multiple authority for identity server 4 ?

Thanks


3 Answer(s)
  • 0
    m.aliozkaya created
    Support Team

    Hi @shedspotter

    Can you try following steps?

    Edit the relevant code in the AuthConfigurer class in the Startup folder as below:

    if (bool.Parse(configuration["IdentityServer:IsEnabled"]))
    {
        IdentityModelEventSource.ShowPII = true;
    
        // authenticationBuilder.AddIdentityServerAuthentication("IdentityBearer", options =>
        // {
        //     options.Authority = configuration["IdentityServer:Authority"];
        //     options.ApiName = configuration["IdentityServer:ApiName"];
        //     options.ApiSecret = configuration["IdentityServer:ApiSecret"];
        //     options.RequireHttpsMetadata = false;
        // });
    
        authenticationBuilder.AddJwtBearer(options =>
        {
            options.Authority = configuration["IdentityServer:Authority"];
            options.RequireHttpsMetadata = false;
            options.Audience = configuration["Authentication:JwtBearer:Audience"];
            options.TokenValidationParameters.ValidIssuers = configuration.GetSection("Authentication:JwtBearer:ValidIssuers").Get<string[]>();
            options.SecurityTokenValidators.Clear();
            options.SecurityTokenValidators.Add(new JwtSecurityTokenHandler
            {
                MapInboundClaims = false
            });
            options.TokenValidationParameters.NameClaimType = "name";
            options.TokenValidationParameters.RoleClaimType = "role";
        });
    }
    

    Go to app settings and ValidIssuers like this:

    "JwtBearer": {
      "IsEnabled": "true",
      "SecurityKey": "AbpZeroTemplate_8CFB2EC534E14D56",
      "Issuer": "AbpZeroTemplate",
      "Audience": "AbpZeroTemplate",
      "ValidIssuers": [
        "https://localhost:44301/",
        "https://localhost:44302/"
      ]
    }
    
  • 0
    shedspotter created

    Hi Krai, I have applied the same way as you applied

    But I am getting below when I am running the project locally

  • 0
    m.aliozkaya created
    Support Team

    Could you update this line like this authenticationBuilder.AddJwtBearer("IdentityBearer", options =>