3

We are using Asp.Net Identity in MVC 5 to allow user log in with their social media accounts.

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

We use above API to retrieve information of accounts, but all of the accounts except Facebook have empty value for loginInfo.Email, how can we get the email address for this two social accounts:

  • Microsoft Account
  • Twitter
Jerry Bian
  • 3,998
  • 6
  • 29
  • 54

1 Answers1

2

I believe none of those providers propagate the user email as claims. You will have to query their APIs directly to obtain the email addresses.

To get the email addresses from a Microsoft Account, poke the /me endpoint

Twitter does not allow you to retrieve a user email address. The advice here (as others have ended up with too) is to ask the user for the email address from within your application.

Community
  • 1
  • 1
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
  • The strangest thing is Facebook can return the email address by `loginInfo.Email` ... – Jerry Bian Aug 18 '14 at 06:54
  • @JerryBian - yes, identity providers *may* issue the email address as a claim. Google does this too. After all, both these providers use an email address as the primary user name. But they are not at all *required* to do this. – Peter Lillevold Aug 18 '14 at 06:59