Skip to content

Commit 5230767

Browse files
chore: merge
.NET 8
2 parents 932fdd3 + f8eeb8e commit 5230767

File tree

21 files changed

+122
-90
lines changed

21 files changed

+122
-90
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
with:
2929
dotnet-version: 7.0.x
3030

31-
- name: Setup .NET Core 3.1
31+
- name: Setup .NET 8
3232
uses: actions/setup-dotnet@v3
3333
with:
34-
dotnet-version: 3.1.x
34+
dotnet-version: 8.0.x
3535

3636
- name: Restore dependencies
3737
run: dotnet restore

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
with:
2525
dotnet-version: 7.0.x
2626

27-
- name: Setup .NET Core 3.1
27+
- name: Setup .NET 8
2828
uses: actions/setup-dotnet@v3
2929
with:
30-
dotnet-version: 3.1.x
30+
dotnet-version: 8.0.x
3131

3232
- name: Restore dependencies
3333
run: dotnet restore

samples/1_AspNet.Default/AspNet.Default.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<IsPackable>false</IsPackable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="Bogus" Version="34.0.2" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
13-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.25.0" />
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1413
</ItemGroup>
1514

1615
<ItemGroup>

samples/2_AspNet.Store.EntityFramework/AspNet.Store.EntityFramework.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<IsPackable>false</IsPackable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="Bogus" Version="34.0.2" />
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
15-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
16-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
17-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.25.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
15+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
16+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1817
</ItemGroup>
1918

2019
<ItemGroup>

