Skip to content

Commit

Permalink
Add support for .NET 6 (#188)
Browse files Browse the repository at this point in the history
* Update `Microsoft.AspNetCore.Authentication.JwtBearer` and `Microsoft.AspNetCore.Authentication.OpenIdConnect` dependencies to the latest version of each target framework supported by the SDK. (#199)

Co-authored-by: Laura Rodriguez <[email protected]>
  • Loading branch information
andriizhegurov-okta and laura-rodriguez authored Mar 30, 2022
1 parent bc09cf5 commit 75af987
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 71 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ sudo: required
dist: xenial
dotnet: 5.0
before_install:
- sudo apt-get install dotnet-sdk-6.0
- sudo apt-get install dotnet-sdk-3.1
script:
- ./build.sh


2 changes: 1 addition & 1 deletion Okta.AspNet.Test/Okta.AspNet.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="FluentAssertions" Version="5.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NSubstitute" Version="4.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
Expand All @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
12 changes: 3 additions & 9 deletions 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>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -11,14 +11,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"/>
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
95 changes: 72 additions & 23 deletions Okta.AspNetCore.Test/OpenIdConnectOptionsHelperShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,40 @@ public class OpenIdConnectOptionsHelperShould
[Theory]
[InlineData(true)]
[InlineData(false)]
public void SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
public async Task SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
{
var mockTokenValidatedEvent = Substitute.For<Func<OpenIdConnectTokenValidatedContext, Task>>();
var mockUserInfoReceivedEvent = Substitute.For<Func<UserInformationReceivedContext, Task>>();
var mockOktaExceptionEvent = Substitute.For<Func<RemoteFailureContext, Task>>();
var mockAuthenticationFailedEvent = Substitute.For<Func<OpenIdConnectAuthenticationFailedContext, Task>>();
var mockRedirectToIdentityProvider = Substitute.For<Func<RedirectContext, Task>>();
bool invoked = false;

Func<OpenIdConnectTokenValidatedContext, Task> mockTokenValidatedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<UserInformationReceivedContext, Task> mockUserInfoReceivedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<RemoteFailureContext, Task> mockOktaExceptionEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<OpenIdConnectAuthenticationFailedContext, Task> mockAuthenticationFailedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<RedirectContext, Task> mockRedirectToIdentityProvider = context =>
{
invoked = true;
return Task.CompletedTask;
};

var mockHttpHandler = Substitute.For<HttpMessageHandler>();

var oktaMvcOptions = new OktaMvcOptions
Expand Down Expand Up @@ -88,30 +115,51 @@ public void SetOpenIdConnectsOptions(bool getClaimsFromUserInfoEndpoint)
oidcOptions.CallbackPath.Value.Should().Be(oktaMvcOptions.CallbackPath);

// Check the event was call once with a null parameter
oidcOptions.Events.OnTokenValidated(null);
mockTokenValidatedEvent.Received(1).Invoke(null);
oidcOptions.Events.OnAuthenticationFailed(null);
mockAuthenticationFailedEvent.Received(1).Invoke(null);
oidcOptions.Events.OnRemoteFailure(null);
mockOktaExceptionEvent.Received(1).Invoke(null);
oidcOptions.Events.OnRedirectToIdentityProvider(null);
mockRedirectToIdentityProvider.Received(1).Invoke(null);
await oidcOptions.Events.OnTokenValidated(default);
invoked.Should().BeTrue();
invoked = false;

await oidcOptions.Events.OnAuthenticationFailed(default);
invoked.Should().BeTrue();
invoked = false;


await oidcOptions.Events.OnRemoteFailure(default);
invoked.Should().BeTrue();
invoked = false;


await oidcOptions.Events.OnRedirectToIdentityProvider(default);
invoked.Should().BeTrue();
invoked = false;

// UserInfo event is mapped only when GetClaimsFromUserInfoEndpoint = true
if (oidcOptions.GetClaimsFromUserInfoEndpoint)
{
// Check the event was call once with a null parameter
oidcOptions.Events.OnUserInformationReceived(null);
mockUserInfoReceivedEvent.Received(1).Invoke(null);
await oidcOptions.Events.OnUserInformationReceived(default);
invoked.Should().BeTrue();
invoked = false;
}
}

[Fact]
public void SetJwtBearerOptions()
public async Task SetJwtBearerOptions()
{
var mockTokenValidatedEvent = Substitute.For<Func<JwtTokenValidatedContext, Task>>();
var mockAuthenticationFailedEvent = Substitute.For<Func<JwtAuthenticationFailedContext, Task>>();
var mockHttpHandler = Substitute.For<HttpMessageHandler>();
bool invoked = false;

Func<JwtTokenValidatedContext, Task> mockTokenValidatedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

Func<JwtAuthenticationFailedContext, Task> mockAuthenticationFailedEvent = context =>
{
invoked = true;
return Task.CompletedTask;
};

var oktaWebApiOptions = new OktaWebApiOptions
{
Expand All @@ -136,10 +184,11 @@ public void SetJwtBearerOptions()
jwtBearerOptions.BackchannelTimeout.Should().Be(TimeSpan.FromMinutes(5));
((DelegatingHandler)jwtBearerOptions.BackchannelHttpHandler).InnerHandler.Should().Be(mockHttpHandler);

jwtBearerOptions.Events.OnTokenValidated(null);
mockTokenValidatedEvent.Received().Invoke(null);
jwtBearerOptions.Events.OnAuthenticationFailed(null);
mockAuthenticationFailedEvent.Received().Invoke(null);
await jwtBearerOptions.Events.OnTokenValidated(default);
invoked.Should().BeTrue();
invoked = false;
await jwtBearerOptions.Events.OnAuthenticationFailed(default);
invoked.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 7 additions & 0 deletions Okta.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
Running changelog of releases since `3.2.0`

## v4.1.0

### Features

- Add support for .NET 6.0 framework
- Update `Microsoft.AspNetCore.Authentication.JwtBearer` and `Microsoft.AspNetCore.Authentication.OpenIdConnect` dependencies to the latest version of each target framework supported by the SDK. (#199)

## v4.0.0

### Features
Expand Down
69 changes: 40 additions & 29 deletions Okta.AspNetCore/Okta.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<PropertyGroup>
<Description>Official Okta middleware for ASP.NET Core 3.0+. Easily add authentication and authorization to ASP.NET Core applications.</Description>
<Copyright>(c) 2020 Okta, Inc.</Copyright>
<VersionPrefix>4.0.0</VersionPrefix>
<Authors>Okta, Inc.</Authors>
<AssemblyName>Okta.AspNetCore</AssemblyName>
<PackageId>Okta.AspNetCore</PackageId>
<PackageTags>okta,token,authentication,authorization</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/okta/okta-sdk-dotnet/master/icon.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/okta/okta-aspnet</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/okta/okta-aspnet</RepositoryUrl>
</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>
<VersionPrefix>4.1.0</VersionPrefix>
<Authors>Okta, Inc.</Authors>
<AssemblyName>Okta.AspNetCore</AssemblyName>
<PackageId>Okta.AspNetCore</PackageId>
<PackageTags>okta,token,authentication,authorization</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/okta/okta-sdk-dotnet/master/icon.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/okta/okta-aspnet</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/okta/okta-aspnet</RepositoryUrl>
<Version>4.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Okta.AspNet.Abstractions\Okta.AspNet.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.23" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.23" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<AdditionalFiles Include="..\stylecop.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.3" />
</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" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Okta.AspNet.Abstractions\Okta.AspNet.Abstractions.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ We also publish these other libraries for .NET:

This library uses semantic versioning and follows Okta's [library version policy](https://developer.okta.com/code/library-versions/).

:heavy_check_mark: The current stable major version series is: 1.x
:heavy_check_mark: The current stable major version series is: 4.x for Okta.AspNetCore and 2.x for Okta.AspNet.

|Package| Version | Status | Compatibility|
| ------- | ------- | ------------------------- | ----------------------- |
|`Okta.AspNet.Abstractions`| 4.x | heavy_check_mark: Stable | .NET Standard 2.0 and .NET Framework 4.5.2 or higher.|
|`Okta.AspNet.Abstractions`| 3.x | :warning: Retiring | .NET Standard 2.0 and .NET Framework 4.5.2 or higher.|
|`Okta.AspNet`| 2.x | :heavy_check_mark: Stable | .NET Framework 4.5.2 |
|`Okta.AspNet`| 1.x | :warning: Retiring | .NET Framework 4.5.2 |
|`Okta.AspNetCore`| 4.x | :heavy_check_mark: Stable | .NET Core 3.x and .NET 5.0 |
|`Okta.AspNetCore`| 4.x | :heavy_check_mark: Stable | .NET Core 3.x, .NET 5.0 and .NET 6.0 |
|`Okta.AspNetCore`| 3.x | :warning: Retiring | .NET Standard 2.0 and .NET Core 2.x |


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": "5.0.301",
"version": "6.0.0",
"rollForward": "latestMajor"
}
}

0 comments on commit 75af987

Please sign in to comment.