I did this by changing these two lines in the boilerplate AccountController (forgive the rough code),
Old:
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Hometown = model.Hometown };
var result = await UserManager.CreateAsync(user);
New:
var user = new ApplicationUser { UserName = info.Email, Email = info.Email, Hometown = model.Hometown };
IdentityResult result = null;
if (!allowedUsers.Contains(info.Email))
{
result = IdentityResult.Failed("User is not in permitted list");
}
else
{
result = await UserManager.CreateAsync(user);
}
Also, the (at first commented-out) OAuth stuff in Startup.Auth does not request email addresses, so you'll need to add this Scope bit as well - otherwise info.Email will be null:
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "",
ClientSecret = "",
Scope = { "email" }
});
Each OAuth provider has different scope items, e.g., Microsoft names email "wl.emails" when using Scope in MicrosoftAccountAuthenticationOptions.