Skip to content

Commit

Permalink
Upgrade to .NET Core 3.1 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Dec 4, 2019
1 parent a809d37 commit 0fe7ea8
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 29 deletions.
9 changes: 7 additions & 2 deletions IdentityServer/IdentityServer.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="IdentityServer4" Version="2.3.0" />
<PackageReference Include="ServiceStack.Common" Version="5.*" />

<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />

<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.0" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions IdentityServer/Quickstart/Home/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@


using IdentityServer4.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

Expand All @@ -16,10 +17,10 @@ namespace IdentityServer
public class HomeController : Controller
{
private readonly IIdentityServerInteractionService _interaction;
private readonly IHostingEnvironment _environment;
private readonly IWebHostEnvironment _environment;
private readonly ILogger _logger;

public HomeController(IIdentityServerInteractionService interaction, IHostingEnvironment environment, ILogger<HomeController> logger)
public HomeController(IIdentityServerInteractionService interaction, IWebHostEnvironment environment, ILogger<HomeController> logger)
{
_interaction = interaction;
_environment = environment;
Expand Down
7 changes: 4 additions & 3 deletions IdentityServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
Expand All @@ -23,17 +24,17 @@ namespace IdentityServer
public class Startup
{
private IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; }
public IWebHostEnvironment Environment { get; }

public Startup(IConfiguration configuration, IHostingEnvironment environment)
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Configuration = configuration;
Environment = environment;
}

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);

var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
Expand Down
5 changes: 3 additions & 2 deletions MyApp.Api/MyApp.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>MyApp.Api</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0" />
<PackageReference Include="ServiceStack" Version="5.*" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions MyApp.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using ServiceStack;

namespace MyApp.Api
{
Expand Down
10 changes: 5 additions & 5 deletions MyApp.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace MyApp.Api
{
public class Startup
{
public IConfiguration Configuration { get; }
public IConfiguration Configuration { get; set; }
public Startup(IConfiguration configuration) => Configuration = configuration;

public void ConfigureServices(IServiceCollection services)
public new void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
services.AddMvcCore(options => options.EnableEndpointRouting = false)
.AddAuthorization()
.AddJsonFormatters();
.AddNewtonsoftJson();

services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options => {
Expand All @@ -32,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
});
}

public void Configure(IApplicationBuilder app)
public new void Configure(IApplicationBuilder app)
{
app.UseAuthentication();

Expand Down
8 changes: 4 additions & 4 deletions MyApp.Tests/MyApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
</PropertyGroup>
Expand All @@ -10,9 +10,9 @@
<ProjectReference Include="..\MyApp.ServiceInterface\MyApp.ServiceInterface.csproj" />
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />

<PackageReference Include="NUnit" Version="3.10.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.*" />
<PackageReference Include="NUnit" Version="3.12.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.*" />
<PackageReference Include="ServiceStack" Version="5.*" />
<PackageReference Include="ServiceStack.Kestrel" Version="5.*" />
<PackageReference Include="IdentityModel" Version="3.10.0" />
Expand Down
7 changes: 5 additions & 2 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>MyApp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ServiceStack" Version="5.*" />

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

<ItemGroup>
Expand Down
18 changes: 11 additions & 7 deletions MyApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using System.Security.Claims;
using System.Text.Json;
using System.Threading.Tasks;
using Funq;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
Expand All @@ -17,17 +19,18 @@

namespace MyApp
{
public class Startup : ModularStartup
public class Startup
{
public Startup(IConfiguration configuration) : base(configuration){}
public IConfiguration Configuration { get; set; }
public Startup(IConfiguration configuration) => Configuration = configuration;

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public new void ConfigureServices(IServiceCollection services)
{
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

services.AddMvc();
services.AddMvc(options => options.EnableEndpointRouting = false);

services.AddAuthentication(options =>
{
Expand Down Expand Up @@ -74,7 +77,7 @@ public Startup(IConfiguration configuration) : base(configuration){}
});
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand Down Expand Up @@ -153,9 +156,10 @@ public class AdminRolesClaimAction : ClaimAction
string[] AdminRoles { get; }
public AdminRolesClaimAction(params string[] adminRoles) : base("role", null) => AdminRoles = adminRoles;

public override void Run(JObject userData, ClaimsIdentity identity, string issuer)
// public override void Run(JObject userData, ClaimsIdentity identity, string issuer)
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
if (!HasAdminRole(userData)) return;
if (!HasAdminRole(JObject.Parse(userData.GetRawText()))) return;
foreach (var role in AdminRoles)
{
identity.AddClaim(new Claim("role", role));
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mvcidentityserver

.NET Core 2.1 MVC Website integrated with IdentityServer4 Auth and ServiceStack
.NET Core 3.1 MVC Website integrated with IdentityServer4 Auth and ServiceStack

![](https://raw.githubusercontent.com/ServiceStack/Assets/master/csharp-templates/mvcidentityserver.png)

Expand Down

0 comments on commit 0fe7ea8

Please sign in to comment.