I have a VS 2013 project using Entity framework with webforms and MVC. I have been struggling to find VB.NET code that will retrieve extra data from the external provider when I use google or other external logins. There is plenty of comments in c# code for this, specifically article(s):-
How do i retrieve the email address when using google auth in mvc 5?
Well I have an answer and thought I'd share it. Placed in the login.aspx.vb file. Having authenticated the login you can use the following to get the extra data such as email
If User.Identity.IsAuthenticated Then
Dim verifiedloginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo(IdentityHelper.XsrfKey, User.Identity.GetUserId())
Dim externalIdentity = Context.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie)
Dim emailClaim = externalIdentity.Result.Claims.FirstOrDefault(Function(c) c.Type = ClaimTypes.Email)
Dim email = emailClaim.Value
MsgBox(email)
end if
Apologies for breaking the forum etiquette but as a newbie I can’t comment on other posts.. what’s a boy to do. Special thanks to this utility http://codeconverter.sharpdevelop.net/SnippetConverter.aspx>