Skip to content

Commit

Permalink
Merge pull request #64 from damienbod/net9
Browse files Browse the repository at this point in the history
Support .NET 9
  • Loading branch information
damienbod authored Dec 10, 2024
2 parents dc8915e + 02d8fd6 commit 8ea0e72
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.*
dotnet-version: 9.0.*

- name: Build Blazor template
run: dotnet build ./BlazorBffOpenIdConnect/
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.*
dotnet-version: 9.0.*

- name: Build Blazor template
run: dotnet build ./BlazorBffOpenIdConnect/
Expand Down
6 changes: 3 additions & 3 deletions BlazorBffOpenIDConnect.Template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>damienbod</Authors>
<Description>This template provides a simple Blazor template with BFF server authentication WASM hosted.</Description>
<PackageTags>dotnet-new;templates;Blazor;BFF;WASM;ASP.NET Core;AspNetCore;OpenIDConnect;OAuth2</PackageTags>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Summary>This template provides a simple Blazor template with BFF server authentication WASM hosted</Summary>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand All @@ -16,10 +16,10 @@
<NoDefaultExcludes>true</NoDefaultExcludes>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/damienbod/Blazor.BFF.OpenIDConnect.Template</PackageProjectUrl>
<Copyright>2023 damienbod</Copyright>
<Copyright>2024 damienbod</Copyright>
<PackageReadmeFile>README-NUGET.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/damienbod/Blazor.BFF.OpenIDConnect.Template</RepositoryUrl>
<PackageReleaseNotes>New template, support for HTTP port parameter</PackageReleaseNotes>
<PackageReleaseNotes>Support .NET 9</PackageReleaseNotes>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 5 additions & 7 deletions BlazorBffOpenIdConnect/Client/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
global using System.Net;
global using System.Net.Http.Headers;
global using System.Net.Http.Json;
global using System.Security.Claims;

global using BlazorBffOpenIDConnect.Client;
global using BlazorBffOpenIDConnect.Client;
global using BlazorBffOpenIDConnect.Client.Services;
global using BlazorBffOpenIDConnect.Shared.Authorization;
global using BlazorBffOpenIDConnect.Shared.Defaults;

global using Microsoft.AspNetCore.Components;
global using Microsoft.AspNetCore.Components.Authorization;
global using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.JSInterop;
global using System.Net;
global using System.Net.Http.Headers;
global using System.Net.Http.Json;
global using System.Security.Claims;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BlazorBffOpenIDConnect.Client.Services;

