Search code examples
openiddotnetopenauthasp.net-mvc-5

How can I access a user's openId/OAuth avatar and email address in MVC5?


I want my website to automatically add the user's email address and avatar when they register via OpenId or OAuth. MVC 5 allows a user to register and login with their openId Google, Facebook, or Twitter account, however it doesn't seem to pass any of the linked information back to the website.

I already have a user profile model that gets created when the user registers, but I would like to be able to add their Email address and avitar without having to ask them for it. How can I access the user's linked avatar and email address that is associated with their Google/Facebook/Twitter account once they register through an openId?

So far the information I have found and tried seems to be applicable to MVC 4 or the release candidate of MVC 5 and doesn't seem to work.

Thanks


Solution

  • I asked the exact same question over here :

    How do i retrieve the email address when using google auth in mvc 5?

    credit goes to jd4u for the answer

    You can retrieve it from ClaimIdentity as an Email Claim

    Check this example

    var email = externalIdentity.FindFirstValue(ClaimTypes.Email);
    

    Regarding the profile pic, once again jd4u pointed me to :

    Get ExtraData from MVC5 framework OAuth/OWin identity provider with external auth provider

    I ended up using their gravatar image instead, as it seemed less work. And thats what gravatar is for anyway...