Skip to content

Commit

Permalink
Dotnet 9.0 and React 19
Browse files Browse the repository at this point in the history
  • Loading branch information
drkno committed Dec 7, 2024
1 parent 61147f0 commit 2b24b16
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 508 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
# https://github.com/actions/setup-dotnet/issues/563
# global-json-file: backend/global.json
- name: Build and test
run: |
cd backend
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ WORKDIR /ui
RUN corepack yarn && \
corepack yarn build

FROM mcr.microsoft.com/dotnet/sdk:8.0 as aspnet-builder
FROM mcr.microsoft.com/dotnet/sdk:9.0 as aspnet-builder
COPY ./backend /backend
WORKDIR /backend
RUN dotnet restore && \
dotnet publish PlexSSO.sln -c Release -o build /p:CopyOutputSymbolsToPublishDirectory=false /p:DebugType=None /p:DebugSymbols=false && \
rm build/ui/index.html
COPY --from=react-builder /ui/build /backend/build/ui

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=aspnet-builder /backend/build /app
RUN mkdir -p /config && \
Expand Down
10 changes: 5 additions & 5 deletions backend/PlexSSO.Test/PlexSSO.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
14 changes: 7 additions & 7 deletions backend/PlexSSO.Test/Service/Auth/AuthenticationValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace PlexSSO.Test.Service.Auth;

