Skip to content

Commit

Permalink
Merge pull request #432 from ActiveLogin/feature/431-net-8
Browse files Browse the repository at this point in the history
Upgrade to .NET 8
  • Loading branch information
jakobehn authored Jan 2, 2024
2 parents 75e333d + 1422aff commit dc4e2df
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 75 deletions.
10 changes: 10 additions & 0 deletions BREAKINGCHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ___Note:___ We might, and will probably, miss to document some of this - if so -

## TOC

* [Version 8.0.0](#version-800)
* [Version 7.0.0](#version-700)
* [Version 6.0.3](#version-603)
* [Version 6.0.0](#version-600)
Expand All @@ -15,6 +16,15 @@ ___Note:___ We might, and will probably, miss to document some of this - if so -

---


## Version 8.0.0

Breaking changes between version 8.0.0 and 7.0.0

### Upgrade to .NET 7

We now require .NET 8 - so this requires you to upgrade your website that uses Active Login.

## Version 7.0.0

Breaking changes between version 7.0.0 and 6.0.3
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.302",
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -17,8 +17,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.5" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -19,10 +19,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" Version="6.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Duende.IdentityServer" Version="6.3.7" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/Standalone.MvcSample/Standalone.MvcSample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -31,6 +31,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />

<PackageReference Include="ActiveLogin.Identity.Swedish" Version="3.0.0" />
</ItemGroup>
Expand Down Expand Up @@ -55,7 +55,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.0.4">
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ public BankIdAuthHandler(
IOptionsMonitor<BankIdAuthOptions> options,
ILoggerFactory loggerFactory,
UrlEncoder encoder,
ISystemClock clock,
IBankIdUiStateProtector uiStateProtector,
IBankIdUiOptionsProtector uiOptionsProtector,
IBankIdUiResultProtector uiResultProtector,
IBankIdEventTrigger bankIdEventTrigger,
IBankIdSupportedDeviceDetector bankIdSupportedDeviceDetector,
IEnumerable<IBankIdClaimsTransformer> bankIdClaimsTransformers)
: base(options, loggerFactory, encoder, clock)
: base(options, loggerFactory, encoder)
{
_httpContextAccessor = httpContextAccessor;
_antiforgery = antiforgery;
Expand Down Expand Up @@ -115,7 +114,12 @@ private async Task<AuthenticationTicket> GetAuthenticationTicket(BankIdUiResult
{
if (Options.TokenExpiresIn.HasValue)
{
properties.ExpiresUtc = Clock.UtcNow.Add(Options.TokenExpiresIn.Value);
if (Options.TimeProvider == null)
{
throw new InvalidOperationException(BankIdConstants.ErrorMessages.TimeProviderNotSet);
}

properties.ExpiresUtc = Options.TimeProvider?.GetUtcNow().Add(Options.TokenExpiresIn.Value);
}

var claims = await GetClaims(uiAuthResult);
Expand Down Expand Up @@ -189,8 +193,13 @@ private void AppendStateCookie(AuthenticationProperties properties)
{
Validators.ThrowIfNullOrWhitespace(Options.StateCookie.Name, StateCookieNameParameterName);

if (Options.TimeProvider == null)
{
throw new InvalidOperationException(BankIdConstants.ErrorMessages.TimeProviderNotSet);
}

var state = new BankIdUiAuthState(properties);
var cookieOptions = Options.StateCookie.Build(Context, Clock.UtcNow);
var cookieOptions = Options.StateCookie.Build(Context, Options.TimeProvider.GetUtcNow());
var cookieValue = _uiStateProtector.Protect(state);

Response.Cookies.Append(Options.StateCookie.Name, cookieValue, cookieOptions);
Expand All @@ -213,7 +222,12 @@ private void DeleteStateCookie()
{
Validators.ThrowIfNullOrWhitespace(Options.StateCookie.Name, StateCookieNameParameterName);

var cookieOptions = Options.StateCookie.Build(Context, Clock.UtcNow);
if (Options.TimeProvider == null)
{
throw new InvalidOperationException(BankIdConstants.ErrorMessages.TimeProviderNotSet);
}

var cookieOptions = Options.StateCookie.Build(Context, Options.TimeProvider.GetUtcNow());
Response.Cookies.Delete(Options.StateCookie.Name, cookieOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static class QueryStringParameters

public static class ErrorMessages
{
public const string TimeProviderNotSet = "TimeProvider must be set.";

public const string CouldNotAccessHttpContext = "Can't access HttpContext";

public const string InvalidReturnUrl = "Invalid returnUrl. Needs to be a local url.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using ActiveLogin.Identity.Swedish;

using Microsoft.AspNetCore.Authentication;

namespace ActiveLogin.Authentication.BankId.AspNetCore.ClaimsTransformation;

public class BankIdDefaultClaimsTransformer : IBankIdClaimsTransformer
{
public ISystemClock Clock { get; }
public TimeProvider TimeProvider { get; }

public BankIdDefaultClaimsTransformer(ISystemClock clock)
public BankIdDefaultClaimsTransformer(TimeProvider timeProvider)
{
Clock = clock;
TimeProvider = timeProvider;
}

public Task TransformClaims(BankIdClaimsTransformationContext context)
Expand Down Expand Up @@ -40,7 +38,7 @@ private Task AddOptionalClaims(BankIdClaimsTransformationContext context)
{
if (context.BankIdAuthOptions.TokenExpiresIn.HasValue)
{
var expiresUtc = Clock.UtcNow.Add(context.BankIdAuthOptions.TokenExpiresIn.Value);
var expiresUtc = TimeProvider.GetUtcNow().Add(context.BankIdAuthOptions.TokenExpiresIn.Value);
context.AddClaim(BankIdClaimTypes.Expires, GetJwtExpires(expiresUtc));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.9.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -14,9 +14,9 @@

<PackageId>$(AssemblyName)</PackageId>

<VersionPrefix>7.0.0</VersionPrefix>
<!--<VersionSuffix>rc-1</VersionSuffix>-->
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<VersionPrefix>8.0.0</VersionPrefix>
<VersionSuffix>alpha-1</VersionSuffix>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion Condition="'$(BUILD_BUILDNUMBER)' == ''">$(VersionPrefix).0</FileVersion>
<FileVersion Condition="'$(BUILD_BUILDNUMBER)' != ''">$(VersionPrefix).$(BUILD_BUILDNUMBER)</FileVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="AngleSharp" Version="1.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,6 @@ public async Task Api_Always_Returns_CamelCase_Json_For_Http400BadRequest()
{
services.AddTransient(s => _bankIdUiOptionsProtector.Object);
services.AddTransient(s => _bankIdUiStateProtector.Object);
services.AddMvc().AddJsonOptions(configure =>
{
configure.JsonSerializerOptions.PropertyNamingPolicy = null;
});
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Net.Http;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;

using ActiveLogin.Authentication.BankId.Api;
Expand Down Expand Up @@ -503,10 +504,6 @@ public async Task Api_Always_Returns_CamelCase_Json_For_Http400BadRequest()
{
services.AddTransient(s => _bankIdUiOptionsProtector.Object);
services.AddTransient(s => _bankIdUiStateProtector.Object);
services.AddMvc().AddJsonOptions(configure =>
{
configure.JsonSerializerOptions.PropertyNamingPolicy = null;
});
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public async Task Should_Add_TokenExpiresIn_As_exp_Claim()
bankIdOptions.TokenExpiresIn = TimeSpan.FromHours(2);

var context = new BankIdClaimsTransformationContext(bankIdOptions, "", "381123-9106", "", "", "", EmptyCompletionData);
var systemClockMock = new Mock<ISystemClock>();
var systemClockMock = new Mock<TimeProvider>();
var dateTime = new DateTime(2022, 03, 11, 05, 30, 30, DateTimeKind.Utc);
systemClockMock.Setup(x => x.UtcNow).Returns(dateTime);
systemClockMock.Setup(x => x.GetUtcNow()).Returns(dateTime);
var claimsTransformer = new BankIdDefaultClaimsTransformer(systemClockMock.Object);

// Act
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task Should_Not_Should_Add_IdentityProvider_As_idp_Claim_When_Disab

private async Task<List<Claim>> TransformClaims(BankIdClaimsTransformationContext context)
{
var claimsTransformer = new BankIdDefaultClaimsTransformer(new SystemClock());
var claimsTransformer = new BankIdDefaultClaimsTransformer(TimeProvider.System);

await claimsTransformer.TransformClaims(context);
return context.Claims;
Expand Down
Loading

0 comments on commit dc4e2df

Please sign in to comment.