Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 2.33 KB

README.md

File metadata and controls

65 lines (54 loc) · 2.33 KB

multi-idp-test

Purpose: Create a single backend for multiple idps.

Getting started

Open solution in VS2019 and hit F5.

What is does is:

Testing:

  • Login with username alice and password alice
  • Go to the privacy tab and check if you got a reply from the backend.

How is the solution setup

The solution is setup by following the guides below

https://identityserver4.readthedocs.io/en/latest/quickstarts/2_interactive_aspnetcore.html https://identityserver4.readthedocs.io/en/latest/quickstarts/1_client_credentials.html https://docs.microsoft.com/en-us/aspnet/core/security/authorization/limitingidentitybyscheme?view=aspnetcore-5.0

IMPORTANT: The solution is not setup using best practices

The trick for multiple idps is found in de api4both\startup.cs

  • Remove default scheme
  • Override the default policy and add all authentication schemas
            services.AddAuthentication() //remove default scheme here
               .AddJwtBearer("Bearer1", options =>
               {
                   options.Authority = "https://localhost:5051";

                   options.TokenValidationParameters = new TokenValidationParameters
                   {
                       ValidateAudience = true,
                       ValidAudience = "https://localhost:5051/resources"
                   };
               })
               .AddJwtBearer("Bearer2", options =>
               {
                   options.Authority = "https://localhost:5052";

                   options.TokenValidationParameters = new TokenValidationParameters
                   {
                       ValidateAudience = true,
                       ValidAudience = "https://localhost:5052/resources"
                   };
               });

            services.AddAuthorization(options =>
            {
                options.DefaultPolicy = new AuthorizationPolicyBuilder()
                            .AddAuthenticationSchemes("Bearer1", "Bearer2") //add all schemas here
                            .RequireAuthenticatedUser()
                            .Build();
            });
        }