samples/2_AspNet.Store.EntityFramework/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
},
1111
"profiles": {
12-
"NetDevPack.Security.Jwt.AspNet.SymetricKey": {
12+
"AspNet.Store.EntityFramework": {
1313
"commandName": "Project",
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,

samples/2_AspNet.Store.EntityFramework/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ConnectionStrings": {
3-
//"DefaultConnection": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=jwks;Integrated Security=SSPI;"
4-
"DefaultConnection": "Data Source=localhost;Initial Catalog=jwks;User Id=sa; Password=@Password1;Connection Timeout=60;MultipleActiveResultSets=True;TrustServerCertificate=True"
3+
"DefaultConnection": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=jwks;Integrated Security=SSPI;"
4+
//"DefaultConnection": "Data Source=localhost;Initial Catalog=jwks;User Id=sa; Password=@Password1;Connection Timeout=60;MultipleActiveResultSets=True;TrustServerCertificate=True"
55
},
66
"Logging": {
77
"LogLevel": {

samples/3_IdentityServer4/AspNet.IdentityServer4.csproj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

8-
9-
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
10-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.0" />
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
1110
</ItemGroup>
12-
1311
<ItemGroup>
1412
<ProjectReference Include="..\..\src\NetDevPack.Security.Jwt.AspNetCore\NetDevPack.Security.Jwt.AspNetCore.csproj" />
1513
<ProjectReference Include="..\..\src\NetDevPack.Security.Jwt.IdentityServer4\NetDevPack.Security.Jwt.IdentityServer4.csproj" />
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
1111
<PackageReference Include="NetDevPack.Security.JwtExtensions" Version="7.0.0" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1313
</ItemGroup>
1414

1515
</Project>

samples/Microservice.Sample/Identity/Controllers/AuthController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ private async Task<string> GenerateAccessToken(string? email)
119119
identityClaims.AddClaim(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()));
120120

121121
var handler = new JwtSecurityTokenHandler();
122-
122+
var key = await _jwtService.GetCurrentSigningCredentials();
123123
var securityToken = handler.CreateToken(new SecurityTokenDescriptor
124124
{
125125
Issuer = "https://www.devstore.academy", // <- Your website
126126
Audience = "NetDevPack.Security.Jwt.AspNet",
127-
SigningCredentials = await _jwtService.GetCurrentSigningCredentials(),
127+
SigningCredentials = key,
128128
Subject = identityClaims,
129129
NotBefore = DateTime.UtcNow,
130130
Expires = DateTime.UtcNow.AddMinutes(60),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace Identity.Controllers
5+
{
6+
[ApiController]
7+
[Route("api/protected"), Authorize]
8+
public class ProtectedController : ControllerBase
9+
{
10+
[HttpGet]
11+
public IActionResult Get()
12+
{
13+
return Ok();
14+
}
15+
}
16+
}

samples/Microservice.Sample/Identity/Identity.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
88
<DockerfileContext>..\..\..\src</DockerfileContext>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
13-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
15-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
15+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

samples/Microservice.Sample/Identity/Program.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
using Identity.Data;
32
using Microsoft.AspNetCore.Authentication.JwtBearer;
43
using Microsoft.AspNetCore.Identity;
@@ -11,9 +10,34 @@
1110

1211
// Add services to the container.
1312
builder.Services.AddControllers();
14-
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
1513
builder.Services.AddEndpointsApiExplorer();
16-
builder.Services.AddSwaggerGen();
14+
builder.Services.AddSwaggerGen(c =>
15+
{
16+
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
17+
{
18+
Description = "Bearer {token}",
19+
Name = "Authorization",
20+
Scheme = "Bearer",
21+
BearerFormat = "JWT",
22+
In = ParameterLocation.Header,
23+
Type = SecuritySchemeType.ApiKey
24+
});
25+
26+
c.AddSecurityRequirement(new OpenApiSecurityRequirement
27+
{
28+
{
29+
new OpenApiSecurityScheme
30+
{
31+
Reference = new OpenApiReference
32+
{
33+
Type = ReferenceType.SecurityScheme,
34+
Id = "Bearer"
35+
}
36+
},
37+
new string[] { }
38+
}
39+
});
40+
});
1741

1842
builder.Services
1943
.AddJwksManager() // <- Use component

src/NetDevPack.Security.Jwt.AspNetCore/JwtPostConfigureOptions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ namespace NetDevPack.Security.Jwt.AspNetCore;
66
public class JwtPostConfigureOptions : IPostConfigureOptions<JwtBearerOptions>
77
{
88
private readonly IServiceProvider _serviceProvider;
9-
// private readonly MyCustomSecurityTokenValidator _tokenValidator; //example dependancy
109

1110
public JwtPostConfigureOptions(IServiceProvider serviceProvider)
1211
{
1312
_serviceProvider = serviceProvider;
1413
}
1514

16-
public void PostConfigure(string name, JwtBearerOptions options)
15+
public void PostConfigure(string? name, JwtBearerOptions options)
1716
{
17+
#if NET8_0_OR_GREATER
18+
options.TokenHandlers.Clear();
19+
options.TokenHandlers.Add(new JwtServiceValidationHandler(_serviceProvider));
20+
#else
1821
options.SecurityTokenValidators.Clear();
1922
options.SecurityTokenValidators.Add(new JwtServiceValidationHandler(_serviceProvider));
23+
#endif
2024
}
2125
}

src/NetDevPack.Security.Jwt.AspNetCore/NetDevPack.Security.Jwt.AspNetCore.csproj

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<Authors>Bruno Brito, Eduardo Pires</Authors>
@@ -21,16 +21,14 @@
2121
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
2222
</ItemGroup>
2323

24-
25-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
26-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.31" />
27-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
28-
</ItemGroup>
2924
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
30-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />
25+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.25" />
3126
</ItemGroup>
3227
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
33-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
28+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.14" />
29+
</ItemGroup>
30+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
31+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
3432
</ItemGroup>
3533

3634
<ItemGroup>

src/NetDevPack.Security.Jwt.Core/NetDevPack.Security.Jwt.Core.csproj

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<LangVersion>10.0</LangVersion>
77
<Authors>Bruno Brito</Authors>
@@ -16,24 +16,29 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.25.0" />
20-
<PackageReference Include="System.Text.Json" Version="7.0.1" />
19+
<PackageReference Include="System.Text.Json" Version="8.0.0" />
20+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
2121
</ItemGroup>
2222

2323
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
2424
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="2.2.0" />
2525
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.31" />
2626
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.31" />
2727
</ItemGroup>
28+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
29+
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="6.0.25" />
30+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
31+
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
32+
</ItemGroup>
2833
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
29-
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="7.0.5" />
34+
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="7.0.14" />
3035
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
3136
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
3237
</ItemGroup>
33-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
34-
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="6.0.16" />
35-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
36-
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
38+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
39+
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.0" />
40+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
3742
</ItemGroup>
3843

3944
<ItemGroup>

src/NetDevPack.Security.Jwt.Store.FileSystem/NetDevPack.Security.Jwt.Store.FileSystem.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
55
<LangVersion>10.0</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>

tests/NetDevPack.Security.Jwt.AspNetCoreTests/NetDevPack.Security.Jwt.AspNetCoreTests.csproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -10,15 +10,11 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="FluentAssertions" Version="6.11.0" />
14-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.5" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
16-
<PackageReference Include="xunit" Version="2.4.2" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
18-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19-
<PrivateAssets>all</PrivateAssets>
20-
</PackageReference>
21-
<PackageReference Include="coverlet.collector" Version="6.0.0">
13+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16+
<PackageReference Include="xunit" Version="2.6.2" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
2218
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2319
<PrivateAssets>all</PrivateAssets>
2420
</PackageReference>

tests/NetDevPack.Security.Jwt.Tests/JwtTests/JweTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public JweTests(WarmupInMemoryStore warmup)
4343
[InlineData(EncryptionAlgorithmKey.Aes256KW, EncryptionAlgorithmContent.Aes192CbcHmacSha384)]
4444
public void ShouldValidateJwe(string algorithm, string encryption)
4545
{
46-
46+
//var sKey = new SecurityKey();
4747
var key = new CryptographicKey(Algorithm.Create(algorithm).WithContentEncryption(encryption));
4848
var encryptingCredentials = new EncryptingCredentials(key, algorithm, encryption);
4949

0 commit comments

Comments
 (0)