开发者

How do I get the username using DotNetOpenAuth with Google

开发者 https://www.devze.com 2022-12-27 12:05 出处:网络
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/account

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号