Skip to content

Commit

Permalink
Test 3rd Party PR: Add support for .NET 8 (okta#257)
Browse files Browse the repository at this point in the history
* Target .NET 8

* Replace deprecated UseSecurityTokenValidators with TokenHandlers ref https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/8.0/securitytoken-events

* Style - Remove blank line

---------

Co-authored-by: Jeff Johnson <jeffcj@gmail.com>
  • Loading branch information
laura-rodriguez and jeffcj authored Mar 4, 2024
1 parent adddd46 commit 2810d1d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Okta.AspNetCore.Test/Okta.AspNetCore.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>

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

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Okta.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
Running changelog of releases since `3.2.0`

## v4.6.0

### Features

- Add support for .NET 8

## v4.5.0

### Features
Expand Down
32 changes: 20 additions & 12 deletions Okta.AspNetCore/Okta.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<Description>Official Okta middleware for ASP.NET Core 3.1+. Easily add authentication and authorization to ASP.NET Core applications.</Description>
<Copyright>(c) 2020 - present Okta, Inc. All rights reserved.</Copyright>
<Version>4.5.0</Version>
<VersionPrefix>4.5.0</VersionPrefix>
<Version>4.6.0</Version>
<VersionPrefix>4.6.0</VersionPrefix>
<Authors>Okta, Inc.</Authors>
<AssemblyName>Okta.AspNetCore</AssemblyName>
<PackageId>Okta.AspNetCore</PackageId>
Expand All @@ -20,8 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.28" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.23" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -30,20 +29,29 @@
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.23.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.*" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Okta.AspNetCore/OktaAuthenticationOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ private static Task BeforeRedirectToIdentityProviderAsync(RedirectContext contex
context.ProtocolMessage.Scope = null;
context.ProtocolMessage.Resource = null;
context.ProtocolMessage.RedirectUri = context?.Properties?.RedirectUri ?? context.ProtocolMessage.RedirectUri;

}

if (redirectEvent != null)
Expand Down
14 changes: 12 additions & 2 deletions Okta.AspNetCore/OpenIdConnectOptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public static void ConfigureOpenIdConnectOptions(OktaMvcOptions oktaMvcOptions,
oidcOptions.SignedOutRedirectUri = oktaMvcOptions.PostLogoutRedirectUri;
oidcOptions.ResponseType = OpenIdConnectResponseType.Code;
oidcOptions.GetClaimsFromUserInfoEndpoint = oktaMvcOptions.GetClaimsFromUserInfoEndpoint;
#if NET8_0_OR_GREATER
oidcOptions.TokenHandler = new StrictTokenHandler();
#else
oidcOptions.SecurityTokenValidator = new StrictSecurityTokenValidator();
#endif
oidcOptions.SaveTokens = true;
oidcOptions.UseTokenLifetime = false;
oidcOptions.BackchannelHttpHandler = new OktaHttpMessageHandler(
Expand Down Expand Up @@ -92,14 +96,20 @@ public static void ConfigureJwtBearerOptions(OktaWebApiOptions oktaWebApiOptions
{
ValidAudience = oktaWebApiOptions.Audience,
};
#if NET8_0_OR_GREATER
jwtBearerOptions.TokenHandlers.Clear();
jwtBearerOptions.TokenHandlers.Add(new StrictTokenHandler());

#else
jwtBearerOptions.SecurityTokenValidators.Clear();
jwtBearerOptions.SecurityTokenValidators.Add(new StrictSecurityTokenValidator());
#endif

jwtBearerOptions.Audience = oktaWebApiOptions.Audience;
jwtBearerOptions.Authority = issuer;
jwtBearerOptions.TokenValidationParameters = tokenValidationParameters;
jwtBearerOptions.BackchannelHttpHandler = new OktaHttpMessageHandler("okta-aspnetcore", typeof(OktaAuthenticationOptionsExtensions).Assembly.GetName().Version, oktaWebApiOptions);
jwtBearerOptions.Events = oktaWebApiOptions.JwtBearerEvents ?? new JwtBearerEvents();
jwtBearerOptions.SecurityTokenValidators.Clear();
jwtBearerOptions.SecurityTokenValidators.Add(new StrictSecurityTokenValidator());
jwtBearerOptions.BackchannelTimeout = oktaWebApiOptions.BackchannelTimeout;
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This library uses semantic versioning and follows Okta's [library version policy
|`Okta.AspNet.Abstractions`| 4.x | :warning: Retiring November 28th, 2023 | .NET Standard 2.0 and .NET Framework 4.5.2 or higher.|
|`Okta.AspNet`| 3.x | :heavy_check_mark: Stable | .NET Framework 4.6.2 |
|`Okta.AspNet`| 2.x | :warning: Retiring | .NET Framework 4.5.2 |
|`Okta.AspNetCore`| 4.x | :heavy_check_mark: Stable | .NET Core 3.x, .NET 5.0, .NET 6.0 and .NET 7.0 |
|`Okta.AspNetCore`| 4.x | :heavy_check_mark: Stable | .NET Core 3.x, .NET 5.0, .NET 6.0, .NET 7.0 and .NET 8.0 |
|`Okta.AspNetCore`| 3.x | :warning: Retiring | .NET Standard 2.0 and .NET Core 2.x |


Expand Down

0 comments on commit 2810d1d

Please sign in to comment.