Skip to content

Commit 27b59e8

Browse files
author
Feras Taleb
committed
Upgrade IdentityMicroservice Project from .NET Core 2.2 to .NET Core 3.1
1 parent b2bff36 commit 27b59e8

6 files changed

Lines changed: 919 additions & 23 deletions

File tree

‎IdentityMicroservice/Config.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static IEnumerable<Client> GetClients()
3939
{
4040
ClientId = "webclient",
4141
ClientName = "Web Client",
42-
42+
RequireConsent = false,
4343
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
4444
ClientSecrets = { new Secret("49C1A7E1-0C79-4A89-A3D6-A37998FB86B0".Sha256()) },
4545

@@ -57,7 +57,7 @@ public static IEnumerable<Client> GetClients()
5757
ClientId = "spaclient",
5858
ClientName = "SPA Client",
5959
ClientUri = "https://localhost:5003",
60-
60+
RequireConsent = false,
6161
AllowedGrantTypes = GrantTypes.Code,
6262
RequirePkce = true,
6363
RequireClientSecret = false,
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Serilog" Version="2.8.0" />
9-
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
8+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.0" />
10+
<PackageReference Include="Serilog" Version="2.9.0" />
11+
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
1012
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
11-
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
13+
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
1214

13-
<PackageReference Include="IdentityServer4" Version="2.4.0" />
14-
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.4.0" />
15+
<PackageReference Include="IdentityServer4" Version="3.1.0" />
16+
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.0" />
1517

16-
<PackageReference Include="Microsoft.AspNetCore.App" />
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
18-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" PrivateAssets="all">
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0" PrivateAssets="all">
1920
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2021
</PackageReference>
21-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
22+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" PrivateAssets="All" />
2223
</ItemGroup>
2324
</Project>

‎IdentityMicroservice/Quickstart/Home/HomeController.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace IdentityServer4.Quickstart.UI
1616
public class HomeController : Controller
1717
{
1818
private readonly IIdentityServerInteractionService _interaction;
19-
private readonly IHostingEnvironment _environment;
19+
private readonly IWebHostEnvironment _environment;
2020
private readonly ILogger _logger;
2121

22-
public HomeController(IIdentityServerInteractionService interaction, IHostingEnvironment environment, ILogger<HomeController> logger)
22+
public HomeController(IIdentityServerInteractionService interaction, IWebHostEnvironment environment, ILogger<HomeController> logger)
2323
{
2424
_interaction = interaction;
2525
_environment = environment;
@@ -28,7 +28,7 @@ public HomeController(IIdentityServerInteractionService interaction, IHostingEnv
2828

2929
public IActionResult Index()
3030
{
31-
if (_environment.IsDevelopment())
31+
if (_environment.EnvironmentName == "Development")
3232
{
3333
// only show in development
3434
return View();
@@ -51,7 +51,7 @@ public async Task<IActionResult> Error(string errorId)
5151
{
5252
vm.Error = message;
5353

54-
if (!_environment.IsDevelopment())
54+
if (_environment.EnvironmentName != "Development")
5555
{
5656
// only show in development
5757
message.ErrorDescription = null;

‎IdentityMicroservice/Startup.cs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace IdentityMicroservice
1717
public class Startup
1818
{
1919
public IConfiguration Configuration { get; }
20-
public IHostingEnvironment Environment { get; }
20+
public IWebHostEnvironment Environment { get; }
2121

22-
public Startup(IConfiguration configuration, IHostingEnvironment environment)
22+
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
2323
{
2424
Configuration = configuration;
2525
Environment = environment;
@@ -36,7 +36,8 @@ public void ConfigureServices(IServiceCollection services)
3636
.AddEntityFrameworkStores<ApplicationDbContext>()
3737
.AddDefaultTokenProviders();
3838

39-
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
39+
//services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
40+
services.AddControllersWithViews();
4041

4142
services.Configure<IISOptions>(iis =>
4243
{
@@ -57,7 +58,7 @@ public void ConfigureServices(IServiceCollection services)
5758
.AddInMemoryClients(Config.GetClients())
5859
.AddAspNetIdentity<ApplicationUser>();
5960

60-
if (Environment.IsDevelopment())
61+
if (Environment.EnvironmentName == "Development")
6162
{
6263
// Block 3:
6364
// Adding Developer Signing Credential, This will generate tempkey.rsa file
@@ -82,7 +83,7 @@ public void ConfigureServices(IServiceCollection services)
8283

8384
public void Configure(IApplicationBuilder app)
8485
{
85-
if (Environment.IsDevelopment())
86+
if (Environment.EnvironmentName == "Development")
8687
{
8788
app.UseDeveloperExceptionPage();
8889
app.UseDatabaseErrorPage();
@@ -93,11 +94,19 @@ public void Configure(IApplicationBuilder app)
9394
}
9495

9596
app.UseStaticFiles();
97+
app.UseRouting();
9698
// Block 4:
9799
// UseIdentityServer include a call to UseAuthentication
98100
app.UseIdentityServer();
101+
app.UseAuthorization();
99102

100-
app.UseMvcWithDefaultRoute();
103+
//app.UseMvcWithDefaultRoute();
104+
app.UseEndpoints(endpoints =>
105+
{
106+
endpoints.MapControllerRoute(
107+
name: "default",
108+
pattern: "{controller=Home}/{action=Index}/{id?}");
109+
});
101110
}
102111
}
103112
}

0 commit comments

Comments
 (0)