Skoruba.IdentityServer4.Admin

repository·master·Indexed 25 days ago

https://github.com/skoruba/identityserver4.admin

An administration UI for managing IdentityServer4 and ASP.NET Core Identity. It provides a web interface to manage clients, API resources, identity resources, users, and roles. The system supports SqlServer, MySql, and PostgreSQL, and includes a dotnet template for project scaffolding, Docker Compose support, and integration with Azure Key Vault.

Tokens
7.6K
Snippets
29
Records
47
Agent score
86%

What's inside Skoruba.IdentityServer4.Admin

  1. Generate a PFX certificate for signing tokens

    master

    If you do not have a certificate for signing tokens, you can generate a .pfx file using OpenSSL.

    On Windows, you can install OpenSSL via Chocolatey:

    choco install openssl.light

    Then, run the following commands to generate the certificate files:

    openssl genrsa 2048 > private.pem
    openssl req -x509 -new -key private.pem -out public.pem
    openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx

    Note: Remember the password used during the export process, as it will be required later.

  2. Install client libraries and manage assets

    master

    The project uses npm for client libraries and Gulp for asset bundling.

    Install Libraries:

    cd src/Skoruba.IdentityServer4.Admin
    npm install
    
    cd src/Skoruba.IdentityServer4.STS.Identity
    npm install

    Gulp Tasks:

    • gulp fonts: copy fonts to dist folder
    • gulp styles: minify CSS, compile SASS to CSS
    • gulp scripts: bundle and minify JS
    • gulp clean: remove dist folder
    • gulp build: run styles and scripts tasks
    • gulp watch: watch all changes in SASS files
  3. Configure authentication for the Admin UI

    master

    Use the AddAuthenticationServices helper method in Startup.cs to register authentication. The Admin UI uses OpenIdConnect middleware connected to IdentityServer4.

    Note: In staging environments, cookie middleware is used for fake authentication. The fake login URL is /Account/Login.

    services.AddAuthenticationServices<AdminIdentityDbContext, UserIdentity, UserIdentityRole>(HostingEnvironment, rootConfiguration.AdminConfiguration);
  4. Install .NET Core 3.1 SDK on Ubuntu 19.04

    master

    To install the .NET Core 3.1 SDK on Ubuntu 19.04, register the Microsoft package repository and use apt-get to install the SDK.

    wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    
    sudo apt-get update
    sudo apt-get install apt-transport-https
    sudo apt-get update
    sudo apt-get install dotnet-sdk-3.1
  5. Configure DbContexts for the Admin UI

    master

    In the Skoruba.IdentityServer4.Admin project, use the AddDbContexts helper method within Startup.cs (inside ConfigureServices) to register the required DbContexts for the administration system.

    The following DbContexts are used:

    • AdminIdentityDbContext: For Asp.Net Core Identity.
    • AdminLogDbContext: For logging.
    • IdentityServerConfigurationDbContext: For the IdentityServer configuration store.
    • IdentityServerPersistedGrantDbContext: For the IdentityServer operational store.
    services.AddDbContexts<AdminIdentityDbContext, IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext>(HostingEnvironment, Configuration);
  6. Install the Skoruba.IdentityServer4.Admin template

    master

    Install the dotnet new template to create new projects using the Skoruba administration scaffolding. Note that version 2.0.0 and higher is compatible with IdentityServer4 version 4.

    Warning: This version affects your database data if you use the default migrations. Ensure you have a database backup before proceeding.

    dotnet new -i Skoruba.IdentityServer4.Admin.Templates::2.1.0
  7. Configure Localization and MVC in the Admin UI

    master

    Register MVC and Localization using the AddMvcWithLocalization extension method. This method uses the same types as the Asp.Net Core Identity registration because these types are injected into generic Controllers.

    services.AddMvcWithLocalization<UserDto<string>, string, RoleDto<string>, string, string, string,
                    UserIdentity, UserIdentityRole, string, UserIdentityUserClaim, UserIdentityUserRole,
                    UserIdentityUserLogin, UserIdentityRoleClaim, UserIdentityUserToken,
                    UsersDto<UserDto<string>, string>, RolesDto<RoleDto<string>, string>, UserRolesDto<RoleDto<string>, string, string>,
                    UserClaimsDto<string>, UserProviderDto<string>, UserProvidersDto<string>, UserChangePasswordDto<string>,
                    RoleClaimsDto<string>>();
  8. Configure Asp.Net Core Identity in the Admin UI

    master

    Use the AddAdminAspNetIdentityServices extension method to register all dependencies for managing Asp.Net Core Identity data.

    This is the recommended location to modify the Identity model, such as changing the primary key type from string to another type.

    services.AddAdminAspNetIdentityServices<AdminIdentityDbContext, IdentityServerPersistedGrantDbContext, UserDto<string>, string, RoleDto<string>, string, string, string,
                                    UserIdentity, UserIdentityRole, string, UserIdentityUserClaim, UserIdentityUserRole,
                                    UserIdentityUserLogin, UserIdentityRoleClaim, UserIdentityUserToken,
                                    UsersDto<UserDto<string>, string>, RolesDto<RoleDto<string>, string>, UserRolesDto<RoleDto<string>, string, string>,
                                    UserClaimsDto<string>, UserProviderDto<string>, UserProvidersDto<string>, UserChangePasswordDto<string>,
                                    RoleClaimsDto<string>, UserClaimDto<string>, RoleClaimDto<string>>();