5

I'm trying to create a Facebook Social Login on my site and followed these steps.

  1. Have a Sitecore 8.0 initial release which is upgraded to update 5. The instance name is mysite.org and this is not a live site yet.
  2. Created an app in facebook and set the Site URL value as http://mysite.org
  3. Ensured that this items exists:

    /sitecore/system/Social/Networks/Facebook

  4. Entered App ID, secret key and selected Facebook as network for this item:

    /sitecore/system/Social/Applications/Default/Facebook

  5. Checked that this item exists:

    /sitecore/layout/Renderings/Social MVC/Connector/Login with Facebook

    The controller for this is :

    Sitecore.Social.Facebook.Client.Mvc.Areas.Social.Controllers.FacebookConnectorController, Sitecore.Social.Facebook.Client.Mvc

  6. In the view, rendering the content as:

    @Html.Sitecore().Rendering("{A58672D4-0B34-41B2-9CCF-5A48C275FD40}")

The html is rendered as:

<form action="/Social/FacebookConnector/Login" method="post" style="display:inline">
<input id="Parameters" name="Parameters" type="hidden" value="">  
<input type="image" title="Login with Facebook" src="/~/media/Images/Social/Connector/Facebook.ashx"> 
</form>

When I click on the facebook icon, the page does a postback and the url changes to:

http://mysite.org/sign-in?state=e0d7a932-9730-4fb2-9d99-50245f235399&authError=29b6cf66-c902-4ee8-91dd-6b89eaf80eff

In the showConfig.aspx, I can see this:

<social patch:source="Sitecore.Social.Facebook.config">
 <networks>
  <network name="Facebook" ItemId="{D7429409-D6DA-46CD-91DD-8702781AE3C4}" prefix="fb" icon="facebook" url="https://www.facebook.com">
      <providers>
        <provider type="Sitecore.Social.Facebook.Networks.Providers.FacebookProvider, Sitecore.Social.Facebook"/>
      </providers>
    </network>

In the error log I find this:

31228 11:39:08 WARN Could not find type in ReflectionUtil.CreateObject: FacebookNetworkProvider
31228 11:39:08 ERROR Sitecore.Social: Can't cast the instance of type "" to NetworkProvider type
31228 11:39:08 ERROR Sitecore.Social: The network provider is not found for Facebook network.
Exception: Sitecore.Social.NetworkProviders.Exceptions.NetworkProviderNotFoundException
Message: The network provider is not found for Facebook network.
Source: Sitecore.Social.Client at Sitecore.Social.Client.Connector.SocialLogin.ProcessRequest(HttpContext httpContext)

There is no call to facebook site in the browser console. I followed the same steps for v8.2 and it worked.

What am I missing here.

6
  • do you have this config ? '/sitecore/social/networks/network' & facebook network added there ? Also please confirm that url facebook contains https & do have SSL binding of your app ? Mar 6 '17 at 7:52
  • config?? do you mean sitecore item or .config file. If it is Sitecore item, then yes. I have mentioned that in my Step 3. In facebook App page, I have updated the site URL to mysite.org. Where should I do the SSL binding. But seeing the error log, I think its missing some type/dll
    – Qwerty
    Mar 6 '17 at 8:25
  • its missing the network, thats the error all about. can you open your showconfig.aspx through mysite.org/sitecore/admin/showconfig.aspx and confirm that you have this node ''/sitecore/social/networks/network' & network facebook node. Mar 6 '17 at 9:00
  • It is available in the config and I have updated my question. Please have a look
    – Qwerty
    Mar 6 '17 at 10:04
  • Just to be sure: are all social related items (renderings, system, templates) published?
    – Thomas D
    Mar 6 '17 at 13:05
5
+25

It would appear to me that based on the above error messages and defined configurations, that somehow, "FacebookNetworkProvider" was set as the type of the Facebook Network Provider configuration "type". Similar to so:

