I'm using the ASP.NET Identity stuff that came with the new MVC 5 templates in VS2013. I've configured external login providers so people can sign up using Google, Facebook, or Microsoft. However, I would still like to get peoples' e-mail address (e.g. for notifications, updates, etc.).
By default the app.UseGoogleAuthentication()
will also request the user's e-mail address. For Facebook, I've created a new instance of the FacebookAuthenticationOptions
class, and added the following scope: facebook.Scope.Add("email")
. This also works.
I'm having problems getting the e-mail for people using a Microsoft Account. The MicrosoftAccountAuthenticationOptions
also has a Scope
property, but adding email
doesn't seem to work. In the documentation I see there is a scope wl.emails
but it returns an array of e-mail addresses and I'm not sure if this is the equivalent for email
with Facebook.
Does anyone have a suggestion how to get the e-mail address as a claim when authenticating?
Configure the scopes for Microsoft.
var mo = new MicrosoftAccountAuthenticationOptions
{
Caption = "Live",
ClientId = clientId,
ClientSecret = clientSecret,
};
mo.Scope.Add("wl.basic");
mo.Scope.Add("wl.emails");
app.UseMicrosoftAccountAuthentication(mo);
Grab the email claim
var identity = await AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie);
var emailClaim = identity.Identity.FindFirst(ClaimTypes.Email);
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With