2

I have an ASP.NET MVC project that uses DotNetOpenAuth as authentication provider. How do I get the username (or email address) when the user logs using https://www.google.com/accounts/o8/id?

switch (response.Status)
    case AuthenticationStatus.Authenticated:
        string userOpenId = response.FriendlyIdentifierForDisplay;
        break;
(...)
Vinicius Rocha
  • 4,023
  • 4
  • 29
  • 38

1 Answers1

4

I hope your userOpenId local variable isn't what you're using for a username, because as the property you're assigning it from is aptly named, it's for display only. You should only use IAuthenticationResponse.ClaimedIdentifier for usernames.

That aside, you can get the Google email address (you can never get the username) by sending a FetchRequest for email marked as a required attribute. This has been asked many times already, for instance this one.

Community
  • 1
  • 1
Andrew Arnott
  • 80,040
  • 26
  • 132
  • 171
  • This might be a newbie question, Andrew Arnott, but why can you get the Google email address but not the username (and what is the difference?) I thought they were one and the same thing. – Umar Farooq Khawaja Nov 10 '12 at 18:45
  • 1
    I'm not sure that there is a difference between username and email address when it comes to Google. But I think users are allowed to change their primary email address on their Google account (especially if it's not linked to a Gmail account), and if you had been using the Google email address as if it were a username, the user would then lose access to their account with your web app. That's just one reason why using the user identifier intended by the protocol (claimed_id) is so important. – Andrew Arnott Nov 25 '12 at 02:03