<social patch:source="Sitecore.Social.Facebook.config">
 <networks>
  <network name="Facebook" ItemId="{D7429409-D6DA-46CD-91DD-8702781AE3C4}" prefix="fb" icon="facebook" url="https://www.facebook.com">
      <providers>
        <provider type="FacebookNetworkProvider, Sitecore.Social.Facebook"/>
      </providers>
    </network>

However, your provided configuration doesn't appear to indicate this. However, the provided error messages do.

So how did I arrive at this conclusion? Let's step through backward beginning with the error message.

WARN Could not find type in ReflectionUtil.CreateObject: FacebookNetworkProvider

This error message contains one clear clue: FacebookNetworkProvider which is a string representation of the class that RefelctionUtil.CreateObject is expecting. We can see that here:

public static object CreateObject(string assembly, string className, object[] parameters)
{
  Assembly assembly1 = ReflectionUtil.LoadAssembly(assembly);
  if (assembly1 != (Assembly) null)
  {
    Type type = assembly1.GetType(className, false, true);
    if (type != (Type) null)
    {
      SystemCount.ReflectionTypesResolved.Increment(1L);
      return ReflectionUtil.CreateObject(type, parameters);
    }
    Log.Warn("Could not find type in ReflectionUtil.CreateObject: " + className, (object) typeof (ReflectionUtil));
    SystemCount.ReflectionTypesNotResolved.Increment(1L);
  }
  return (object) null;
}

Notice that className is used in the error message. However, most class names should be in the form of Some.Name.Space.Class (In this case, it should be Sitecore.Social.Facebook.Networks.Providers.FacebookProvider). In addition, ReflectionUtil is specifically using the CreateObject(string assembly, string className, object[] parameters) method because it detected a comma in the typeName

public static object CreateObject(string typeName, object[] parameters)
{
  if (typeName == null || typeName.Length == 0)
    return (object) null;
  int length = typeName.IndexOf(',');
  if (length >= 0)
  {
    string className = typeName.Substring(0, length).Trim();
    return ReflectionUtil.CreateObject(typeName.Substring(length + 1).Trim(), className, parameters);
  }

  //Snipped

}

But, this only provides a warning and instead returns null for the value of the created object, which in this case is supposed to be a network provider.

ERROR Sitecore.Social: Can't cast the instance of type "" to NetworkProvider type

So, now that the Reflection.Util has tried to create a FacebookNetworkProvider to wit it had zero success in doing, the NetworkProviderFactory checks to see if the object returned is of subtype NetworkProvider.

public NetworkProvider GetNetworkProvider(Application application)
{
  Assert.IsNotNull((object) application, "Application is not defined");
  Assert.IsNotNull((object) application.Network, "Network of application is not defined");
  string providerTypeName = this.GetNetworkProviderTypeName(application.Network.Name);
  try
  {
    object obj = ReflectionUtil.CreateObject(providerTypeName, new object[1]
    {
      (object) application
    });
    if (!(obj is NetworkProvider))
      this.logManager.LogMessage(string.Format((IFormatProvider) CultureInfo.CurrentCulture, "Can't cast the instance of type \"{0}\" to NetworkProvider type", new object[1]
      {
        obj
      }), Sitecore.Social.Infrastructure.Logging.LogLevel.Error, (object) this);
    return obj as NetworkProvider;
  }
  catch (Exception ex)
  {
    this.logManager.LogMessage(ex.Message, Sitecore.Social.Infrastructure.Logging.LogLevel.Error, (object) this, ex);
  }
  return (NetworkProvider) null;
}

Since it is not, NetworkProviderFactory logs an error to the log indicating Can't cast the instance of type \"{0}\" to NetworkProvider type", new object[1], which in this case object[1] is null because no provider object was created, and nulls translate to nothing in string format notation hence the empty quotes in the error message.

ERROR Sitecore.Social: The network provider is not found for Facebook network.

Last but not least, is the SocialLogin.ProcessRequest() method ends up throwing an error (in a try catch)

    NetworkProvider networkProvider = ExecutingContext.Current.IoC.Get<INetworkProviderFactory>().GetNetworkProvider(authArgs.Application);
    string name = authArgs.Application.Network.Name;
    if (networkProvider == null)
      throw new NetworkProviderNotFoundException(name);

