Skip to content

Commit 248a3ac

Browse files
committed
Merge branch 'dev' into eShopOnServiceFabric-Win
2 parents de9b655 + 4e12176 commit 248a3ac

20 files changed

Lines changed: 728 additions & 841 deletions

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
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;
2522

2623
namespace IdentityServer4.Quickstart.UI.Controllers
2724
{
@@ -36,7 +33,7 @@ public class AccountController : Controller
3633
private readonly ILoginService<ApplicationUser> _loginService;
3734
private readonly IIdentityServerInteractionService _interaction;
3835
private readonly IClientStore _clientStore;
39-
private readonly ILogger _logger;
36+
private readonly ILogger<AccountController> _logger;
4037
private readonly UserManager<ApplicationUser> _userManager;
4138

4239
public AccountController(
@@ -45,13 +42,13 @@ public AccountController(
4542
ILoginService<ApplicationUser> loginService,
4643
IIdentityServerInteractionService interaction,
4744
IClientStore clientStore,
48-
ILoggerFactory loggerFactory,
45+
ILogger<AccountController> logger,
4946
UserManager<ApplicationUser> userManager)
5047
{
5148
_loginService = loginService;
5249
_interaction = interaction;
5350
_clientStore = clientStore;
54-
_logger = loggerFactory.CreateLogger<AccountController>();
51+
_logger = logger;
5552
_userManager = userManager;
5653
}
5754

@@ -69,6 +66,7 @@ public async Task<IActionResult> Login(string returnUrl)
6966
}
7067

7168
var vm = await BuildLoginViewModelAsync(returnUrl, context);
69+
7270
ViewData["ReturnUrl"] = returnUrl;
7371

7472
return View(vm);
@@ -97,6 +95,7 @@ public async Task<IActionResult> Login(LoginViewModel model)
9795
};
9896

9997
await _loginService.SignIn(user);
98+
10099
// make sure the returnUrl is still valid, and if yes - redirect back to authorize endpoint
101100
if (_interaction.IsValidReturnUrl(model.ReturnUrl))
102101
{
@@ -111,7 +110,9 @@ public async Task<IActionResult> Login(LoginViewModel model)
111110

112111
// something went wrong, show form with error
113112
var vm = await BuildLoginViewModelAsync(model);
113+
114114
ViewData["ReturnUrl"] = model.ReturnUrl;
115+
115116
return View(vm);
116117
}
117118

@@ -180,6 +181,7 @@ public async Task<IActionResult> Logout(string logoutId)
180181
public async Task<IActionResult> Logout(LogoutViewModel model)
181182
{
182183
var idp = User?.FindFirst(JwtClaimTypes.IdentityProvider)?.Value;
184+
183185
if (idp != null && idp != IdentityServerConstants.LocalIdentityProvider)
184186
{
185187
if (model.LogoutId == null)
@@ -191,10 +193,15 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
191193
}
192194

193195
string url = "/Account/Logout?logoutId=" + model.LogoutId;
196+
194197
try
195198
{
199+
196200
// hack: try/catch to handle social providers that throw
197-
await HttpContext.Authentication.SignOutAsync(idp, new AuthenticationProperties { RedirectUri = url });
201+
await HttpContext.SignOutAsync(idp, new AuthenticationProperties
202+
{
203+
RedirectUri = url
204+
});
198205
}
199206
catch (Exception ex)
200207
{
@@ -203,7 +210,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
203210
}
204211

205212
// delete authentication cookie
206-
await HttpContext.Authentication.SignOutAsync();
213+
await HttpContext.SignOutAsync();
207214

208215
// set this so UI rendering sees an anonymous user
209216
HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity());
@@ -217,7 +224,7 @@ public async Task<IActionResult> Logout(LogoutViewModel model)
217224
public async Task<IActionResult> DeviceLogOut(string redirectUrl)
218225
{
219226
// delete authentication cookie
220-
await HttpContext.Authentication.SignOutAsync();
227+
await HttpContext.SignOutAsync();
221228

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

src/Services/Identity/Identity.API/Data/ApplicationContextSeed.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using Extensions.Logging;
66
using global::eShopOnContainers.Identity;
77
using global::Identity.API.Data;
8+
using global::Identity.API.Extensions;
89
using global::Identity.API.Models;
9-
using Identity.API.Extensions;
1010
using Microsoft.AspNetCore.Builder;
1111
using Microsoft.AspNetCore.Hosting;
1212
using Microsoft.Extensions.DependencyInjection;
@@ -16,7 +16,6 @@
1616
using System.IO;
1717
using System.IO.Compression;
1818
using System.Linq;
19-
using System.Security.Cryptography;
2019
using System.Text.RegularExpressions;
2120
using System.Threading.Tasks;
2221

src/Services/Identity/Identity.API/Data/ApplicationDbContext.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using Identity.API.Models;
52
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
63
using Microsoft.EntityFrameworkCore;
7-
using Identity.API.Models;
84

95
namespace Identity.API.Data
106
{

0 commit comments

Comments
 (0)