Skip to content

Commit 5df31ed

Browse files
authored
Identity App to ASP.NET Core 2 (#16)
1 parent 8e79ac1 commit 5df31ed

25 files changed

+625
-516
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,5 @@ _Pvt_Extensions
234234
.paket/paket.exe
235235

236236
# FAKE - F# Make
237-
.fake/
237+
.fake/
238+
/IdentityApp/IdentityAppDb.db

ClientApp/ClientApp/dist/main-server.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ClientApp/wwwroot/dist/main-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
/******/
6060
/******/
6161
/******/ var hotApplyOnUpdate = true;
62-
/******/ var hotCurrentHash = "5c95d35492fd64c98259"; // eslint-disable-line no-unused-vars
62+
/******/ var hotCurrentHash = "5ec7e4cd3862e11569d8"; // eslint-disable-line no-unused-vars
6363
/******/ var hotCurrentModuleData = {};
6464
/******/ var hotCurrentChildModule; // eslint-disable-line no-unused-vars
6565
/******/ var hotCurrentParents = []; // eslint-disable-line no-unused-vars

ClientApp/wwwroot/dist/main-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IdentityApp/Controllers/ManageController.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using IdentityApp.Models.ManageViewModels;
99
using IdentityApp.Services;
1010
using IdentityServer4.Quickstart.UI;
11-
using Microsoft.Extensions.Options;
11+
using Microsoft.AspNetCore.Authentication;
1212

1313
namespace IdentityApp.Controllers
1414
{
@@ -18,22 +18,19 @@ public class ManageController : Controller
1818
{
1919
private readonly UserManager<ApplicationUser> _userManager;
2020
private readonly SignInManager<ApplicationUser> _signInManager;
21-
private readonly string _externalCookieScheme;
2221
private readonly IEmailSender _emailSender;
2322
private readonly ISmsSender _smsSender;
2423
private readonly ILogger _logger;
2524

2625
public ManageController(
2726
UserManager<ApplicationUser> userManager,
2827
SignInManager<ApplicationUser> signInManager,
29-
IOptions<IdentityCookieOptions> identityCookieOptions,
3028
IEmailSender emailSender,
3129
ISmsSender smsSender,
3230
ILoggerFactory loggerFactory)
3331
{
3432
_userManager = userManager;
3533
_signInManager = signInManager;
36-
_externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
3734
_emailSender = emailSender;
3835
_smsSender = smsSender;
3936
_logger = loggerFactory.CreateLogger<ManageController>();
@@ -291,7 +288,7 @@ public async Task<IActionResult> ManageLogins(ManageMessageId? message = null)
291288
return View("Error");
292289
}
293290
var userLogins = await _userManager.GetLoginsAsync(user);
294-
var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();
291+
var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();
295292
ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;
296293
return View(new ManageLoginsViewModel
297294
{
@@ -307,7 +304,7 @@ public async Task<IActionResult> ManageLogins(ManageMessageId? message = null)
307304
public async Task<IActionResult> LinkLogin(string provider)
308305
{
309306
// Clear the existing external cookie to ensure a clean login process
310-
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);
307+
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
311308

312309
// Request a redirect to the external login provider to link a login for the current user
313310
var redirectUrl = Url.Action(nameof(LinkLoginCallback), "Manage");
@@ -336,7 +333,7 @@ public async Task<ActionResult> LinkLoginCallback()
336333
{
337334
message = ManageMessageId.AddLoginSuccess;
338335
// Clear the existing external cookie to ensure a clean login process
339-
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);
336+
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
340337
}
341338
return RedirectToAction(nameof(ManageLogins), new { Message = message });
342339
}

IdentityApp/Data/ApplicationDbContext.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ namespace IdentityApp.Data
1010
{
1111
public sealed class ApplicationDbContext : IdentityDbContext<ApplicationUser>
1212
{
13-
private static bool _migrated;
14-
1513
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
1614
: base(options)
1715
{
18-
if (_migrated) return;
19-
Database.Migrate();
20-
_migrated = true;
2116
}
2217

2318
protected override void OnModelCreating(ModelBuilder builder)

IdentityApp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs renamed to IdentityApp/Data/Migrations/20170916221705_InitApplication.Designer.cs

Lines changed: 90 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)