Get started with the Logto integrations
此内容尚不支持你的语言。
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.
Why use Logto with Aspire
Section titled “Why use Logto with Aspire”- 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/statusendpoint. - 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.
How the pieces fit together
Section titled “How the pieces fit together”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.
Prerequisites
Section titled “Prerequisites”- 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.
Set up a local Logto instance
Section titled “Set up a local Logto instance”Install 📦 CommunityToolkit.Aspire.Hosting.Logto in the AppHost:
aspire add communitytoolkit-logtoAspire CLI 是交互式的;按提示选择合适的搜索结果:
Select an integration to add:
> communitytoolkit-logto (CommunityToolkit.Aspire.Hosting.Logto)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.Logto@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.Logto" Version="*" />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.
-
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();AppHost.cs var builder = DistributedApplication.CreateBuilder(args);var postgres = builder.AddPostgres("postgres");var logto = builder.AddLogto("logto", postgres).WithDatabaseSeeding();builder.AddProject<Projects.Web>("web").WithReference(logto).WaitFor(logto);// After adding all resources, run the app...builder.Build().Run();Use the path or project type for your consuming project in place of
Web. -
Run
aspire run. Open theadminendpoint for thelogtoresource in the Aspire dashboard. Complete the Logto setup and create the application or API resource your consuming app needs. -
Configure the consuming app with
AddLogtoOIDC("logto")for browser sign-in orAddLogtoJwtBearer("logto", ...)for API access-token validation. Follow the connection guide for required settings and complete .NET examples.
Choose a flow
Section titled “Choose a flow”- 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.