Skip to content

Latest commit

 

History

History
73 lines (56 loc) · 1.94 KB

File metadata and controls

73 lines (56 loc) · 1.94 KB

Description

Keycloak authentication extension (auth adapter) with predefined configuration and authorization policies requirements. It's simplify integration with auth service, all you needs it's just drop the installation keycloak client's file (keycloak.json) in root application folder.

Setup

Authentication

  1. Allow to application reads client installation file from the root directory
public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
                // New line 
                .UseKeycloak()
                .UseStartup<Startup>();
}
  1. Add Keycloak authentication functionality and authorization policies
public void ConfigureServices(IServiceCollection services)
{  
    // New line 
    services.AddKeycloakAuthentication();

    services.AddAuthorization(config => /* ... */);
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseAuthentication();
    app.UseAuthorization();
}
  1. Enjoy

Autosigning HttpClient

  1. Do first step from Authentication section
  2. Configure http client
public void ConfigureServices(IServiceCollection services)
{
    services.AddHttpClient<IMicroserviceFirst, MicroserviceFirst>()
            // new line
            .AddKeycloakSupport();
}
  1. Done. Just invoke IMicroserviceFirst whenever you want and don't think about auth tokens.

Features

  1. Authentication with autosetup through keycloak.json file
  2. HttpClient with auto obtaining and refreshing access_token
  3. Predefined authorization policy requirements
    3.1. ResourceAccess - allows to check roles from different resources

TODO

  • More predefined policy requirements
  • Importing Authorization configuration from Keycloak ([service-id]-authz-config.json)