views:

252

answers:

1

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;
(...)
+1  A: 

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.

Andrew Arnott