Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 06972cc

Browse files
committed
ASP.Net Core 3
netcore 3 Net Standard 2.1 Known issues: * PostgreSQL bug: npgsql/efcore.pg#1069
1 parent 32ae1e1 commit 06972cc

40 files changed

Lines changed: 257 additions & 254 deletions

File tree

src/Backend/Jp.Application/Jp.Application.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="AutoMapper" Version="8.1.1" />
9-
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
8+
<PackageReference Include="AutoMapper" Version="9.0.0" />
9+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
1010
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" />
1111
</ItemGroup>
1212

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

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<PackageReference Include="mediatr" Version="7.0.0" />
9-
<PackageReference Include="FluentValidation" Version="8.4.0" />
9+
<PackageReference Include="FluentValidation" Version="8.5.0" />
1010
</ItemGroup>
1111

1212
</Project>

src/Backend/Jp.Domain/CommandHandlers/ClientCommandHandler.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using IdentityServer4.EntityFramework.Entities;
2-
using IdentityServer4.EntityFramework.Mappers;
1+
using Jp.Domain.Commands.Clients;
32
using Jp.Domain.Core.Bus;
43
using Jp.Domain.Core.Notifications;
54
using Jp.Domain.Events.Client;
@@ -10,7 +9,7 @@
109
using System.Linq;
1110
using System.Threading;
1211
using System.Threading.Tasks;
13-
using Jp.Domain.Commands.Clients;
12+
using IdentityServer4.EntityFramework.Mappers;
1413

1514
namespace Jp.Domain.CommandHandlers
1615
{
@@ -202,7 +201,7 @@ public async Task<bool> Handle(SaveClientPropertyCommand request, CancellationTo
202201
return false;
203202
}
204203
var property = request.ToEntiyTy(savedClient);
205-
204+
206205

207206
_clientPropertyRepository.Add(property);
208207

@@ -319,7 +318,7 @@ public async Task<bool> Handle(CopyClientCommand request, CancellationToken canc
319318
}
320319

321320
var copyOf = savedClient.ToModel();
322-
321+
323322
copyOf.ClientId = $"copy-of-{copyOf.ClientId}-{Guid.NewGuid().ToString().Replace("-", string.Empty)}";
324323
copyOf.ClientSecrets = new List<IdentityServer4.Models.Secret>();
325324
copyOf.ClientName = "Copy of " + copyOf.ClientName;

src/Backend/Jp.Domain/Commands/Clients/SaveClientCommand.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using IdentityServer4.EntityFramework.Mappers;
32
using IdentityServer4.Models;
43
using Jp.Domain.Validations.Client;
@@ -14,7 +13,7 @@ public class SaveClientCommand : ClientCommand
1413
public SaveClientCommand(string clientId, string name, string clientUri, string logoUri, string description,
1514
ClientType clientType, string postLogoutUri)
1615
{
17-
this.Client = new IdentityServer4.Models.Client()
16+
this.Client = new Client()
1817
{
1918
ClientId = clientId,
2019
ClientName = name,
@@ -43,13 +42,12 @@ private void PrepareClientTypeForNewClient()
4342
break;
4443
case ClientType.WebImplicit:
4544
ConfigureWebImplicit();
46-
4745
break;
4846
case ClientType.WebHybrid:
4947
ConfigureWebHybrid();
5048
break;
5149
case ClientType.Spa:
52-
ConfigureSpa();
50+
ConfigureWebHybrid();
5351
break;
5452
case ClientType.Native:
5553
ConfigureNative();
@@ -60,7 +58,7 @@ private void PrepareClientTypeForNewClient()
6058

6159
break;
6260
default:
63-
throw new ArgumentOutOfRangeException();
61+
throw new ArgumentOutOfRangeException(nameof(ClientType));
6462
}
6563
}
6664

@@ -72,36 +70,31 @@ public override bool IsValid()
7270

7371
private void ConfigureDevice()
7472
{
75-
Client.AllowedGrantTypes = GrantTypes.DeviceFlow;
73+
Client.AllowedGrantTypes.Add(GrantType.DeviceFlow);
7674
Client.RequireClientSecret = false;
7775
Client.AllowOfflineAccess = true;
7876
}
7977

8078
private void ConfigureWebImplicit()
8179
{
82-
Client.AllowedGrantTypes = GrantTypes.Implicit;
80+
Client.AllowedGrantTypes.Add(GrantType.Implicit);
8381
Client.AllowAccessTokensViaBrowser = true;
8482
}
8583

8684
private void ConfigureWebHybrid()
8785
{
88-
Client.AllowedGrantTypes = GrantTypes.Hybrid;
89-
}
90-
91-
private void ConfigureSpa()
92-
{
93-
Client.AllowedGrantTypes = GrantTypes.Implicit;
94-
Client.AllowAccessTokensViaBrowser = true;
86+
Client.AllowedGrantTypes.Add(GrantType.Hybrid);
9587
}
9688

9789
private void ConfigureNative()
9890
{
99-
Client.AllowedGrantTypes = GrantTypes.Hybrid;
91+
Client.AllowedGrantTypes.Add(GrantType.Hybrid);
10092
}
10193

10294
private void ConfigureMachine()
10395
{
104-
Client.AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials;
96+
Client.AllowedGrantTypes.Add(GrantType.ResourceOwnerPassword);
97+
Client.AllowedGrantTypes.Add(GrantType.ClientCredentials);
10598
}
10699
}
107100
}

