Skip to content

Commit 9ed7325

Browse files
committed
Downgrade Identity.api version due to compatibility issues
Updated Test project version Fix issue Idsrv token
1 parent c601c3e commit 9ed7325

30 files changed

Lines changed: 225 additions & 169 deletions

File tree

docker-compose.override.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ services:
6161
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
6262
- UseCustomizationData=True
6363
- AzureServiceBusEnabled=False
64+
- GracePeriodTime=1
65+
- CheckUpdateTime=30000
6466
ports:
6567
- "5102:80"
6668

Lines changed: 3 additions & 3 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>netstandard1.5</TargetFramework>
55
<RootNamespace>Microsoft.eShopOnContainers.BuildingBlocks</RootNamespace>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="1.1.2" />
10-
<PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.4" />
10+
<PackageReference Include="StackExchange.Redis" Version="1.2.3" />
1111
</ItemGroup>
12-
12+
1313
</Project>

src/BuildingBlocks/HealthChecks/src/Microsoft.AspNetCore.HealthChecks/Microsoft.AspNetCore.HealthChecks.csproj

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

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

77
<ItemGroup>
88
<Compile Include="..\common\Guard.cs" Link="Internal\Guard.cs" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.1.2" />
1313
<ProjectReference Include="..\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />
1414
</ItemGroup>
1515

src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions.HealthChecks.SqlServer/Microsoft.Extensions.HealthChecks.SqlServer.csproj

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

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

77
<ItemGroup>
88
<Compile Include="..\common\Guard.cs" Link="Internal\Guard.cs" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
12+
<PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions.HealthChecks/Microsoft.Extensions.HealthChecks.csproj

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

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

77
<ItemGroup>
88
<Compile Include="..\common\Guard.cs" Link="Internal\Guard.cs" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
1313
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
1414
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
1515
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Basket.API.Infrastructure.Filters;
44
using Basket.API.IntegrationEvents.EventHandling;
55
using Basket.API.IntegrationEvents.Events;
6+
using Microsoft.AspNetCore.Authentication.JwtBearer;
67
using Microsoft.AspNetCore.Builder;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.Http;
@@ -25,6 +26,7 @@
2526
using Swashbuckle.AspNetCore.Swagger;
2627
using System;
2728
using System.Collections.Generic;
29+
using System.IdentityModel.Tokens.Jwt;
2830
using System.Threading.Tasks;
2931

3032
namespace Microsoft.eShopOnContainers.Services.Basket.API
@@ -50,23 +52,16 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
5052

5153
}).AddControllersAsServices();
5254

55+
ConfigureAuthService(services);
56+
5357
services.AddHealthChecks(checks =>
5458
{
5559
checks.AddValueTaskCheck("HTTP Endpoint", () => new ValueTask<IHealthCheckResult>(HealthCheckResult.Healthy("Ok")),
5660
TimeSpan.Zero //No cache for this HealthCheck, better just for demos
5761
);
5862
});
5963

60-
services.Configure<BasketSettings>(Configuration);
61-
62-
services.AddAuthentication()
63-
.AddJwtBearer(options =>
64-
{
65-
options.Authority = Configuration.GetValue<string>("IdentityUrl");
66-
options.Audience = "basket";
67-
options.RequireHttpsMetadata = false;
68-
69-
});
64+
services.Configure<BasketSettings>(Configuration);
7065

7166
//By connecting here we are making sure that our service
7267
//cannot start until redis is ready. This might slow down startup,
@@ -151,7 +146,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
151146
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
152147
services.AddTransient<IBasketRepository, RedisBasketRepository>();
153148
services.AddTransient<IIdentityService, IdentityService>();
154-
149+
155150
services.AddOptions();
156151

157152
var container = new ContainerBuilder();
@@ -167,7 +162,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
167162
{
168163
app.UseStaticFiles();
169164
app.UseCors("CorsPolicy");
170-
app.UseAuthentication();
165+
ConfigureAuth(app);
171166
app.UseMvcWithDefaultRoute();
172167

173168
app.UseSwagger()
@@ -181,6 +176,30 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
181176

182177
}
183178

179+
private void ConfigureAuthService(IServiceCollection services)
180+
{
181+
// prevent from mapping "sub" claim to nameidentifier.
182+
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
183+
184+
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
185+
186+
services.AddAuthentication(options =>
187+
{
188+
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
189+
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
190+
191+
}).AddJwtBearer(options =>
192+
{
193+
options.Authority = identityUrl;
194+
options.RequireHttpsMetadata = false;
195+
options.Audience = "basket";
196+
});
197+
}
198+
199+
protected virtual void ConfigureAuth(IApplicationBuilder app)
200+
{
201+
app.UseAuthentication();
202+
}
184203

