Watch Aspire live streamsDocumentationEssayer Aspire

Get started with the Logto integrations

Ce contenu n’est pas encore disponible dans votre langue.

⭐ Community Toolkit

Logto is an identity platform that supports OpenID Connect (OIDC) sign-in and access-token authentication. The Aspire Community Toolkit provides a hosting integration to run Logto with PostgreSQL and a .NET client integration to configure ASP.NET Core authentication.

  • Model the identity server and its PostgreSQL dependency in the AppHost. The hosting integration supplies the database URL and waits for PostgreSQL.
  • Add Redis when Logto needs caching, and persist container data with volumes or bind mounts.
  • Check server readiness through Logto’s /api/status endpoint.
  • Pass the Logto endpoint to consuming apps through a resource reference instead of maintaining separate connection strings.
  • Configure browser sign-in and API token validation with the .NET client package.
flowchart LR
    AppHost["Aspire AppHost"] --> Logto["Logto container"]
    Logto --> PostgreSQL["PostgreSQL"]
    Logto -. Optional cache .-> Redis["Redis"]
    AppHost -- Connection information --> Web["Web app: OIDC sign-in"]
    AppHost -- Connection information --> API["API: JWT validation"]
    Web -- Sign-in redirect --> Logto
    API -- OIDC discovery and signing keys --> Logto

The hosting package creates a LogtoResource with a primary HTTP endpoint and an Admin Console endpoint. Referencing that resource supplies its primary endpoint to a consuming app. The client package configures authentication handlers; it doesn’t register a general-purpose Logto Management API client.

Application registration is separate from orchestration. Create a traditional web application in the Logto Admin Console for browser sign-in. For an API, register an API resource and use its identifier as the accepted token audience.

  • An Aspire development environment with a supported container runtime.
  • An AppHost and an ASP.NET Core web or API project to reference.
  • Access to the Logto Admin Console to register applications and API resources after startup.

Install 📦 CommunityToolkit.Aspire.Hosting.Logto in the AppHost:

Aspire CLI — Ajouter le package CommunityToolkit.Aspire.Hosting.Logto
aspire add communitytoolkit-logto

La CLI Aspire est interactive ; choisissez le résultat approprié lorsque demandé :

Aspire CLI — Exemple de sortie
Select an integration to add:
> communitytoolkit-logto (CommunityToolkit.Aspire.Hosting.Logto)
> Other results listed as selectable options...

The hosting package depends on the PostgreSQL and Redis hosting integrations. Its exported APIs support both TypeScript and C# AppHosts. After installing the package, regenerate the TypeScript AppHost bindings through the Aspire CLI before using the examples.

  1. Add PostgreSQL and Logto to the AppHost. Enable database seeding for this initial local setup:

    apphost.mts
    import { createBuilder } from './.aspire/modules/aspire.mjs';
    const builder = await createBuilder();
    const postgres = await builder.addPostgres('postgres');
    const logto = await builder.addLogto('logto', postgres);
    await logto.withDatabaseSeeding();
    const web = await builder.addProject('web', '../Web/Web.csproj');
    await web.withReference(logto);
    await web.waitFor(logto);
    await builder.build().run();

    Use the path or project type for your consuming project in place of Web.

  2. Run aspire run. Open the admin endpoint for the logto resource in the Aspire dashboard. Complete the Logto setup and create the application or API resource your consuming app needs.

  3. Configure the consuming app with AddLogtoOIDC("logto") for browser sign-in or AddLogtoJwtBearer("logto", ...) for API access-token validation. Follow the connection guide for required settings and complete .NET examples.

  • Logto hosting integration: configure ports, PostgreSQL, Redis, persistence, environment settings, and hosting health checks.
  • Logto client integration: consume connection properties, configure OIDC or JWT authentication, and connect from other languages.