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;
(...)
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.
精彩评论