Sunday, February 14, 2010

Facebook Developer Toolkit, MVC and an Incorrect Signature Error

Attempting to do the simplest login to Facebook (groovy) and then grabbing some user data using the Facebook Developer Toolkit in preparation for creating a new user, I spent way too much time trying to resolve an 'Incorrect Signature' error from Facebook on every call. I finally figured out... well, maybe not why the code doesn't work for me, but at least a hack to get past the signature issue.

In my default configuration (an MVC website, not a desktop application), the FDT uses the session key in the MD5 hash computing the signature.

void SendRequestAsync(IDictionary parameterList, bool useSession, AsyncResult ar) {
OR
string SendRequestSynchronous(IDictionary parameterDictionary, bool useSession) {

...in both case useSession = true;

Force this to useSession = false and, voila, no incorrect signature error, and all is, momentarily, right with the world.

So, knowing what to look for I grabbed a bit of code from brianromanko here, and stuck that under both the sync and asyc methods above:


void SendRequestAsync(IDictionary parameterList, bool useSession, AsyncResult ar) {
    var useSession = uid <= 0 || Session is DesktopSession;
...etc.


Why this is creating a DesktopSession, and how to stop it, I have not yet determined.

No comments:

Post a Comment