185204
private void RegisterEventBus(IServiceCollection services)
186205
{

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,13 @@
3636

3737
public class Startup
3838
{
39-
public IConfigurationRoot Configuration { get; }
40-
41-
public Startup(IHostingEnvironment env)
39+
public Startup(IConfiguration configuration)
4240
{
43-
var builder = new ConfigurationBuilder()
44-
.SetBasePath(env.ContentRootPath)
45-
.AddJsonFile($"settings.json", optional: false, reloadOnChange: true)
46-
.AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true);
47-
48-
if (env.IsDevelopment())
49-
{
50-
builder.AddUserSecrets(typeof(Startup).GetTypeInfo().Assembly);
51-
}
52-
53-
builder.AddEnvironmentVariables();
54-
55-
Configuration = builder.Build();
41+
Configuration = configuration;
5642
}
5743

44+
public IConfiguration Configuration { get; }
45+
5846
public IServiceProvider ConfigureServices(IServiceCollection services)
5947
{
6048
// Add framework services.

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
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;
85
using IdentityModel;
9-
using IdentityServer4.Models;
6+
using IdentityServer4.Quickstart.UI.Models;
107
using IdentityServer4.Services;
11-
using IdentityServer4.Stores;
12-
using Microsoft.AspNetCore.Authentication;
13-
using Microsoft.AspNetCore.Authorization;
14-
using Microsoft.AspNetCore.Identity;
8+
using Microsoft.AspNetCore.Http.Authentication;
159
using Microsoft.AspNetCore.Mvc;
16-
using Microsoft.Extensions.Logging;
1710
using System;
11+
using System.Collections.Generic;
1812
using System.Linq;
1913
using System.Security.Claims;
2014
using System.Text.Encodings.Web;
2115
using System.Threading.Tasks;
22-
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;
2325

2426
namespace IdentityServer4.Quickstart.UI.Controllers
2527
{
@@ -38,12 +40,12 @@ public class AccountController : Controller
3840
private readonly UserManager<ApplicationUser> _userManager;
3941

4042
public AccountController(
41-
43+
4244
//InMemoryUserLoginService loginService,
4345
ILoginService<ApplicationUser> loginService,
4446
IIdentityServerInteractionService interaction,
4547
IClientStore clientStore,
46-
ILoggerFactory loggerFactory,
48+
ILoggerFactory loggerFactory,
4749
UserManager<ApplicationUser> userManager)
4850
{
4951
_loginService = loginService;
@@ -84,7 +86,7 @@ public async Task<IActionResult> Login(LoginViewModel model)
8486
var user = await _loginService.FindByUsername(model.Email);
8587
if (await _loginService.ValidateCredentials(user, model.Password))
8688
{
87-
AuthenticationProperties props = null;
89+
AuthenticationProperties props = null;
8890
if (model.RememberMe)
8991
{
9092
props = new AuthenticationProperties
@@ -192,16 +194,16 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
192194
try
193195
{
194196
// hack: try/catch to handle social providers that throw
195-
await HttpContext.SignOutAsync(idp, new AuthenticationProperties { RedirectUri = url });
197+
await HttpContext.Authentication.SignOutAsync(idp, new AuthenticationProperties { RedirectUri = url });
196198
}
197-
catch(Exception ex)
199+
catch (Exception ex)
198200
{
199201
_logger.LogCritical(ex.Message);
200202
}
201203
}
202204

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

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

220222
// set this so UI rendering sees an anonymous user
221223
HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());
@@ -238,7 +240,7 @@ public IActionResult ExternalLogin(string provider, string returnUrl)
238240
// start challenge and roundtrip the return URL
239241
var props = new AuthenticationProperties
240242
{
241-
RedirectUri = returnUrl,
243+
RedirectUri = returnUrl,
242244
Items = { { "scheme", provider } }
243245
};
244246
return new ChallengeResult(provider, props);
@@ -291,7 +293,8 @@ public async Task<IActionResult> Register(RegisterViewModel model, string return
291293
}
292294
}
293295

294-
if (returnUrl != null) {
296+
if (returnUrl != null)
297+
{
295298
if (HttpContext.User.Identity.IsAuthenticated)
296299
return Redirect(returnUrl);
297300
else

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

Lines changed: 30 additions & 8 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>netcoreapp2.0</TargetFramework>
5-
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
4+
<TargetFramework>netcoreapp1.1</TargetFramework>
5+
<RuntimeFrameworkVersion>1.1.2</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,8 +16,30 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
19-
<PackageReference Include="IdentityServer4" Version="2.0.0-preview3" />
20-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.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" />
2143
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="1.0.1" />
2244
<PackageReference Include="IdentityServer4.EntityFramework" Version="1.0.1" />
2345
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
@@ -30,9 +52,9 @@
3052

3153
<ItemGroup>
3254
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.4.337" />
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" />
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" />
3658
</ItemGroup>
3759

3860
<ItemGroup>

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

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

48
namespace Identity.API.Models

0 commit comments

Comments
 (0)