Squashed commit of the following:

commit ca4defa086a411094f9e90fbe3acef337d6613bb
Author: Praburaj <praburaj.t@microsoft.com>
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 <praburaj.t@microsoft.com>
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 <haok@microsoft.com>
Date:   Tue Sep 23 17:24:42 2014 -0700

    Remove comment

commit 913fd251a39edcf0182b36be17879484ae90fd90
Author: Hao Kung <haok@microsoft.com>
Date:   Tue Sep 23 17:23:12 2014 -0700

    React to identity changes
This commit is contained in:
Praburaj 2014-09-24 15:36:24 -07:00
parent 647a5b6031
commit ef11294897
6 changed files with 9 additions and 88 deletions

View File

@ -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<ApplicationUser> 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
}
/// <summary>
/// TODO: Work around until there is a token provider
/// </summary>
internal class StaticTokenProvider : IUserTokenProvider<ApplicationUser>
{
public Task<string> GenerateAsync(string purpose, UserManager<ApplicationUser> manager,
ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(MakeToken(purpose, user));
}
public Task<bool> ValidateAsync(string purpose, string token, UserManager<ApplicationUser> manager,
ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(token == MakeToken(purpose, user));
}
public Task NotifyAsync(string token, UserManager<ApplicationUser> manager, ApplicationUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task<bool> IsValidProviderForUserAsync(UserManager<ApplicationUser> 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");
}
}
}

View File

@ -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");

View File

@ -76,8 +76,7 @@ namespace MusicStore
});
// Add Identity services to the services container
services.AddIdentitySqlServer<MusicStoreContext, ApplicationUser>()
.AddAuthentication();
services.AddIdentitySqlServer<MusicStoreContext, ApplicationUser>();
// 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()
{

View File

@ -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<MusicStoreContext, ApplicationUser>()
.AddAuthentication();
services.AddDefaultIdentity<MusicStoreContext, ApplicationUser, IdentityRole>(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()
{

View File

@ -83,8 +83,7 @@ namespace MusicStore
});
// Add Identity services to the services container
services.AddIdentitySqlServer<MusicStoreContext, ApplicationUser>()
.AddAuthentication();
services.AddIdentitySqlServer<MusicStoreContext, ApplicationUser>();
// Add MVC services to the services container
services.AddMvc();
@ -125,4 +124,4 @@ namespace MusicStore
SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
}
}
}
}

View File

@ -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": { }
}
}
}