Skip to content

Commit cd78d98

Browse files
Unai Zorrilla CastroUnai Zorrilla Castro
authored andcommitted
Updated Identity.API to preview version of IdentityServer4, Fix breaking changes. Not well tested
1 parent acefa64 commit cd78d98

6 files changed

Lines changed: 47 additions & 81 deletions

File tree

src/Services/Identity/Identity.API/Controllers/AccountController.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

5+
using Identity.API.Models;
6+
using Identity.API.Models.AccountViewModels;
7+
using Identity.API.Services;
58
using IdentityModel;
6-
using IdentityServer4.Quickstart.UI.Models;
9+
using IdentityServer4.Models;
710
using IdentityServer4.Services;
8-
using Microsoft.AspNetCore.Http.Authentication;
11+
using IdentityServer4.Stores;
12+
using Microsoft.AspNetCore.Authentication;
13+
using Microsoft.AspNetCore.Authorization;
14+
using Microsoft.AspNetCore.Identity;
915
using Microsoft.AspNetCore.Mvc;
16+
using Microsoft.Extensions.Logging;
1017
using System;
11-
using System.Collections.Generic;
1218
using System.Linq;
1319
using System.Security.Claims;
1420
using System.Text.Encodings.Web;
1521
using System.Threading.Tasks;
16-
using IdentityServer4.Models;
17-
using IdentityServer4.Stores;
18-
using Identity.API.Services;
19-
using Identity.API.Models;
20-
using Microsoft.Extensions.Logging;
21-
using Microsoft.AspNetCore.Authorization;
22-
using Identity.API.Models.AccountViewModels;
23-
using Microsoft.AspNetCore.Identity;
24-
using Microsoft.AspNetCore.Authentication;
22+
2523

2624
namespace IdentityServer4.Quickstart.UI.Controllers
2725
{
@@ -194,7 +192,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
194192
try
195193
{
196194
// hack: try/catch to handle social providers that throw
197-
await HttpContext.Authentication.SignOutAsync(idp, new AuthenticationProperties { RedirectUri = url });
195+
await HttpContext.SignOutAsync(idp, new AuthenticationProperties { RedirectUri = url });
198196
}
199197
catch(Exception ex)
200198
{
@@ -203,7 +201,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
203201
}
204202

205203
// delete authentication cookie
206-
await HttpContext.Authentication.SignOutAsync();
204+
await HttpContext.SignOutAsync();
207205

208206
// set this so UI rendering sees an anonymous user
209207
HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());
@@ -217,7 +215,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
217215
public async Task<IActionResult> DeviceLogOut(string redirectUrl)
218216
{
219217
// delete authentication cookie
220-
await HttpContext.Authentication.SignOutAsync();
218+
await HttpContext.SignOutAsync();
221219

222220
// set this so UI rendering sees an anonymous user
223221
HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());

src/Services/Identity/Identity.API/Identity.API.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
5-
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
66
<UserSecretsId>aspnet-eShopOnContainers.Identity-90487118-103c-4ff0-b9da-e5e26f7ab0c5</UserSecretsId>
7-
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
7+
<!--<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>-->
88
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
99
</PropertyGroup>
1010

@@ -16,30 +16,8 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
19-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
20-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.2" />
21-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.2" />
22-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
23-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
24-
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.2" />
25-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.2" />
26-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
27-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
28-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2">
30-
<PrivateAssets>All</PrivateAssets>
31-
</PackageReference>
32-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1">
33-
<PrivateAssets>All</PrivateAssets>
34-
</PackageReference>
35-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
36-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
37-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
38-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
39-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
40-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
41-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
42-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.1.0" />
19+
<PackageReference Include="IdentityServer4" Version="2.0.0-preview3" />
20+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
4321
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="1.0.1" />
4422
<PackageReference Include="IdentityServer4.EntityFramework" Version="1.0.1" />
4523
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
@@ -52,9 +30,9 @@
5230

5331
<ItemGroup>
5432
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.4.337" />
55-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
56-
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0-msbuild3-final" />
57-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
33+
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
34+
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
35+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
5836
</ItemGroup>
5937

6038
<ItemGroup>

src/Services/Identity/Identity.API/Models/ApplicationUser.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1+
using Microsoft.AspNetCore.Identity;
62
using System.ComponentModel.DataAnnotations;
73

84
namespace Identity.API.Models
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Logging;
24
using System.IO;
35

46
namespace eShopOnContainers.Identity
@@ -7,15 +9,19 @@ public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = new WebHostBuilder()
11-
.UseKestrel()
12-
.UseHealthChecks("/hc")
12+
BuildWebHost(args).Run();
13+
}
14+
15+
public static IWebHost BuildWebHost(string[] args) =>
16+
WebHost.CreateDefaultBuilder(args)
1317
.UseContentRoot(Directory.GetCurrentDirectory())
14-
.UseIISIntegration()
18+
.UseHealthChecks("/hc")
1519
.UseStartup<Startup>()
16-
.Build();
17-
18-
host.Run();
19-
}
20+
.ConfigureLogging((hostingContext, builder) =>
21+
{
22+
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
23+
builder.AddConsole();
24+
builder.AddDebug();
25+
}).Build();
2026
}
2127
}

src/Services/Identity/Identity.API/Startup.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Identity.API.Certificate;
1+
using Autofac;
2+
using Autofac.Extensions.DependencyInjection;
3+
using Identity.API.Certificate;
24
using Identity.API.Configuration;
35
using Identity.API.Data;
46
using Identity.API.Models;
@@ -9,16 +11,12 @@
911
using Microsoft.AspNetCore.Builder;
1012
using Microsoft.AspNetCore.Hosting;
1113
using Microsoft.AspNetCore.Identity;
12-
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1314
using Microsoft.EntityFrameworkCore;
1415
using Microsoft.eShopOnContainers.BuildingBlocks;
1516
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
1617
using Microsoft.Extensions.Configuration;
1718
using Microsoft.Extensions.DependencyInjection;
1819
using Microsoft.Extensions.HealthChecks;
19-
using Identity.API.Certificate;
20-
using Autofac.Extensions.DependencyInjection;
21-
using Autofac;
2220
using Microsoft.Extensions.Logging;
2321
using System;
2422
using System.Collections.Generic;
@@ -30,24 +28,13 @@ namespace eShopOnContainers.Identity
3028
{
3129
public class Startup
3230
{
33-
public Startup(IHostingEnvironment env)
31+
public Startup(IConfiguration configuration)
3432
{
35-
var builder = new ConfigurationBuilder()
36-
.SetBasePath(env.ContentRootPath)
37-
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
38-
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
39-
40-
if (env.IsDevelopment())
41-
{
42-
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
43-
builder.AddUserSecrets<Startup>();
44-
}
45-
46-
builder.AddEnvironmentVariables();
47-
Configuration = builder.Build();
33+
Configuration = configuration;
4834
}
4935

50-
public IConfigurationRoot Configuration { get; }
36+
public IConfiguration Configuration { get; }
37+
5138

5239
// This method gets called by the runtime. Use this method to add services to the container.
5340
public IServiceProvider ConfigureServices(IServiceCollection services)
@@ -136,9 +123,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
136123
await next();
137124
});
138125

139-
app.UseIdentity();
126+
140127

141128
// Adds IdentityServer
129+
app.UseAuthentication();
130+
142131
app.UseIdentityServer();
143132

144133
app.UseMvc(routes =>

src/Web/WebMVC/WebMVC.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
<ItemGroup>
3939
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
40-
<!--<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.1.4" />-->
4140
</ItemGroup>
4241

4342
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">

0 commit comments

Comments
 (0)