public class AntiforgeryHttpClientFactory(IHttpClientFactory httpClientFactory, IJSRuntime jSRuntime)
public class AntiforgeryHttpClientFactory(IHttpClientFactory httpClientFactory, IJSRuntime jSRuntime)
: IAntiforgeryHttpClientFactory
{
public async Task<HttpClient> CreateClientAsync(string clientName = AuthDefaults.AuthorizedClientName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace BlazorBffOpenIDConnect.Client.Services;

// orig src https://github.com/berhir/BlazorWebAssemblyCookieAuth
public class AuthorizedHandler(HostAuthenticationStateProvider authenticationStateProvider)
public class AuthorizedHandler(HostAuthenticationStateProvider authenticationStateProvider)
: DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace BlazorBffOpenIDConnect.Client.Services;

// orig src https://github.com/berhir/BlazorWebAssemblyCookieAuth
public class HostAuthenticationStateProvider(NavigationManager navigation, HttpClient client, ILogger<HostAuthenticationStateProvider> logger)
public class HostAuthenticationStateProvider(NavigationManager navigation, HttpClient client, ILogger<HostAuthenticationStateProvider> logger)
: AuthenticationStateProvider
{
private static readonly TimeSpan userCacheRefreshInterval = TimeSpan.FromSeconds(60);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -12,10 +12,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.8" NoWarn="NU1605" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="1.0.0-preview.1" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders.TagHelpers" Version="1.0.0-preview.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" NoWarn="NU1605" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="1.0.0-preview.2" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders.TagHelpers" Version="1.0.0-preview.2" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions BlazorBffOpenIdConnect/Server/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
global using System.Diagnostics;
global using System.Security.Claims;

global using BlazorBffOpenIDConnect.Server;
global using BlazorBffOpenIDConnect.Server;
global using BlazorBffOpenIDConnect.Server.Services;
global using BlazorBffOpenIDConnect.Shared.Authorization;
global using BlazorBffOpenIDConnect.Shared.Defaults;

global using Microsoft.AspNetCore.Authentication;
global using Microsoft.AspNetCore.Authentication.Cookies;
global using Microsoft.AspNetCore.Authentication.OpenIdConnect;
Expand All @@ -14,4 +10,6 @@
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.RazorPages;
global using Microsoft.IdentityModel.Protocols.OpenIdConnect;
global using System.Diagnostics;
global using System.Security.Claims;

8 changes: 7 additions & 1 deletion BlazorBffOpenIdConnect/Server/SecurityHeadersDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

public static class SecurityHeadersDefinitions
{
private static HeaderPolicyCollection? policy;

public static HeaderPolicyCollection GetHeaderPolicyCollection(bool isDev, string? idpHost)
{
ArgumentNullException.ThrowIfNull(idpHost);

var policy = new HeaderPolicyCollection()
// Avoid building a new HeaderPolicyCollection on every request for performance reasons.
// Where possible, cache and reuse HeaderPolicyCollection instances.
if (policy != null) return policy;

policy = new HeaderPolicyCollection()
.AddFrameOptionsDeny()
.AddContentTypeOptionsNoSniff()
.AddReferrerPolicyStrictOriginWhenCrossOrigin()
Expand Down
6 changes: 3 additions & 3 deletions BlazorBffOpenIdConnect/Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"OpenIDConnectSettings": {
"Authority": "--your-authority--",
"ClientId": "--client-ID--",
"ClientSecret": "--client-secret-from-user-secrets--"
"Authority": "https://localhost:44395",
"ClientId": "blazorcodeflowpkceclient",
"ClientSecret": "codeflow_pkce_client_secret"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[Readme](https://github.com/damienbod/Blazor.BFF.OpenIDConnect.Template/blob/main/README.md)

**2024-12-10** 4.0.0
- .NET 9

**2024-10-07** 3.0.5
- Updated security headers package

Expand Down
4 changes: 2 additions & 2 deletions README-NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This template can be used to create a Blazor WASM application hosted in an ASP.N

## Features

- WASM hosted in ASP.NET Core 8
- WASM hosted in ASP.NET Core 9
- BFF (backend for frontend) with Standard OpenID Connect
- OAuth2 and OpenID Connect OIDC
- No tokens in the browser
Expand Down Expand Up @@ -48,7 +48,7 @@ dotnet new uninstall Blazor.BFF.OpenIDConnect.Template
```


## Credits, Used NuGet packages + ASP.NET Core 8.0 standard packages
## Credits, Used NuGet packages + ASP.NET Core 9.0 standard packages

- NetEscapades.AspNetCore.SecurityHeaders

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This template can be used to create a Blazor WASM application hosted in an ASP.N

## Features

- WASM hosted in ASP.NET Core 8
- WASM hosted in ASP.NET Core 9
- BFF with OpenID Connect
- OAuth2 and OpenID Connect OIDC
- No tokens in the browser
Expand Down Expand Up @@ -81,7 +81,7 @@ dotnet new install <PATH>
Where `<PATH>` is the path to the folder containing .template.config.


## Credits, Used NuGet packages + ASP.NET Core 8.0 standard packages
## Credits, Used NuGet packages + ASP.NET Core 9.0 standard packages

- NetEscapades.AspNetCore.SecurityHeaders

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.400"
"version": "9.0.101"
}
}

0 comments on commit 8ea0e72

Please sign in to comment.