Duende Software Samples

repository·main·Indexed 42 days ago

https://github.com/duendesoftware/samples

A collection of sample projects demonstrating the usage of Duende Software products across various frontend frameworks, including Angular, React, and Vue. Includes implementation guides for BFF v2 and v3, Docker HTTPS certificate setup, and integration examples.

Tokens
41.2K
Snippets
135
Records
211
Agent score
51%

What's inside Duende Software Samples

  1. Overview of the MCP Sample

    main
    The MCP Sample demonstrates a workflow where a console client uses Dynamic Client Registration (DCR) to register itself with IdentityServer at runtime. Once registered, the client can make authorized calls to a locally hosted MCP Server. This sample is designed to showcase how IdentityServer integrates with the Model Context Protocol (MCP) ecosystem.
  2. Use the Sample IdentityServer as a shared token service

    main
    The IdentityServerHost instance serves as a centralized token service shared across all samples in this repository. Developers can use this instance to obtain tokens required for testing and running various client samples (such as Angular, React, or Vue clients) without needing to configure a local IdentityServer instance for every individual sample.
  3. Use the authorization_code grant type in an MVC Client

    main

    This sample demonstrates how to implement an ASP.NET Core MVC client using the authorization_code grant type, which is the standard for interactive web applications.

    Key capabilities demonstrated include:

    • Configuring an MVC client to integrate with IdentityServer.
    • Accessing access tokens within the ASP.NET Core authentication session.
    • Making secure calls to a Web API using the retrieved tokens.
    • Manually performing token refreshes.
  4. MVC Client with Back-Channel Logout Notifications sample

    main

    This sample demonstrates how to implement back-channel logout notifications in an ASP.NET Core MVC client. It specifically covers:

    • Implementing a dedicated back-channel notification endpoint to receive logout requests from IdentityServer.
    • Leveraging events on the cookie handler (specifically OnValidatePrincipal) to invalidate the local user session when a logout notification is received.
  5. MVC Client with JAR and JWT-based Authentication sample overview

    main

    This sample demonstrates how to implement an ASP.NET Core MVC client that utilizes JWT Profile for Client Authentication (JAR) and JWT-based authentication.

    Key capabilities demonstrated include:

    • Implementing signed authorize requests using ASP.NET Core extensibility points.
    • Using JWT-based authentication to enable automatic token management.
    • Configuring IdentityServer clients to share key material across both front-channel and back-channel communications.
  6. Architecture of the SAML 2.0 IdP-Initiated Sample

    main

    The solution uses .NET Aspire to orchestrate three main components:

    1. IdentityServerHost: Acts as the SAML 2.0 IdP. It uses AllowIdpInitiated = true for registered SPs and features a custom Razor Page "My Apps" portal. This portal uses IIdpInitiatedSsoService to trigger the SSO flow.
    2. ServiceProvider: An ASP.NET Core Razor Pages application using Sustainsys.Saml2.AspNetCore2. It is configured via environment variables for entity ID, base URL, display name, and signing certificate. The sample runs two distinct instances: "HR Portal" and "Expense Tracker".
    3. IdPInitiated.AppHost: The .NET Aspire orchestrator. It manages the lifecycle of the services and handles security by generating ephemeral self-signed certificates for each SP and passing the public keys to the IdP for signature validation.
  7. Use the React + Vite template

    main

    This template provides a minimal setup for running React applications using Vite. It includes support for Hot Module Replacement (HMR) and pre-configured ESLint rules.

    There are two official plugin options available for the build process:

    1. @vitejs/plugin-react: Uses Babel for Fast Refresh.
    2. @vitejs/plugin-react-swc: Uses SWC for Fast Refresh (typically faster compilation).",
  8. Understand the types of Sample APIs available

    main

    The sample repository provides two distinct types of APIs to demonstrate different security scenarios with Duende IdentityServer:

    1. SimpleApi: A basic API used by most samples. It is designed to accept any valid token issued by the sample IdentityServer. It typically includes an IdentityController that echoes back the claims contained within the token to the client for verification.

    2. ResourceBasedApi: A more advanced API that implements the ApiResource concept from Duende IdentityServer. This API is used to demonstrate advanced security features such as:

      • Audience Validation: Ensuring the token was intended for this specific API.
      • Token Introspection: Validating the token against the IdentityServer to check its current status and metadata.
  9. Access Duende Software product samples

    main
    You can find detailed descriptions and guidance for various product samples on the official Duende documentation site. For samples related to older versions of Duende products, refer to the GitHub archive.
  10. How Space Resolution works in Duende Spaces

    main

    Duende Spaces allows running multiple isolated IdentityServer instances within a single ASP.NET Core host. Space resolution is handled early in the middleware pipeline using app.UseSpacesResolution().

    Important: app.UseSpacesResolution() must be called before app.UseIdentityServer() to ensure all IdentityServer operations (configuration, user lookups, etc.) occur within the correct space context.

    Resolution Strategies

    1. Host-based (Origin) Resolution: The request origin (hostname) is matched against configured SpaceMatchPattern.Origin values. This is the highest priority.
    2. Path-based Resolution: Requests following a specific path pattern (e.g., /t/{space-path}) are matched, and the path is rewritten for downstream routing.
    3. Default/Fallback: If no host or path matches, the system resolves to a default space. This is useful for scenarios where multiple issuers share the same configuration data.

    Note: If a request matches both an origin pattern and a path pattern (e.g., https://space1.dev.localhost:5000/t/space3), the origin-based routing takes precedence, and the path-based space will not be selected (resulting in a 404 if the origin space doesn't match the path).

  11. Coordinate client refresh tokens with user sessions

    main

    You can configure a client to automatically extend a user's server-side session whenever a refresh token is used. This is done by enabling CoordinateLifetimeWithUserSession in the client configuration (typically found in Clients.cs).

    When this is enabled, as the client application refreshes its access token, the user's server-side session expiration is automatically extended.

    // In Clients.cs
    new Client
    {
        // ... other client settings
        CoordinateLifetimeWithUserSession = true
    };
  12. Coordinate refresh token lifetime with user session

    main

    You can configure a client to automatically extend a user's server-side session whenever a refresh token is used. This is achieved by setting CoordinateLifetimeWithUserSession to true in the client configuration (found in Clients.cs in this sample).

    When this is enabled, as the client application refreshes its access token, the user's server-side session expiration is automatically extended.

    // In Clients.cs
    new Client
    {
        // ... other settings
        CoordinateLifetimeWithUserSession = true
    };