Getting the email from external providers Google and Facebook during account association step in a default MVC5 app

PLEASE SEE UPDATES AT THE BOTTOM OF THIS POST! The following works for me for Facebook: StartupAuth.cs: var facebookAuthenticationOptions = new FacebookAuthenticationOptions() { AppId = “x”, AppSecret = “y” }; facebookAuthenticationOptions.Scope.Add(“email”); app.UseFacebookAuthentication(facebookAuthenticationOptions); ExternalLoginCallback method: var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie); var emailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email); var email = emailClaim.Value; And for Google: StartupAuth.cs app.UseGoogleAuthentication(); … Read more

How to inject UserManager & SignInManager

Prerequisites Start a new MVC5 application using the MVC template. This will install all the necessary dependencies as well as deploy the Startup.Auth.cs file which contains the bootstrap code for Microsoft.AspNet.Identity (it als includes the all the references for Microsoft.AspNet.Identity). Install the following packages and update them to the latest afterwards. Install-Package Ninject Install-Package Ninject.MVC5 … Read more

How to implement Multi-tenant User Login using ASP.NET Identity

I’ve now got a working solution that I’ve shared in a GitHub repository: https://github.com/JSkimming/AspNet.Identity.EntityFramework.Multitenant The extensibility required to support multi-tenancy is not possible with the 1.0.0 release of Microsoft.AspNet.Identity.EntityFramework (at least not without a lot of custom work), but is available in the 1.1 alpha release currently available through the Nightly ASP.NET Web Stack NuGet … Read more

Registering Web API 2 external logins from multiple API clients with OWIN Identity

Update: things have changed since I wrote this post in January: MSFT released their official OpenID connect client middleware and I worked hard with @manfredsteyer to adapt the OAuth2 authorization server built in Katana to OpenID connect. This combination results in a far easier and far more powerful solution that doesn’t require any custom client … Read more

The entity type ‘IdentityUserLogin’ requires a primary key to be defined [duplicate]

keys of Identity tables are mapped in OnModelCreating method of IdentityDbContext and if this method is not called, you will end up getting the error that you got. All you need to do is call. protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } The original answer (just copied for other’s reference just in case) here

Register AspNetCore 2.1 Identity system with DbContext interface

By default, when you call AddDbContext, you register a scoped DbContext instance. This means that anywhere within the handling of a single request, requesting said DbContext via DI will give you the same instance. With the double registration you have, the DI system will give you a different instance depending upon whether you ask for … Read more

Configure Unity DI for ASP.NET Identity

You also need to resolve the UserManager. The following is an example how you could do it with the UserManager and the RoleManager. In this sample I use the regular Unity 3 package instead of one of the derivates or bootstrappers (had some problems with them in the past). AccountController private readonly UserManager<ApplicationUser> _userManager; private … Read more