-
Notifications
You must be signed in to change notification settings - Fork 172
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
base: main
Are you sure you want to change the base?
Logto #1241
Changes from 9 commits
cd63a59
0daa9ae
34b16e2
9c725dd
60f73e9
8a0f9de
95d01da
541111c
bc8b00c
d4378b3
4557bf8
0e3f42c
3976aec
6685b60
cde0cbd
d271f0a
f282231
a2e300c
97ce6d6
63356b8
20f300b
cbd16a8
907c4d5
bac366e
95c6f2c
231ae98
6bfd3ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.AddLogtoContainer("logto", postgres) | ||
| .WithRedis(cache); | ||
|
|
||
|
|
||
| var clientOIDC = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Logto_ClientOIDC>("clientOIDC") | ||
| .WithReference(logto) | ||
| .WaitFor(logto); | ||
| var clientJWT = builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Logto_ClientJWT>("clientJWT") | ||
| .WithReference(logto) | ||
| .WaitFor(logto); | ||
|
|
||
|
|
||
| builder.Build().Run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.0.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
|
axies20 marked this conversation as resolved.
Outdated
|
||
| <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.Hosting.Logto.ClientJWT\CommunityToolkit.Aspire.Hosting.Logto.ClientJWT.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Logto.ClientOIDC\CommunityToolkit.Aspire.Hosting.Logto.ClientOIDC.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.PostgreSQL" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| 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" | ||
| } | ||
| } | ||
| } | ||
| } |
| 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" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Logto.Client\CommunityToolkit.Aspire.Hosting.Logto.Client.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| 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 | ||
|
|
||
| ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using CommunityToolkit.Aspire.Hosting.Logto.Client; | ||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
| using Microsoft.AspNetCore.Authorization; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
|
|
||
| builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | ||
| .AddLogtoJwtBearer("logto", "http://localhost:5072/", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the endpoint come from Aspire?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does. |
||
| 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(); | ||
| 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" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @CommunityToolkit.Aspire.Hosting.Logto.Client_HostAddress = http://localhost:5137 | ||
|
|
||
| GET {{CommunityToolkit.Aspire.Hosting.Logto.Client_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| <PropertyGroup> | ||
| <RootNamespace>CommunityToolkit.Aspire.Hosting.Logto.Client</RootNamespace> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Logto.Client\CommunityToolkit.Aspire.Hosting.Logto.Client.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Logto.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using CommunityToolkit.Aspire.Hosting.Logto.Client; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using System.Security.Claims; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
|
|
||
| builder.AddLogtoOIDC("logto", logtoOptions: config => | ||
| { | ||
| config.AppId = "s6zda5bqn1qlsjzaiklqn"; | ||
| config.AppSecret = "Df77aDt13MG3nSTgo8eKZP2HdeSfbed0"; | ||
|
|
||
| },oidcOptions: opt => | ||
| { | ||
| opt.RequireHttpsMetadata = false; | ||
| }); | ||
| builder.Services.AddAuthorization(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
|
|
||
| app.UseAuthentication(); | ||
| app.UseAuthorization(); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| app.MapGet("/", () => "Hello World!"); | ||
|
|
||
| app.MapGet("/me", | ||
| [Authorize](ClaimsPrincipal user) => new | ||
| { | ||
| Name = user.Identity?.Name, | ||
| IsAuthenticated = user.Identity?.IsAuthenticated ?? false, | ||
| Claims = user.Claims.Select(c => new { c.Type, c.Value }) | ||
| }) | ||
| .WithName("Me"); | ||
|
|
||
| app.MapGet("/signin", async context => | ||
| { | ||
| if (!(context.User?.Identity?.IsAuthenticated ?? false)) | ||
| { | ||
| await context.ChallengeAsync(new AuthenticationProperties { RedirectUri = "/me" }); | ||
| } | ||
| else | ||
| { | ||
| context.Response.Redirect("/me"); | ||
| } | ||
| }); | ||
| app.MapGet("/tokens", [Authorize] async (HttpContext ctx) => | ||
| { | ||
| var accessToken = await ctx.GetTokenAsync("access_token"); | ||
| var idToken = await ctx.GetTokenAsync("id_token"); | ||
| var refreshToken = await ctx.GetTokenAsync("refresh_token"); | ||
|
|
||
| return Results.Ok(new | ||
| { | ||
| access_token = accessToken, | ||
| id_token = idToken, | ||
| refresh_token = refreshToken | ||
| }); | ||
| }); | ||
|
|
||
| app.MapGet("/signout", async context => | ||
| { | ||
| if (context.User?.Identity?.IsAuthenticated ?? false) | ||
| { | ||
| await context.SignOutAsync(new AuthenticationProperties { RedirectUri = "/" }); | ||
| } | ||
| else | ||
| { | ||
| context.Response.Redirect("/"); | ||
| } | ||
| }); | ||
| app.Run(); |
| 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:5137", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7288;http://localhost:5137", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is a merge gone bad