/AspireForIdentityServer

Sample solution for a basic Identity Server & Client using Aspire orchestration

Primary LanguageC#

.NET CodeQL

Important

This repo is for experimental and example use only and it not intended as a "best current practice" for production solution architecture. Solution structure, features, code style etc are all likely to change on the fly and may contain errors and/or unsupported preview/prerelease packages.

Solution Overview

This Aspire based project contains and manages:

  • SQL Server & Database (Persisted)
  • Redis Cache (Persisted)
  • Redis Insight (Preconfigured to the Redis Cache instance)
  • App Projects (IdentityServer, Client app, API Resource)

Customisations

  • Customised HostingExtensions.cs (provides new ConfigureServices(), InitializeDatabase() and ConfigurePipeline() methods).
  • Custom WebApplicationBuilder extensions to provide configuration of IdentityServer and Redis.
  • Cleaned up Config.cs into SeedConfig.cs to provider starter users and clients.
  • Added Redis and SQL Server resources to the Aspire AppHost project for use in the IdentityServer application.
  • Endpoint routing with MediatR. A customised instance of IdentityServer from Duende using version 7.1.0 configured to use SQL Server storage.
  • ASP.Net Identity with Two-Factor Authentication and Passkey support.
  • An MVC client application setup to use PAR (pushed authorisation requests) and configured to use Redis cache.
  • A protected API resource, also configured to use Redis for output caching.
  • Serilog integration in the above projects, output to console.
  • Samples using Endpoint routing & MediatR.
  • Sample unit tests using Moq & FluentAssertions.

Cloning and Building this project

Prerequisites

Before you start, make sure you have the following installed on your machine:

  • .NET 9 SDK: Download and install from the official .NET website.
  • IDE of Choice: Preferably Visual Studio for its robust support for .NET development. Alternatively, you can use Visual Studio Code or any other IDE that supports .NET.
  • Docker: Preferablly Docker Desktop or Rancher for ease of use, but any installation of Docker should work fine.

Planned Customisations

  • Additional account management features.
  • Additional client and API resources management.

The idea here is to create a simple, yet feature-rich, IdentityServer solution that can be used as a starting point for new projects.

Steps to Clone and Build the Project

Note

With the update to Aspire v9, the solution now makes use of the .WaitFor() helpers, ensuring that the Identity Server, Client and API projects wait for the containers to finish loading and enter a healthy state before loading. If you do not already have the latest version of the Redis and MSSQL container images, it will take longer for them to provision while the images are downloaded.

  1. Clone the Repository:

    Open a terminal or command prompt and run the following command to clone the repository:

    git clone https://github.com/StuFrankish/AspireForIdentityServer.git
    cd AspireForIdentityServer
  2. Restore the Dependencies:

    Navigate to the project directory and restore the dependencies using the .NET CLI:

    dotnet restore
  3. Build the Project:

    Build the project using the .NET CLI:

    dotnet build
  4. Run the Project:

    To run the project, use the following command:

    dotnet run

    The application will start and open the Aspire dashboard in your default browser, where you should see the projects listed as well as the SQL & Redis containers begin to provision.

Contributing

If you'd like to contribute to the project, feel free to fork the repository, make your changes, and create a pull request.

For any further questions or issues, please open an issue on the GitHub repository.

Repo Activity

Alt