{"id":2304,"date":"2012-08-22T12:13:43","date_gmt":"2012-08-22T12:13:43","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2012\/08\/22\/extra-information-from-oauthopenid-provider\/"},"modified":"2022-08-10T06:30:47","modified_gmt":"2022-08-10T13:30:47","slug":"extra-information-from-oauthopenid-provider","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/extra-information-from-oauthopenid-provider\/","title":{"rendered":"Extra Information from OAuth\/OpenId Provider"},"content":{"rendered":"<p>When you authenticate a user using the OAuth\/OpenId providers, you can request for some extra information about the user if you have granted access for these providers to send this information.<\/p>\n<p>For eg if you login using Facebook, you can request information such as Gender, country etc.<\/p>\n<p>Each provider has different set of data that you can retrieve. I am not going to into the details of these different sets of data. In this post I am going to cover what kind of information can you retrieve from the implementations of the providers that we shipped with templates&#160; in VS2012 and how can you retrieve this information. <\/p>\n<h3>What kind of information can you retrieve<\/h3>\n<p><strong>Google<\/strong><\/p>\n<ul>\n<li>email<\/li>\n<li>firstname<\/li>\n<li>lastname<\/li>\n<li>country<\/li>\n<\/ul>\n<p><a href=\"https:\/\/developers.google.com\/accounts\/docs\/OpenID\">https:\/\/developers.google.com\/accounts\/docs\/OpenID<\/a> is a good place to look for more information<\/p>\n<p><strong>Facebook <\/strong><\/p>\n<ul>\n<li>id<\/li>\n<li>Name<\/li>\n<li>link<\/li>\n<li>gender&#160; <\/li>\n<li>accesstoken<\/li>\n<\/ul>\n<p><a href=\"http:\/\/developers.facebook.com\/docs\/\">http:\/\/developers.facebook.com\/docs\/<\/a> is a good place to look for more information<\/p>\n<ul><\/ul>\n<p><strong>Twitter<\/strong><\/p>\n<ul>\n<li>name<\/li>\n<li>location<\/li>\n<li>description<\/li>\n<li>url<\/li>\n<li>accesstoken<\/li>\n<\/ul>\n<h3><a href=\"https:\/\/dev.twitter.com\/docs\/auth\/oauth\/faq\"><font style=\"font-weight: normal\">https:\/\/dev.twitter.com\/docs\/auth\/oauth\/faq<\/font><\/a><font style=\"font-weight: normal\"> is a good place to look for more information<\/font><\/h3>\n<h3>How to retrieve this information<\/h3>\n<p>This data is available when you login using anyone of the providers. In specifics to the code you can access this data after the authentication has happened. The data is returned as a dictionary. Following image shows a snapshot of the data returned from facebook provider<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/08\/0447.oauthextradata_thumb_71397625.png\"><img decoding=\"async\" title=\"oauthextradata\" border=\"0\" alt=\"oauthextradata\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/08\/0447.oauthextradata_thumb_71397625.png\" width=\"602\" height=\"271\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><strong>Web Forms<\/strong><\/p>\n<ul><!--StartFragment-->   <\/p>\n<li>Create the ASP.NET WebForm template<\/li>\n<li>Goto AccountRegisterExternalLogin.cs<\/li>\n<li>In the AuthenticationResult type we have Extradata dictionary bag which has this data<\/li>\n<\/ul>\n<div class=\"csharpcode\">\n<pre class=\"alt\">var authResult = OpenAuth.VerifyAuthentication(redirectUrl);<\/pre>\n<\/div>\n<ul><!--EndFragment--><\/ul>\n<p>&#160;<\/p>\n<p><strong>MVC<\/strong><\/p>\n<ul>\n<li>Create the internet template in MVC4<\/li>\n<li>Goto the account controller in ExternalLoginCallBack<\/li>\n<li>In the AuthenticationResult type we have Extradata dictionary bag which has this data<\/li>\n<\/ul>\n<div class=\"csharpcode\"><\/div>\n<div class=\"csharpcode\">\n<pre class=\"alt\"> AuthenticationResult result = <\/pre>\n<\/div>\n<div class=\"csharpcode\"><\/div>\n<div class=\"csharpcode\">\n<pre>                OAuthWebSecurity.VerifyAuthentication(Url.Action(<span class=\"str\">&quot;ExternalLoginCallback&quot;<\/span>, <span class=\"kwrd\">new<\/span> { ReturnUrl = returnUrl }));<\/pre>\n<\/div>\n<div class=\"csharpcode\"><\/div>\n<p><strong>Web Pages<\/strong><\/p>\n<ul><!--StartFragment--><\/p>\n<li>Create the webpages2 template<\/li>\n<li>Goto ExternalLoginCallBack<\/li>\n<li>In the AuthenticationResult type we have Extradata dictionary bag which has this data<\/li>\n<p><!--EndFragment--><\/ul>\n<p>&#160;<\/p>\n<div class=\"csharpcode\">\n<pre class=\"alt\"> AuthenticationResult result = <\/pre>\n<pre>                OAuthWebSecurity.VerifyAuthentication(Url.Action(<span class=\"str\">&quot;ExternalLoginCallback&quot;<\/span>, <span class=\"kwrd\">new<\/span> { ReturnUrl = returnUrl }));<\/pre>\n<\/div>\n<p>&#160;<\/p>\n<p>In the following posts I will be spending more time showing you how you can customize our OAuth\/OpenId stack and how you can customize and plugin your own providers<\/p>\n<p>Cross posted to <a title=\"http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/08\/22\/extra-information-from-oauth-openid-provider.aspx\" href=\"http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/08\/22\/extra-information-from-oauth-openid-provider.aspx\">http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/08\/22\/extra-information-from-oauth-openid-provider.aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you authenticate a user using the OAuth\/OpenId providers, you can request for some extra information about the user if you have granted access for these providers to send this information. For eg if you login using Facebook, you can request information such as Gender, country etc. Each provider has different set of data that [&hellip;]<\/p>\n","protected":false},"author":408,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[],"class_list":["post-2304","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet"],"acf":[],"blog_post_summary":"<p>When you authenticate a user using the OAuth\/OpenId providers, you can request for some extra information about the user if you have granted access for these providers to send this information. For eg if you login using Facebook, you can request information such as Gender, country etc. Each provider has different set of data that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/408"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=2304"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2304\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=2304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=2304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=2304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}