src/Backend/Jp.Domain/Commands/User/ResetPasswordCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace Jp.Domain.Commands.User
44
{
55
public class ResetPasswordCommand : UserCommand
66
{
7-
public string Code { get; }
8-
97
public ResetPasswordCommand(string password, string confirmPassword, string code, string email)
108
{
119
Password = password;

src/Backend/Jp.Domain/Interfaces/IClientRepository.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
1+
using IdentityServer4.EntityFramework.Entities;
32
using System.Threading.Tasks;
4-
using IdentityServer4.EntityFramework.Entities;
53

64
namespace Jp.Domain.Interfaces
75
{
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
@@ -10,8 +10,7 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="FluentValidation" Version="8.4.0" />
14-
<PackageReference Include="IdentityServer4.EntityFramework" Version="2.5.0" />
13+
<PackageReference Include="IdentityServer4.EntityFramework.Storage" Version="3.0.1" />
1514
</ItemGroup>
1615

1716
</Project>

src/Backend/Jp.Infra.CrossCutting.Bus/Jp.Infra.CrossCutting.Bus.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-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

src/Backend/Jp.Infra.CrossCutting.Database/DbSettingsConfig.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using Jp.Infra.CrossCutting.Identity.Context;
1+
using IdentityModel;
2+
using Jp.Infra.CrossCutting.Identity.Context;
23
using Jp.Infra.CrossCutting.Identity.Entities.Identity;
34
using Jp.Infra.Data.MySql.Configuration;
45
using Jp.Infra.Data.PostgreSQL.Configuration;
56
using Jp.Infra.Data.Sql.Configuration;
67
using Jp.Infra.Data.Sqlite.Configuration;
7-
using Microsoft.AspNetCore.Identity;
88
using Microsoft.Extensions.Configuration;
99
using Microsoft.Extensions.DependencyInjection;
1010

1111
namespace Jp.Infra.CrossCutting.Database
1212
{
1313
public static class DbSettingsConfig
1414
{
15-
public static void ConfigureDatabase(this IServiceCollection services, IConfiguration configuration)
15+
public static void AddAuthentication(this IServiceCollection services, IConfiguration configuration)
1616
{
1717
var database = configuration["ApplicationSettings:DatabaseType"].ToUpper();
1818
var connString = configuration.GetConnectionString("SSOConnection");
@@ -32,9 +32,25 @@ public static void ConfigureDatabase(this IServiceCollection services, IConfigur
3232
break;
3333
}
3434

35-
services.AddIdentity<UserIdentity, UserIdentityRole>()
36-
.AddEntityFrameworkStores<ApplicationIdentityContext>()
37-
.AddDefaultTokenProviders();
35+
services.AddIdentity<UserIdentity, UserIdentityRole>(options =>
36+
{
37+
options.ClaimsIdentity.RoleClaimType = JwtClaimTypes.Role;
38+
options.ClaimsIdentity.UserIdClaimType = JwtClaimTypes.Name;
39+
options.SignIn.RequireConfirmedAccount = true;
40+
options.User.RequireUniqueEmail = true;
41+
42+
// NIST Password best practices: https://pages.nist.gov/800-63-3/sp800-63b.html#appA
43+
options.Lockout.MaxFailedAccessAttempts = 10;
44+
options.Password.RequiredLength = 8;
45+
options.Password.RequireDigit = false;
46+
options.Password.RequireLowercase = false;
47+
options.Password.RequireDigit = false;
48+
options.Password.RequireNonAlphanumeric = false;
49+
options.Password.RequireUppercase = false;
50+
options.Password.RequiredUniqueChars = 0;
51+
52+
})
53+
.AddEntityFrameworkStores<ApplicationIdentityContext>();
3854
}
3955

4056
public static void ConfigureIdentityServerDatabase(this IIdentityServerBuilder builder, IConfiguration configuration)

src/Backend/Jp.Infra.CrossCutting.Database/Jp.Infra.CrossCutting.Database.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
9-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
8+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1313
</PackageReference>

0 commit comments

Comments
 (0)