Repository navigation
Logto #1241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Logto #1241
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
cd63a59
Add Logto with PostgreSQL and Redis integration (#815)
axies20 0daa9ae
Add Logto client hosting support (#817)
axies20 34b16e2
Add Logto Client API example project
axies20 9c725dd
Add tests and enhancements for Logto Client integration
axies20 60f73e9
Refactor Logto client integration
axies20 8a0f9de
Remove unused `/signout` route from ClientApi example
axies20 95d01da
Rename `ClientApi` example to `ClientOIDC` and update method signatures
axies20 541111c
Add `ClientJWT` example with Logto JWT authentication support
axies20 bc8b00c
Merge branch 'main' into Logto
axies20 d4378b3
Update examples/logto/CommunityToolkit.Aspire.Hosting.Logto.AppHost/C…
axies20 4557bf8
Update src/CommunityToolkit.Aspire.Hosting.Logto.Client/CommunityTool…
axies20 0e3f42c
Merge branch 'main' into Logto
axies20 3976aec
Remove unused package references and resolve merge conflict in projec…
axies20 6685b60
Update package versions and project SDKs for Logto client integration
axies20 cde0cbd
Update `ClientJWT` example to use a constant for API audience in Logt…
axies20 d271f0a
Remove `<IsPreview>` property from Logto project
axies20 f282231
Rename `Hosting.Logto.Client` to `Logto.Client` and adjust related re…
axies20 a2e300c
Add `WithDeprecationTracing` method to enable Node.js deprecation tra…
axies20 97ce6d6
Merge branch 'main' into Logto
axies20 63356b8
Add `Hosting.Logto.Tests` and `Logto.Client.Tests` to test matrix in …
axies20 20f300b
Refactor Logto configuration: introduce validation for Logto options …
axies20 cbd16a8
Refactor `AppHostTest` to use `AspireIntegrationTestFixture`; add `Ap…
axies20 907c4d5
Allow null `port` and `adminPort` in `WithResourcePort` to enable ran…
axies20 bac366e
Update Logto container tag to v1.38
axies20 95c6f2c
Refactor `LogtoContainerResource` to `LogtoResource` and update relat…
axies20 231ae98
Set default HTTP and admin ports in `WithResourcePort` method of `Log…
axies20 6bfd3ca
Merge branch 'main' into Logto
axies20 9aa53f9
Merge branch 'main' into Logto
aaronpowell dcbb327
Merge branch 'main' into Logto
aaronpowell 99a5a14
Merge branch 'main' into Logto
aaronpowell 3b00722
Merge branch 'main' into Logto
axies20 d67f854
Update examples/logto/CommunityToolkit.Aspire.Hosting.Logto.AppHost/C…
aaronpowell 614b9e9
Merge branch 'main' into Logto
axies20 6311c8b
Add Logto integration: introduce `LogtoResource` and client builders …
axies20 6be30bf
Merge branch 'main' into Logto
aaronpowell dcd379e
Merge branch 'main' into Logto
aaronpowell 98603e5
Apply suggestion from @aaronpowell
aaronpowell dc8e10c
Fixing build errors
aaronpowell c7eb02e
Fix Logto test startup
aaronpowell f4476a6
not using persisted db
aaronpowell 0284f21
Testing a better endpoint
aaronpowell 1c631eb
deleting the generated files
aaronpowell ec3e661
Adding missing README.md
aaronpowell cf368fc
Merge branch 'Logto' of https://github.com/axies20/CommunityToolkit.A…
aaronpowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
examples/logto/CommunityToolkit.Aspire.Hosting.Logto.AppHost/AppHost.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using CommunityToolkit.Aspire.Hosting.Logto; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var postgres = builder.AddPostgres("postgres") | ||
| .WithDataVolume(); | ||
|
|
||
| var cache = builder.AddRedis("redis") | ||
| .WithDataVolume(); | ||
|
|
||
| var logto = builder.AddLogto("logto", postgres) | ||
| .WithRedis(cache); | ||
|
|
||
|
|
||
| var clientOIDC = builder.AddProject<Projects.CommunityToolkit_Aspire_Logto_ClientOIDC>("clientOIDC") | ||
| .WithReference(logto) | ||
| .WaitFor(logto); | ||
| var clientJWT = builder.AddProject<Projects.CommunityToolkit_Aspire_Logto_ClientJWT>("clientJWT") | ||
| .WithReference(logto) | ||
| .WaitFor(logto); | ||
|
|
||
|
|
||
| builder.Build().Run(); |
21 changes: 21 additions & 0 deletions
21
...Toolkit.Aspire.Hosting.Logto.AppHost/CommunityToolkit.Aspire.Hosting.Logto.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.2.0"> | ||
|
aaronpowell marked this conversation as resolved.
Outdated
|
||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Logto\CommunityToolkit.Aspire.Hosting.Logto.csproj" | ||
| IsAspireProjectResource="false" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Logto.ClientJWT\CommunityToolkit.Aspire.Logto.ClientJWT.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Logto.ClientOIDC\CommunityToolkit.Aspire.Logto.ClientOIDC.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.PostgreSQL" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
31 changes: 31 additions & 0 deletions
31
examples/logto/CommunityToolkit.Aspire.Hosting.Logto.AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17139;http://localhost:15140", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21242", | ||
| "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23087", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22172" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15140", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19078", | ||
| "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18181", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20004" | ||
| } | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
examples/logto/CommunityToolkit.Aspire.Hosting.Logto.AppHost/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...osting.Logto.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App"/> | ||
|
|
||
| <PackageReference Include="Microsoft.Extensions.Http.Resilience"/> | ||
| <PackageReference Include="Microsoft.Extensions.ServiceDiscovery" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol"/> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Runtime"/> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
128 changes: 128 additions & 0 deletions
128
examples/logto/CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults/Extensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.ServiceDiscovery; | ||
| using OpenTelemetry; | ||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| namespace Microsoft.Extensions.Hosting; | ||
|
|
||
| // Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry. | ||
| // This project should be referenced by each service project in your solution. | ||
| // To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults | ||
| public static class Extensions | ||
| { | ||
| private const string HealthEndpointPath = "/health"; | ||
| private const string AlivenessEndpointPath = "/alive"; | ||
|
|
||
| public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.ConfigureOpenTelemetry(); | ||
|
|
||
| builder.AddDefaultHealthChecks(); | ||
|
|
||
| builder.Services.AddServiceDiscovery(); | ||
|
|
||
| builder.Services.ConfigureHttpClientDefaults(http => | ||
| { | ||
| // Turn on resilience by default | ||
| http.AddStandardResilienceHandler(); | ||
|
|
||
| // Turn on service discovery by default | ||
| http.AddServiceDiscovery(); | ||
| }); | ||
|
|
||
| // Uncomment the following to restrict the allowed schemes for service discovery. | ||
| // builder.Services.Configure<ServiceDiscoveryOptions>(options => | ||
| // { | ||
| // options.AllowedSchemes = ["https"]; | ||
| // }); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) | ||
| where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Logging.AddOpenTelemetry(logging => | ||
| { | ||
| logging.IncludeFormattedMessage = true; | ||
| logging.IncludeScopes = true; | ||
| }); | ||
|
|
||
| builder.Services.AddOpenTelemetry() | ||
| .WithMetrics(metrics => | ||
| { | ||
| metrics.AddAspNetCoreInstrumentation() | ||
| .AddHttpClientInstrumentation() | ||
| .AddRuntimeInstrumentation(); | ||
| }) | ||
| .WithTracing(tracing => | ||
| { | ||
| tracing.AddSource(builder.Environment.ApplicationName) | ||
| .AddAspNetCoreInstrumentation(tracing => | ||
| // Exclude health check requests from tracing | ||
| tracing.Filter = context => | ||
| !context.Request.Path.StartsWithSegments(HealthEndpointPath) | ||
| && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath) | ||
| ) | ||
| // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) | ||
| //.AddGrpcClientInstrumentation() | ||
| .AddHttpClientInstrumentation(); | ||
| }); | ||
|
|
||
| builder.AddOpenTelemetryExporters(); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) | ||
| where TBuilder : IHostApplicationBuilder | ||
| { | ||
| var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); | ||
|
|
||
| if (useOtlpExporter) | ||
| { | ||
| builder.Services.AddOpenTelemetry().UseOtlpExporter(); | ||
| } | ||
|
|
||
| // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) | ||
| //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) | ||
| //{ | ||
| // builder.Services.AddOpenTelemetry() | ||
| // .UseAzureMonitor(); | ||
| //} | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) | ||
| where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Services.AddHealthChecks() | ||
| // Add a default liveness check to ensure app is responsive | ||
| .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static WebApplication MapDefaultEndpoints(this WebApplication app) | ||
| { | ||
| // Adding health checks endpoints to applications in non-development environments has security implications. | ||
| // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. | ||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| // All health checks must pass for app to be considered ready to accept traffic after starting | ||
| app.MapHealthChecks(HealthEndpointPath); | ||
|
|
||
| // Only health checks tagged with the "live" tag must pass for app to be considered alive | ||
| app.MapHealthChecks(AlivenessEndpointPath, | ||
| new HealthCheckOptions { Predicate = r => r.Tags.Contains("live") }); | ||
| } | ||
|
|
||
| return app; | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...munityToolkit.Aspire.Logto.ClientJWT/CommunityToolkit.Aspire.Hosting.Logto.ClientJWT.http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @CommunityToolkit.Aspire.Hosting.Logto.ClientJWT_HostAddress = http://localhost:5072 | ||
|
|
||
| GET {{CommunityToolkit.Aspire.Hosting.Logto.ClientJWT_HostAddress}}/weatherforecast/ | ||
|
|
||
| Accept: application/json | ||
|
|
||
| ### | ||
12 changes: 12 additions & 0 deletions
12
...to/CommunityToolkit.Aspire.Logto.ClientJWT/CommunityToolkit.Aspire.Logto.ClientJWT.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Logto.Client\CommunityToolkit.Aspire.Logto.Client.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
34 changes: 34 additions & 0 deletions
34
examples/logto/CommunityToolkit.Aspire.Logto.ClientJWT/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using CommunityToolkit.Aspire.Logto.Client; | ||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
| using Microsoft.AspNetCore.Authorization; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
| const string apiAudience = "http://localhost:5072/"; | ||
| builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | ||
| .AddLogtoJwtBearer("logto", appIdentification: apiAudience, | ||
| configureOptions: opt => | ||
| { | ||
| opt.RequireHttpsMetadata = false; | ||
| }); | ||
|
|
||
| builder.Services.AddAuthorization(); | ||
|
|
||
|
|
||
| var app = builder.Build(); | ||
| app.UseAuthentication(); | ||
| app.UseAuthorization(); | ||
|
|
||
| app.MapGet("/", () => "OK"); | ||
|
|
||
| app.MapGet("/secure", [Authorize] (System.Security.Claims.ClaimsPrincipal user) => | ||
| { | ||
| return new | ||
| { | ||
| user.Identity?.Name, | ||
| Claims = user.Claims.Select(c => new { c.Type, c.Value }) | ||
| }; | ||
| }); | ||
|
|
||
|
|
||
| app.Run(); |
23 changes: 23 additions & 0 deletions
23
examples/logto/CommunityToolkit.Aspire.Logto.ClientJWT/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5072", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7138;http://localhost:5072", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.