Vinicius Rocha
Vinicius Rocha

Reputation: 4223

How do I get the username using DotNetOpenAuth with Google

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;
(...)

Upvotes: 2

Views: 2767

Answers (1)

Andrew Arnott
Andrew Arnott

Reputation: 81781

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.

Upvotes: 4

Related Questions