From ef11294897c86db91f0ac6abc9d32d6f54a20304 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 24 Sep 2014 15:36:24 -0700 Subject: [PATCH] Squashed commit of the following: commit ca4defa086a411094f9e90fbe3acef337d6613bb Author: Praburaj Date: Wed Sep 24 15:13:28 2014 -0700 Enabling account validation, 2FA, Forgot password in the sample Some identity helpers are still missing. Work arounds are applied to enable them working. Will clean it up as soon as identity helpers are available. commit 6072c45537946c29588cfad92ce5e69ecd21656b Author: Praburaj Date: Tue Sep 23 20:08:59 2014 -0700 Using QueryHelpers.ParseQuery for parsing query string. Removed the helpers implemented in the test project. commit 632dd8d43fafb6307b3e504731431479aa96ec50 Author: Hao Kung Date: Tue Sep 23 17:24:42 2014 -0700 Remove comment commit 913fd251a39edcf0182b36be17879484ae90fd90 Author: Hao Kung Date: Tue Sep 23 17:23:12 2014 -0700 React to identity changes --- .../Controllers/AccountController.cs | 43 +------------------ .../Controllers/ManageController.cs | 2 +- src/MusicStore/Mocks/StartupSocialTesting.cs | 20 +-------- src/MusicStore/Startup.cs | 24 +---------- src/MusicStore/StartupNtlmAuthentication.cs | 5 +-- src/MusicStore/project.json | 3 +- 6 files changed, 9 insertions(+), 88 deletions(-) diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index ce4e8ead61..e6eb8690ae 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -6,7 +6,6 @@ using Microsoft.AspNet.Identity; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Rendering; using MusicStore.Models; -using System.Threading; namespace MusicStore.Controllers { @@ -17,11 +16,6 @@ namespace MusicStore.Controllers { UserManager = userManager; SignInManager = signInManager; - - //TODO: Work around - Identity helpers will be available to do this - UserManager.UserTokenProvider = new StaticTokenProvider(); - UserManager.RegisterTwoFactorProvider("Phone Code", UserManager.UserTokenProvider); - UserManager.RegisterTwoFactorProvider("Email Code", UserManager.UserTokenProvider); } public UserManager UserManager { get; private set; } @@ -110,9 +104,7 @@ namespace MusicStore.Controllers // If a user enters incorrect codes for a specified amount of time then the user account // will be locked out for a specified amount of time. // You can configure the account lockout settings in IdentityConfig - // TODO : This helper does not take in the remember browser option yet. - // var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent: model.RememberMe, rememberBrowser: model.RememberBrowser); - var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent: model.RememberMe); + var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent: model.RememberMe, rememberClient: model.RememberBrowser); switch (result) { case SignInStatus.Success: @@ -453,37 +445,4 @@ namespace MusicStore.Controllers #endregion } - - /// - /// TODO: Work around until there is a token provider - /// - internal class StaticTokenProvider : IUserTokenProvider - { - public Task GenerateAsync(string purpose, UserManager manager, - ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken)) - { - return Task.FromResult(MakeToken(purpose, user)); - } - - public Task ValidateAsync(string purpose, string token, UserManager manager, - ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken)) - { - return Task.FromResult(token == MakeToken(purpose, user)); - } - - public Task NotifyAsync(string token, UserManager manager, ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken)) - { - return Task.FromResult(0); - } - - public Task IsValidProviderForUserAsync(UserManager manager, ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken)) - { - return Task.FromResult(true); - } - - private static string MakeToken(string purpose, ApplicationUser user) - { - return string.Join(":", user.Id, purpose, "ImmaToken"); - } - } } \ No newline at end of file diff --git a/src/MusicStore/Controllers/ManageController.cs b/src/MusicStore/Controllers/ManageController.cs index 94d283dc4b..a122240b60 100644 --- a/src/MusicStore/Controllers/ManageController.cs +++ b/src/MusicStore/Controllers/ManageController.cs @@ -260,7 +260,7 @@ namespace MusicStore.Controllers var user = await GetCurrentUserAsync(); if (user != null) { - await SignInManager.RememberTwoFactorClient(user); + await SignInManager.RememberTwoFactorClientAsync(user); await SignInManager.SignInAsync(user, isPersistent: false); } return RedirectToAction("Index", "Manage"); diff --git a/src/MusicStore/Mocks/StartupSocialTesting.cs b/src/MusicStore/Mocks/StartupSocialTesting.cs index bc2282d131..99693dd23f 100644 --- a/src/MusicStore/Mocks/StartupSocialTesting.cs +++ b/src/MusicStore/Mocks/StartupSocialTesting.cs @@ -76,8 +76,7 @@ namespace MusicStore }); // Add Identity services to the services container - services.AddIdentitySqlServer() - .AddAuthentication(); + services.AddIdentitySqlServer(); // Add MVC services to the services container services.AddMvc(); @@ -116,22 +115,7 @@ namespace MusicStore // Add static files to the request pipeline app.UseStaticFiles(); - // Add cookie-based authentication to the request pipeline - app.UseCookieAuthentication(new CookieAuthenticationOptions - { - AuthenticationType = "External", - AuthenticationMode = AuthenticationMode.Passive, - ExpireTimeSpan = TimeSpan.FromMinutes(5) - }); - - // Add cookie-based authentication to the request pipeline - app.UseCookieAuthentication(new CookieAuthenticationOptions - { - AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType, - LoginPath = new PathString("/Account/Login") - }); - - app.UseTwoFactorSignInCookies(); + app.UseIdentity(); var facebookOptions = new FacebookAuthenticationOptions() { diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 6d1767f5d5..3eaea83374 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -1,10 +1,8 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Routing; -using Microsoft.AspNet.Security.Cookies; using Microsoft.Data.Entity; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; @@ -13,7 +11,6 @@ using Microsoft.AspNet.Security.Facebook; using Microsoft.AspNet.Security.Google; using Microsoft.AspNet.Security.Twitter; using Microsoft.AspNet.Security.MicrosoftAccount; -using Microsoft.AspNet.Security; using Microsoft.Framework.Cache.Memory; namespace MusicStore @@ -32,8 +29,6 @@ namespace MusicStore //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. app.UseErrorPage(ErrorPageOptions.ShowAll); - app.SetDefaultSignInAsAuthenticationType("External"); - app.UseServices(services => { //If this type is present - we're on mono @@ -69,8 +64,7 @@ namespace MusicStore }); // Add Identity services to the services container - services.AddIdentitySqlServer() - .AddAuthentication(); + services.AddDefaultIdentity(configuration); // Add MVC services to the services container services.AddMvc(); @@ -90,21 +84,7 @@ namespace MusicStore app.UseStaticFiles(); // Add cookie-based authentication to the request pipeline - app.UseCookieAuthentication(new CookieAuthenticationOptions - { - AuthenticationType = "External", - AuthenticationMode = AuthenticationMode.Passive, - ExpireTimeSpan = TimeSpan.FromMinutes(5) - }); - - // Add cookie-based authentication to the request pipeline - app.UseCookieAuthentication(new CookieAuthenticationOptions - { - AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType, - LoginPath = new PathString("/Account/Login") - }); - - app.UseTwoFactorSignInCookies(); + app.UseIdentity(); app.UseFacebookAuthentication(new FacebookAuthenticationOptions() { diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index 3dbe03de33..f2111ca497 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -83,8 +83,7 @@ namespace MusicStore }); // Add Identity services to the services container - services.AddIdentitySqlServer() - .AddAuthentication(); + services.AddIdentitySqlServer(); // Add MVC services to the services container services.AddMvc(); @@ -125,4 +124,4 @@ namespace MusicStore SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait(); } } -} \ No newline at end of file +} diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index a1c3d8c75e..cd0ec5f37c 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -13,7 +13,6 @@ "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Diagnostics": "1.0.0-*", "Microsoft.AspNet.Identity.SqlServer": "3.0.0-*", - "Microsoft.AspNet.Identity.Authentication": "3.0.0-*", "Microsoft.AspNet.Security.Cookies": "1.0.0-*", "Microsoft.AspNet.Security.Facebook": "1.0.0-*", "Microsoft.AspNet.Security.Google": "1.0.0-*", @@ -37,4 +36,4 @@ "aspnet50": { }, "aspnetcore50": { } } -} \ No newline at end of file +}