From f1fa630717188142aad20dc37dc4cadc98d02e70 Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Thu, 30 Nov 2023 12:39:13 -0600 Subject: [PATCH] Update sample apis to .NET 8 --- .vscode/launch.json | 41 ------------------- .vscode/tasks.json | 24 ----------- .../Properties/launchSettings.json | 4 +- samples/Api.DPoP/Api.DPoP.csproj | 6 +-- samples/Api.DPoP/DPoP/DPoPJwtBearerEvents.cs | 3 +- samples/Api.DPoP/DPoP/DPoPProofValidator.cs | 10 ++--- .../Api.DPoP/Properties/launchSettings.json | 2 +- samples/Api.Isolated/Api.Isolated.csproj | 6 +-- .../Properties/launchSettings.json | 2 +- samples/Api/Api.csproj | 6 +-- samples/Api/Properties/launchSettings.json | 2 +- samples/IdentityServer/Config.cs | 25 +++++++++-- .../JS.Yarp/Properties/launchSettings.json | 4 +- .../JS6.DPoP/Properties/launchSettings.json | 4 +- samples/JS6.EF/Properties/launchSettings.json | 4 +- samples/JS6.EF/Startup.cs | 2 +- samples/JS6/Properties/launchSettings.json | 4 +- .../JS8.DPoP/Properties/launchSettings.json | 4 +- samples/JS8.EF/Properties/launchSettings.json | 4 +- samples/JS8.EF/Startup.cs | 2 +- 20 files changed, 55 insertions(+), 104 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e25925b4..9db6eafd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -93,47 +93,6 @@ "order": 40 } }, - { - "name": "JS3", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build-js3", - "program": "${workspaceFolder}/samples/JS3/bin/Debug/net6.0/JS3.dll", - "args": [], - "cwd": "${workspaceFolder}/samples/JS3", - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "serverReadyAction": { - "action": "openExternally", - "pattern": "\\bNow listening on:\\s+(https?://\\S+)" - }, - "presentation": { - "hidden": false, - "order": 10 - } - }, - - { - "name": "JS5", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build-js5", - "program": "${workspaceFolder}/samples/JS5/bin/Debug/net6.0/JS5.dll", - "args": [], - "cwd": "${workspaceFolder}/samples/JS5", - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "serverReadyAction": { - "action": "openExternally", - "pattern": "\\bNow listening on:\\s+(https?://\\S+)" - }, - "presentation": { - "hidden": false, - "order": 10 - } - }, { "name": "JS6", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3036f4c4..03e6d4b7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -61,30 +61,6 @@ ], "problemMatcher": "$msCompile" }, - { - "label": "build-js3", - "type": "process", - "command": "dotnet", - "args": [ - "build", - "${workspaceFolder}/samples/JS3/JS3.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "build-js5", - "type": "process", - "command": "dotnet", - "args": [ - "build", - "${workspaceFolder}/samples/JS5/JS5.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, { "label": "build-js6", "type": "process", diff --git a/migrations/UserSessionDb/Properties/launchSettings.json b/migrations/UserSessionDb/Properties/launchSettings.json index 171748a2..08ed1617 100644 --- a/migrations/UserSessionDb/Properties/launchSettings.json +++ b/migrations/UserSessionDb/Properties/launchSettings.json @@ -17,7 +17,7 @@ }, "UserSessionDb": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://localhost:5000", "environmentVariables": { @@ -25,4 +25,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/Api.DPoP/Api.DPoP.csproj b/samples/Api.DPoP/Api.DPoP.csproj index 14928e00..60336f13 100644 --- a/samples/Api.DPoP/Api.DPoP.csproj +++ b/samples/Api.DPoP/Api.DPoP.csproj @@ -1,12 +1,12 @@ - net6.0 + net8.0 - - + + diff --git a/samples/Api.DPoP/DPoP/DPoPJwtBearerEvents.cs b/samples/Api.DPoP/DPoP/DPoPJwtBearerEvents.cs index e4351d77..e5801b23 100644 --- a/samples/Api.DPoP/DPoP/DPoPJwtBearerEvents.cs +++ b/samples/Api.DPoP/DPoP/DPoPJwtBearerEvents.cs @@ -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; @@ -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")) diff --git a/samples/Api.DPoP/DPoP/DPoPProofValidator.cs b/samples/Api.DPoP/DPoP/DPoPProofValidator.cs index e97587f2..89ab2ed7 100644 --- a/samples/Api.DPoP/DPoP/DPoPProofValidator.cs +++ b/samples/Api.DPoP/DPoP/DPoPProofValidator.cs @@ -169,7 +169,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP /// /// Validates the signature. /// - protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result) + protected virtual async Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result) { TokenValidationResult tokenValidationResult; @@ -185,14 +185,14 @@ 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) @@ -200,12 +200,10 @@ protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context, 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; } /// diff --git a/samples/Api.DPoP/Properties/launchSettings.json b/samples/Api.DPoP/Properties/launchSettings.json index 2c5847d0..07ad731c 100644 --- a/samples/Api.DPoP/Properties/launchSettings.json +++ b/samples/Api.DPoP/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Api": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": false, "applicationUrl": "https://localhost:5011", "environmentVariables": { diff --git a/samples/Api.Isolated/Api.Isolated.csproj b/samples/Api.Isolated/Api.Isolated.csproj index 14928e00..60336f13 100644 --- a/samples/Api.Isolated/Api.Isolated.csproj +++ b/samples/Api.Isolated/Api.Isolated.csproj @@ -1,12 +1,12 @@ - net6.0 + net8.0 - - + + diff --git a/samples/Api.Isolated/Properties/launchSettings.json b/samples/Api.Isolated/Properties/launchSettings.json index a3f4507c..ac1212f8 100644 --- a/samples/Api.Isolated/Properties/launchSettings.json +++ b/samples/Api.Isolated/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Api": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": false, "applicationUrl": "https://localhost:5012", "environmentVariables": { diff --git a/samples/Api/Api.csproj b/samples/Api/Api.csproj index 14928e00..60336f13 100644 --- a/samples/Api/Api.csproj +++ b/samples/Api/Api.csproj @@ -1,12 +1,12 @@ - net6.0 + net8.0 - - + + diff --git a/samples/Api/Properties/launchSettings.json b/samples/Api/Properties/launchSettings.json index bc73add9..13f28561 100644 --- a/samples/Api/Properties/launchSettings.json +++ b/samples/Api/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Api": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": false, "applicationUrl": "https://localhost:5010", "environmentVariables": { diff --git a/samples/IdentityServer/Config.cs b/samples/IdentityServer/Config.cs index cb7d0775..80083cef 100644 --- a/samples/IdentityServer/Config.cs +++ b/samples/IdentityServer/Config.cs @@ -49,15 +49,32 @@ public static class Config }, RedirectUris = { "https://localhost:5002/signin-oidc" }, - - //FrontChannelLogoutUri = "https://localhost:5002/signout-oidc", - BackChannelLogoutUri = "https://localhost:5002/bff/backchannel", - + FrontChannelLogoutUri = "https://localhost:5002/signout-oidc", PostLogoutRedirectUris = { "https://localhost:5002/signout-callback-oidc" }, AllowOfflineAccess = true, AllowedScopes = { "openid", "profile", "api", "scope-for-isolated-api" }, }, + + new Client + { + ClientId = "backchannel-spa", + ClientSecrets = { new Secret("secret".Sha256()) }, + + AllowedGrantTypes = + { + GrantType.AuthorizationCode, + GrantType.ClientCredentials, + OidcConstants.GrantTypes.TokenExchange + }, + + RedirectUris = { "https://localhost:5003/signin-oidc" }, + BackChannelLogoutUri = "https://localhost:5003/bff/backchannel", + PostLogoutRedirectUris = { "https://localhost:5003/signout-callback-oidc" }, + + AllowOfflineAccess = true, + AllowedScopes = { "openid", "profile", "api", "scope-for-isolated-api" }, + }, }; } } \ No newline at end of file diff --git a/samples/JS.Yarp/Properties/launchSettings.json b/samples/JS.Yarp/Properties/launchSettings.json index ff245f9a..41550a4d 100644 --- a/samples/JS.Yarp/Properties/launchSettings.json +++ b/samples/JS.Yarp/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Host5": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:5002", "environmentVariables": { @@ -10,4 +10,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/JS6.DPoP/Properties/launchSettings.json b/samples/JS6.DPoP/Properties/launchSettings.json index 7478247e..0cceaadb 100644 --- a/samples/JS6.DPoP/Properties/launchSettings.json +++ b/samples/JS6.DPoP/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Host6": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:5002", "environmentVariables": { @@ -10,4 +10,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/JS6.EF/Properties/launchSettings.json b/samples/JS6.EF/Properties/launchSettings.json index 1ddc0799..178ff1a8 100644 --- a/samples/JS6.EF/Properties/launchSettings.json +++ b/samples/JS6.EF/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Host5.EntityFramework": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:5002", "environmentVariables": { @@ -10,4 +10,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/JS6.EF/Startup.cs b/samples/JS6.EF/Startup.cs index 91729079..6c8baba9 100644 --- a/samples/JS6.EF/Startup.cs +++ b/samples/JS6.EF/Startup.cs @@ -63,7 +63,7 @@ public void ConfigureServices(IServiceCollection services) options.Authority = "https://localhost:5001"; // confidential client using code flow + PKCE - options.ClientId = "spa"; + options.ClientId = "backchannel-spa"; options.ClientSecret = "secret"; options.ResponseType = "code"; options.ResponseMode = "query"; diff --git a/samples/JS6/Properties/launchSettings.json b/samples/JS6/Properties/launchSettings.json index 7478247e..0cceaadb 100644 --- a/samples/JS6/Properties/launchSettings.json +++ b/samples/JS6/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Host6": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:5002", "environmentVariables": { @@ -10,4 +10,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/JS8.DPoP/Properties/launchSettings.json b/samples/JS8.DPoP/Properties/launchSettings.json index 7478247e..0cceaadb 100644 --- a/samples/JS8.DPoP/Properties/launchSettings.json +++ b/samples/JS8.DPoP/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Host6": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:5002", "environmentVariables": { @@ -10,4 +10,4 @@ } } } -} +} \ No newline at end of file diff --git a/samples/JS8.EF/Properties/launchSettings.json b/samples/JS8.EF/Properties/launchSettings.json index aa2d3a1e..02e1106a 100644 --- a/samples/JS8.EF/Properties/launchSettings.json +++ b/samples/JS8.EF/Properties/launchSettings.json @@ -2,9 +2,9 @@ "profiles": { "Host8.EntityFramework": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:5002", + "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/JS8.EF/Startup.cs b/samples/JS8.EF/Startup.cs index ac128642..9d302cff 100644 --- a/samples/JS8.EF/Startup.cs +++ b/samples/JS8.EF/Startup.cs @@ -63,7 +63,7 @@ public void ConfigureServices(IServiceCollection services) options.Authority = "https://localhost:5001"; // confidential client using code flow + PKCE - options.ClientId = "spa"; + options.ClientId = "backchannel-spa"; options.ClientSecret = "secret"; options.ResponseType = "code"; options.ResponseMode = "query";