Skip to content

Commit

Permalink
Update BFF/DPoP to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdecock committed Jan 17, 2024
1 parent eb17170 commit f9f288b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions IdentityServer/v7/BFF/DPoP/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-api",
"program": "${workspaceFolder}/DPoP.Api/bin/Debug/net6.0/DPoP.Api.dll",
"program": "${workspaceFolder}/DPoP.Api/bin/Debug/net8.0/DPoP.Api.dll",
"args": [],
"cwd": "${workspaceFolder}/DPoP.Api",
"env": {
Expand All @@ -30,7 +30,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-bff",
"program": "${workspaceFolder}/DPoP.Bff/bin/Debug/net6.0/DPoP.Bff.dll",
"program": "${workspaceFolder}/DPoP.Bff/bin/Debug/net8.0/DPoP.Bff.dll",
"args": [],
"cwd": "${workspaceFolder}/DPoP.Bff",
"env": {
Expand Down
8 changes: 4 additions & 4 deletions IdentityServer/v7/BFF/DPoP/DPoP.Api/DPoP.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" version="6.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.9" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="IdentityModel" version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using IdentityModel;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using System.Text;
Expand Down Expand Up @@ -130,7 +131,7 @@ public override Task Challenge(JwtBearerChallengeContext context)
}
}

context.Response.Headers.Add(HeaderNames.WWWAuthenticate, sb.ToString());
context.Response.Headers.Append(HeaderNames.WWWAuthenticate, sb.ToString());


if (context.HttpContext.Items.ContainsKey("DPoP-Nonce"))
Expand Down
12 changes: 5 additions & 7 deletions IdentityServer/v7/BFF/DPoP/DPoP.Api/DPoP/DPoPProofValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
return Task.CompletedTask;
}

if (!token.TryGetHeaderValue<IDictionary<string, object>>(JwtClaimTypes.JsonWebKey, out var jwkValues))
if (!token.TryGetHeaderValue<JsonElement>(JwtClaimTypes.JsonWebKey, out var jwkValues))
{
result.IsError = true;
result.ErrorDescription = "Invalid 'jwk' value.";
Expand Down Expand Up @@ -169,7 +169,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
/// <summary>
/// Validates the signature.
/// </summary>
protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
protected virtual async Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
{
TokenValidationResult tokenValidationResult;

Expand All @@ -185,27 +185,25 @@ protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context,
};

var handler = new JsonWebTokenHandler();
tokenValidationResult = handler.ValidateToken(context.ProofToken, tvp);
tokenValidationResult = await handler.ValidateTokenAsync(context.ProofToken, tvp);
}
catch (Exception ex)
{
Logger.LogDebug("Error parsing DPoP token: {error}", ex.Message);
result.IsError = true;
result.ErrorDescription = "Invalid signature on DPoP token.";
return Task.CompletedTask;
return;
}

if (tokenValidationResult.Exception != null)
{
Logger.LogDebug("Error parsing DPoP token: {error}", tokenValidationResult.Exception.Message);
result.IsError = true;
result.ErrorDescription = "Invalid signature on DPoP token.";
return Task.CompletedTask;
return;
}

result.Payload = tokenValidationResult.Claims;

return Task.CompletedTask;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions IdentityServer/v7/BFF/DPoP/DPoP.Bff/DPoP.Bff.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Host6</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.9" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Duende.Bff.Yarp" Version="2.1.0-preview.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Duende.Bff.Yarp" Version="2.2.0" />
</ItemGroup>
</Project>
5 changes: 2 additions & 3 deletions IdentityServer/v7/BFF/DPoP/DPoP.Bff/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void ConfigureServices(IServiceCollection services)
var jwk = JsonSerializer.Serialize(jwkKey);
options.DPoPJsonWebKey = jwk;
})
.AddRemoteApis()
.AddServerSideSessions();
.AddRemoteApis();
// .AddServerSideSessions();

// local APIs
services.AddControllers();
Expand Down Expand Up @@ -204,7 +204,6 @@ private static void MapRemoteUrls(IEndpointRouteBuilder endpoints)

// On this path, we require the user token
endpoints.MapRemoteBffApiEndpoint("/api/user-token", "https://localhost:6001")
.WithUserAccessTokenParameter(new BffUserAccessTokenParameters(resource: "urn:example-api"))
.RequireAccessToken(TokenType.User);
}
}
2 changes: 1 addition & 1 deletion IdentityServer/v7/BFF/DPoP/DPoP.Bff/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<div class="container">
<header class="page-header">
<h1>SPA (.NET 6 host)</h1>
<h1>SPA with BFF using DPoP</h1>
</header>

<div class="row">
Expand Down

0 comments on commit f9f288b

Please sign in to comment.