Skip to content

RolfDeVries/multi-idp-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();
            });
        }

About

Purpose: Create a single backend for multiple idps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published