public class AuthenticationValidatorTest
{
private ILogger<AuthenticationValidator> _mockLogger;
private PlexSsoConfig _config;
private ILogger<AuthenticationValidator>? _mockLogger;
private PlexSsoConfig? _config;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -52,9 +52,9 @@ public void Validate_WithNullServiceUri_DeniesAccess()
{
var validator = CreateValidator();
var identity = new Identity(new List<Claim>());
var serviceName = new ServiceName(_config.AccessControls.Keys.First());
var serviceName = new ServiceName(_config!.AccessControls.Keys.First());

ServiceUri serviceUri = null;
ServiceUri? serviceUri = null;

var result = validator.ValidateAuthenticationStatus(identity, serviceName, serviceUri);

Expand All @@ -71,7 +71,7 @@ public void Validate_WithNoAccess_ReturnsDefaultAccessDeniedMessage()
{
var validator = CreateValidator();
var identity = new Identity(new List<Claim>());
var serviceName = new ServiceName(_config.AccessControls.Keys.First());
var serviceName = new ServiceName(_config!.AccessControls.Keys.First());
var serviceUri = new ServiceUri("/");

var result = validator.ValidateAuthenticationStatus(identity, serviceName, serviceUri);
Expand All @@ -84,7 +84,7 @@ public void Validate_WithNoAccess_ReturnsCustomisedAccessDeniedMessage()
{
var validator = CreateValidator();
var identity = new Identity(new List<Claim>());
var serviceName = new ServiceName(_config.AccessControls.Keys.First());
var serviceName = new ServiceName(_config!.AccessControls.Keys.First());
var serviceUri = new ServiceUri("/");

_config.AccessControls[serviceName.Value].First().BlockMessage = "Test Access Denied Message";
Expand All @@ -96,6 +96,6 @@ public void Validate_WithNoAccess_ReturnsCustomisedAccessDeniedMessage()

private AuthenticationValidator CreateValidator()
{
return new AuthenticationValidator(new TestConfigurationService(_config), _mockLogger);
return new AuthenticationValidator(new TestConfigurationService(_config!), _mockLogger);
}
}
2 changes: 1 addition & 1 deletion backend/PlexSSO/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ await HttpContext.SignInAsync(
}
catch (Exception e)
{
_logger.LogError("Failed to log user in", e);
_logger.LogError("Failed to log user in: {e}", e);
Identity.AccessTier = AccessTier.NoAccess;
Identity.IsAuthenticated = false;
return GetErrorResponse();
Expand Down
2 changes: 1 addition & 1 deletion backend/PlexSSO/Controllers/LogoutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<BasicResponse> Logout()
}
catch (Exception e)
{
_logger.LogError("Failed to log a user out", e);
_logger.LogError("Failed to log a user out: {e}", e);
Response.StatusCode = 400;
return new BasicResponse(false);
}
Expand Down
8 changes: 4 additions & 4 deletions backend/PlexSSO/Controllers/RedirectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private int GenerateRedirect(AuthenticationToken authenticationToken,
var location = string.IsNullOrWhiteSpace(authenticationToken.Location)
? path
: authenticationToken.Location;
Response.Headers.Add("Location", protoString + host + location);
var redirectSuccess = Response.Headers.TryAdd("Location", protoString + host + location);
Response.Cookies.AppendWithoutEncoding(authenticationToken.CookieName, authenticationToken.CookieValue, new CookieOptions
{
HttpOnly = false,
Expand All @@ -70,7 +70,7 @@ private int GenerateRedirect(AuthenticationToken authenticationToken,
Path = "/",
Secure = false
});
_logger.LogInformation($"Performing service specific redirect to '{location}' with status {authenticationToken.StatusCode}");
_logger.LogInformation($"Performing service specific redirect to '{location}' with status {authenticationToken.StatusCode}. Added Location header = {redirectSuccess}");
return authenticationToken.StatusCode;
}

Expand All @@ -79,8 +79,8 @@ private int GenerateNormalRedirectUrl((Protocol, string, string) redirectCompone
var (protocol, host, path) = redirectComponents;
var protoString = protocol == Protocol.Https ? "https://" : "http://";
var location = protoString + host + path;
Response.Headers.Add("Location", location);
_logger.LogInformation($"Performing normal redirect to '{location}' with status 302");
var redirectSuccess = Response.Headers.TryAdd("Location", location);
_logger.LogInformation($"Attempting redirect to '{location}' with status 302. Added Location header = {redirectSuccess}");
return 302;
}

Expand Down
17 changes: 14 additions & 3 deletions backend/PlexSSO/Controllers/SsoController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using PlexSSO.Model;
using PlexSSO.Model.API;
using PlexSSO.Service.Auth;
Expand All @@ -9,10 +11,14 @@ namespace PlexSSO.Controllers
[Route(Constants.ControllerPath)]
public class SsoController : CommonAuthController
{
private readonly ILogger<SsoController> _logger;
private readonly IAuthValidator _authValidator;

public SsoController(IAuthValidator authValidator)
public SsoController(
ILogger<SsoController> logger,
IAuthValidator authValidator)
{
_logger = logger;
_authValidator = authValidator;
}

Expand All @@ -24,8 +30,13 @@ public SsoResponse Get()

if (Identity.IsAuthenticated)
{
Response.Headers.Add(Constants.SsoResponseUserHeader, Identity.Username.ToString());
Response.Headers.Add(Constants.SsoResponseEmailHeader, Identity.Email.ToString());
var success = Response.Headers.TryAdd(Constants.SsoResponseUserHeader, Identity.Username.ToString());
success = success || Response.Headers.TryAdd(Constants.SsoResponseEmailHeader, Identity.Email.ToString());

if (!success)
{
_logger.LogWarning("Adding response headers failed:\n{headers}", Response.Headers);
}
}
return response;
}
Expand Down
4 changes: 2 additions & 2 deletions backend/PlexSSO/PlexSSO.csproj
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>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
Expand All @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion backend/PlexSSO/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Antiforgery;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAntifor
app.Use((context, next) => {
var tokens = antiForgery.GetAndStoreTokens(context);
context.Response.Cookies.Append(Constants.CsrfHeaderName, tokens.RequestToken, new CookieOptions { HttpOnly = false });
context.Response.Headers.Add(Constants.PoweredByHeaderName, Constants.PoweredByHeaderValue);
context.Response.Headers.TryAdd(Constants.PoweredByHeaderName, Constants.PoweredByHeaderValue);
return next.Invoke();
});
app.UseStaticFiles();
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>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\..\build\</OutputPath>
<LangVersion>12</LangVersion>
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>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\..\build\</OutputPath>
<LangVersion>12</LangVersion>
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>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\..\build\</OutputPath>
<LangVersion>12</LangVersion>
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>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\..\build\</OutputPath>
<LangVersion>12</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion backend/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.0",
"version": "9.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
2 changes: 0 additions & 2 deletions examples/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.4'

# For a fuller example, see
# https://github.com/drkno/media-scripts/blob/main/docker-compose.yml

Expand Down
12 changes: 6 additions & 6 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "@plexauth/sso",
"version": "2.2.0",
"version": "2.2.1",
"private": true,
"type": "module",
"dependencies": {
"bootstrap": "^5.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.3.6"
"@vitejs/plugin-react": "^4.3.4",
"vite": "^6.0.3"
},
"scripts": {
"start": "vite",
Expand All @@ -24,5 +24,5 @@
"not ie <= 11",
"not op_mini all"
],
"packageManager": "yarn@4.3.1"
"packageManager": "yarn@4.5.3"
}
Loading

0 comments on commit 2b24b16

Please sign in to comment.