Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got the same problem. As you did, I configured the RegisterFacebookClient with dictionary to define my app's scope, and unfortunately the request didn't include the scope as I configured. So I found <a href="http://mvc4beginner.com/Sample-Code/Facebook-Twitter/MVC-4-oAuth-Facebook-Login-EMail-Problem-Solved.html">that</a>. It seems that would work, but it wasn't enough. So I found <a href="http://savvydev.com/authenticating-facebook-users-with-mvc-4-oauth-and-obtaining-scope-permissions/">this</a>.</p> <p>So here is what solve my problems:</p> <p>First of all I added this new client to my code:</p> <pre><code>using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Web; using DotNetOpenAuth.AspNet; using Newtonsoft.Json; namespace MyApp.UI.Infrastructure { public class FacebookScopedClient : IAuthenticationClient { private string appId; private string appSecret; private string scope; private const string baseUrl = "https://www.facebook.com/dialog/oauth?client_id="; public const string graphApiToken = "https://graph.facebook.com/oauth/access_token?"; public const string graphApiMe = "https://graph.facebook.com/me?"; private static string GetHTML(string URL) { string connectionString = URL; try { System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString); myRequest.Credentials = CredentialCache.DefaultCredentials; //// Get the response WebResponse webResponse = myRequest.GetResponse(); Stream respStream = webResponse.GetResponseStream(); //// StreamReader ioStream = new StreamReader(respStream); string pageContent = ioStream.ReadToEnd(); //// Close streams ioStream.Close(); respStream.Close(); return pageContent; } catch (Exception) { } return null; } private IDictionary&lt;string, string&gt; GetUserData(string accessCode, string redirectURI) { string token = GetHTML(graphApiToken + "client_id=" + appId + "&amp;redirect_uri=" + HttpUtility.UrlEncode(redirectURI) + "&amp;client_secret=" + appSecret + "&amp;code=" + accessCode); if (token == null || token == "") { return null; } string access_token = token.Substring(token.IndexOf("access_token="), token.IndexOf("&amp;")); string data = GetHTML(graphApiMe + "fields=id,name,email,username,gender,link&amp;" + access_token); // this dictionary must contains Dictionary&lt;string, string&gt; userData = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(data); return userData; } public FacebookScopedClient(string appId, string appSecret, string scope) { this.appId = appId; this.appSecret = appSecret; this.scope = scope; } public string ProviderName { get { return "facebook"; } } public void RequestAuthentication(System.Web.HttpContextBase context, Uri returnUrl) { string url = baseUrl + appId + "&amp;redirect_uri=" + HttpUtility.UrlEncode(returnUrl.ToString()) + "&amp;scope=" + scope; context.Response.Redirect(url); } public AuthenticationResult VerifyAuthentication(System.Web.HttpContextBase context) { string code = context.Request.QueryString["code"]; string rawUrl = context.Request.Url.OriginalString; //From this we need to remove code portion rawUrl = Regex.Replace(rawUrl, "&amp;code=[^&amp;]*", ""); IDictionary&lt;string, string&gt; userData = GetUserData(code, rawUrl); if (userData == null) return new AuthenticationResult(false, ProviderName, null, null, null); string id = userData["id"]; string username = userData["username"]; userData.Remove("id"); userData.Remove("username"); AuthenticationResult result = new AuthenticationResult(true, ProviderName, id, username, userData); return result; } } } </code></pre> <p>I put it on a folder "infrastructure" in my asp.net solution with oder stuff, next I change my old configuration, in order to use the new facebook client, as follows:</p> <p>Old code:</p> <pre><code>OAuthWebSecurity.RegisterFacebookClient( appId: "&lt;app-id&gt;", appSecret: "&lt;app-secret&gt;", displayName: "Facebook", extraData: facebookExtraData); </code></pre> <p>New Code:</p> <pre><code>OAuthWebSecurity.RegisterClient( new FacebookScopedClient( "&lt;app-id&gt;", "&lt;app-secret&gt;", "scope"), "Facebook", null); </code></pre> <p>That's it. It may help you, as helped me. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload