Duende Software Samples
repository·main·Indexed 42 days ago
https://github.com/duendesoftware/samplesA 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.
What's inside Duende Software Samples
- 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.
Use the Sample IdentityServer as a shared token service
mainTheIdentityServerHostinstance 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.Use the authorization_code grant type in an MVC Client
mainThis sample demonstrates how to implement an ASP.NET Core MVC client using the
authorization_codegrant 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.
MVC Client with Back-Channel Logout Notifications sample
mainThis 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.
MVC Client with JAR and JWT-based Authentication sample overview
mainThis 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.
Architecture of the SAML 2.0 IdP-Initiated Sample
mainThe solution uses .NET Aspire to orchestrate three main components:
- IdentityServerHost: Acts as the SAML 2.0 IdP. It uses
AllowIdpInitiated = truefor registered SPs and features a custom Razor Page "My Apps" portal. This portal usesIIdpInitiatedSsoServiceto trigger the SSO flow. - ServiceProvider: An ASP.NET Core Razor Pages application using
Sustainsys.Saml2.AspNetCore2. It is configured via environment variables forentity ID,base URL,display name, andsigning certificate. The sample runs two distinct instances: "HR Portal" and "Expense Tracker". - 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.
- IdentityServerHost: Acts as the SAML 2.0 IdP. It uses
Use the React + Vite template
mainThis 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:
@vitejs/plugin-react: Uses Babel for Fast Refresh.@vitejs/plugin-react-swc: Uses SWC for Fast Refresh (typically faster compilation).",
Understand the types of Sample APIs available
mainThe sample repository provides two distinct types of APIs to demonstrate different security scenarios with Duende IdentityServer:
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
IdentityControllerthat echoes back the claims contained within the token to the client for verification.ResourceBasedApi: A more advanced API that implements the
ApiResourceconcept 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.
Access Duende Software product samples
mainYou 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.How Space Resolution works in Duende Spaces
mainDuende 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 beforeapp.UseIdentityServer()to ensure all IdentityServer operations (configuration, user lookups, etc.) occur within the correct space context.Resolution Strategies
- Host-based (Origin) Resolution: The request origin (hostname) is matched against configured
SpaceMatchPattern.Originvalues. This is the highest priority. - Path-based Resolution: Requests following a specific path pattern (e.g.,
/t/{space-path}) are matched, and the path is rewritten for downstream routing. - 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).- Host-based (Origin) Resolution: The request origin (hostname) is matched against configured
Coordinate client refresh tokens with user sessions
mainYou can configure a client to automatically extend a user's server-side session whenever a refresh token is used. This is done by enabling
CoordinateLifetimeWithUserSessionin the client configuration (typically found inClients.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 };Coordinate refresh token lifetime with user session
mainYou can configure a client to automatically extend a user's server-side session whenever a refresh token is used. This is achieved by setting
CoordinateLifetimeWithUserSessiontotruein the client configuration (found inClients.csin 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 };