Register IAuthenticationManager with Simple Injector

As TrailMax already mentioned, the exception you got probably got raised during the call to container.Verify(). At application start-up time there is no HttpContext, hence the exception. Although the removal of the call to container.Verify() will ‘solve’ the problem, I would advise against doing this and I will suggest a better solution below. NightOwl888 references … Read more

How do I forcefully propagate role changes to users with ASP.NET Identity 2.0.1?

If you want to enable immediate revocation of cookies, then every request must hit the database to validate the cookie. So the tradeoff between delay is with your database load. But you can always set the validationInterval to 0. app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), Provider = new CookieAuthenticationProvider { // … Read more

Why new fb api 2.4 returns null email on MVC 5 with Identity and oauth 2?

Taken from a Katana Thread I devised the following: Change the FacebookAuthenticationOptions to include BackchannelHttpHandler and UserInformationEndpoint as seen below. Make sure to include the names of the fields you want and need for your implementation. var facebookOptions = new FacebookAuthenticationOptions() { AppId = “*”, AppSecret = “*”, BackchannelHttpHandler = new FacebookBackChannelHandler(), UserInformationEndpoint = “https://graph.facebook.com/v2.4/me?fields=id,name,email,first_name,last_name” … Read more

Asp.NET Identity 2 giving “Invalid Token” error

I encountered this problem and resolved it. There are several possible reasons. 1. URL-Encoding issues (if problem occurring “randomly”) If this happens randomly, you might be running into url-encoding problems. For unknown reasons, the token is not designed for url-safe, which means it might contain invalid characters when being passed through a url (for example, … Read more

How to extend available properties of User.Identity

Whenever you want to extend the properties of User.Identity with any additional properties like the question above, add these properties to the ApplicationUser class first like so: public class ApplicationUser : IdentityUser { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, … Read more