Because NetworkProviderNotFoundException() is not listed as one of the Exception classes to catch, it falls into the Exeception catch:

  catch (Exception ex)
  {
    AuthException authException1 = new AuthException();
    authException1.DetailedMessage = ex.Message;
    AuthException authException2 = authException1;
    ExecutingContext.Current.IoC.Get<ILogManager>().LogMessage(authException2.DetailedMessage, Sitecore.Social.Infrastructure.Logging.LogLevel.Error, (object) this, ex);
    Guid exceptionKey = new ExceptionManager().Put(new SocialExceptionInfo((ISocialException) authException2));
    SocialLogin.RedirectWithError(authArgs, exceptionKey, httpContext);
  }

This is important, because the SocialLogin.RedirectWithError will actually redirect the client browser to the Callback Url with query parameters with state and authError which you are seeing.

http://mysite.org/sign-in?state=e0d7a932-9730-4fb2-9d99-50245f235399&authError=29b6cf66-c902-4ee8-91dd-6b89eaf80eff

private static void RedirectWithError(AuthArgs authArgs, Guid exceptionKey, HttpContext httpContext)
{
  if (authArgs == null)
  {
    httpContext.Response.ContentType = "text/plain";
    httpContext.Response.Write(Translate.Text("Session has been expired."));
  }
  else
  {
    string str = authArgs.InternalData == null || authArgs.InternalData["UrlReferrer"] == null ? (string) null : authArgs.InternalData["UrlReferrer"].ToString();
    string uri = authArgs.CallbackUrl ?? str;
    if (uri == null)
      return;
    UriBuilder uriBuilder = new UriBuilder(uri);
    SafeDictionary<string> queryString = WebUtil.ParseQueryString(uriBuilder.Query);
    if (exceptionKey != Guid.Empty)
      queryString["authError"] = exceptionKey.ToString();
    queryString["state"] = authArgs.StateKey.ToString();
    uriBuilder.Query = WebUtil.BuildQueryString(queryString, false, false);
    RedirectUtil.Redirect(uriBuilder.ToString(), httpContext);
  }
}

Auth Error Messages

Coincidently, any time that the Social Connect encounters an error during this process, it saves the error message to the client browsers HttpContext.Current.Session as a Hashtable of exceptions called socialExceptionCollection, where the key of the exception thrown equal the Guid that is provided in the authError query string parameter.

Additional Possibilities

  1. In trying to figure how in the world this is occuring, another possibility is that there is an additional config (or multiple configs) laying around in the Include folder that potentially could be interferring with this node. (This is an assumption).

  2. Additionally, I would make sure that for some reason, the facebook network config node doesn't show up more than once in the ShowConfig.aspx.

1
  • An excellent insight into how this actually works. Disappointlingly poor docs still on Sitecore. There is some info here that I wasn't aware of despite hours of poking about in the decompiled assemblies! Thanks
    – geedubb
    Sep 14 '18 at 13:29
1

Please cross verfiy below:

  1. Find below Social Network configuration for facebook which is required: under '/sitecore/social/networks/network' using /sitecore/admin/showconfig.aspx Social Network Config

  2. Make sure you have 'Sitecore.Social.Facebook.dll' & appropriate version in your bin folder since you have "reflectionUtil.CreateObject: Sitecore.Social.Facebook.Networks.Providers.FacebookProvidererror"error

3
  • Sure Thank you. But this is already there in my config. The error in log is Could not find type in ReflectionUtil.CreateObject: Sitecore.Social.Facebook.Networks.Providers.FacebookProvider
    – Qwerty
    Mar 6 '17 at 10:22
  • did you check this config from sitecore/admin/showconfig.aspx ? Mar 6 '17 at 10:42
  • also check you have Sitecore.Social.Facebook.dll in your bin folder Mar 6 '17 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.