-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1710 from Erwinvandervalk/bff-add-aspire-to-samples
Bff add aspire to samples
- Loading branch information
Showing
41 changed files
with
855 additions
and
599 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information.</s:String></wpf:ResourceDictionary> | ||
// See LICENSE in the project root for license information.</s:String> | ||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Duende.IdentityModel" /> | ||
<PackageReference Include="Duende.AspNetCore.Authentication.JwtBearer" Version="0.1.3" /> | ||
<PackageReference Include="Serilog.AspNetCore" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Hosts.ServiceDefaults\Hosts.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains 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,86 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using Duende.AspNetCore.Authentication.JwtBearer.DPoP; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Serilog; | ||
|
||
internal static class Extensions | ||
{ | ||
public static WebApplication ConfigureServices(this WebApplicationBuilder builder) | ||
{ | ||
var services = builder.Services; | ||
|
||
services.AddControllers(); | ||
|
||
services.AddAuthentication("token") | ||
.AddJwtBearer("token", options => | ||
{ | ||
options.Authority = "https://localhost:5001"; | ||
options.MapInboundClaims = false; | ||
|
||
options.TokenValidationParameters = new TokenValidationParameters() | ||
{ | ||
ValidateAudience = false, | ||
ValidTypes = new[] { "at+jwt" }, | ||
|
||
NameClaimType = "name", | ||
RoleClaimType = "role" | ||
}; | ||
}); | ||
|
||
// layers DPoP onto the "token" scheme above | ||
services.ConfigureDPoPTokensForScheme("token"); | ||
|
||
services.AddAuthorization(options => | ||
{ | ||
options.AddPolicy("ApiCaller", policy => | ||
{ | ||
policy.RequireClaim("scope", "api"); | ||
}); | ||
|
||
options.AddPolicy("RequireInteractiveUser", policy => | ||
{ | ||
policy.RequireClaim("sub"); | ||
}); | ||
}); | ||
return builder.Build(); | ||
|
||
} | ||
|
||
public static WebApplication ConfigurePipeline(this WebApplication app) | ||
{ | ||
// The BFF sets the X-Forwarded-* headers to reflect that it | ||
// forwarded the request here. Using the forwarded headers | ||
// middleware here would therefore change the request's host to be | ||
// the bff instead of this API, which is not what the DPoP | ||
// validation code expects when it checks the htu value. If this API | ||
// were hosted behind a load balancer, you might need to add back | ||
// the forwarded headers middleware, or consider changing the DPoP | ||
// proof validation. | ||
|
||
// app.UseForwardedHeaders(new ForwardedHeadersOptions | ||
// { | ||
// ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost, | ||
// }); | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseRouting(); | ||
app.UseAuthentication(); | ||
app.UseAuthorization(); | ||
|
||
app.MapControllers() | ||
.RequireAuthorization("ApiCaller"); | ||
|
||
return app; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,58 +1,44 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Hosting; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace Api.DPoP | ||
Console.Title = "DPoP Api"; | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
Log.Information("Starting up"); | ||
|
||
try | ||
{ | ||
public class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Console.Title = "DPoP API"; | ||
Activity.DefaultIdFormat = ActivityIdFormat.W3C; | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.AddServiceDefaults(); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) | ||
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) | ||
.MinimumLevel.Override("System", LogEventLevel.Warning) | ||
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code) | ||
.CreateLogger(); | ||
builder.Host.UseSerilog((ctx, lc) => lc | ||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") | ||
.Enrich.FromLogContext() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) | ||
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) | ||
.MinimumLevel.Override("System", LogEventLevel.Warning) | ||
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) | ||
.ReadFrom.Configuration(ctx.Configuration)); | ||
|
||
try | ||
{ | ||
Log.Information("Starting host..."); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly."); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
var app = builder | ||
.ConfigureServices() | ||
.ConfigurePipeline(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) | ||
{ | ||
return Host.CreateDefaultBuilder(args) | ||
.UseSerilog() | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} | ||
app.Run(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
} | ||
finally | ||
{ | ||
Log.Information("Shut down complete"); | ||
Log.CloseAndFlush(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Duende.IdentityModel" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" /> | ||
<PackageReference Include="Serilog.AspNetCore" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Hosts.ServiceDefaults\Hosts.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.