0

I'm trying to handle the DeAuth callback from Facebook in my .Net MVC3, so that I can retrieve the UserId and remove the user from my database.

I've created an action that writes to a log file (for debugging purposes) using code from this answer:

FacebookApp app = new FacebookApp();
string accessToken = app.Session.AccessToken;
long userId = app.UserId;

At first my code failed with app being null. I then tried to add the CanvasAuthorizeAttribute to the Controller, which didn't help much either. Is there some other attribute I should have added instead? Or is there something else I'm wrong?

Edit:

I'm using version 4.2.1 of the SDK.

Edit 2: Thanks to Pat I figured out that the following code does the job (without any attributes on the action or controller).

var app = new FacebookApp();
var userId = app.SignedRequest.UserId;
Community
  • 1
  • 1
Tor-Erik
  • 990
  • 8
  • 25

1 Answers1

2

I do this by parsing the signed_request that comes when Facebook hits your DeAuth page:

string signedRequestValue = Request.Form["signed_request"];
var app = new FacebookApp();
var sig = app.ParseSignedRequest(signedRequestValue);
long userid = sig.UserId;

I am using a prior release of the SDK that I had to modify to make the ParseSignedRequest public (it was private), but I believe this is a public method in the latest release 4.2.1 that you are using.

Pat James
  • 4,348
  • 26
  • 39
  • Thank you for setting me on the right path :). The code was actually even simpler than what you suggested. – Tor-Erik Jan 25 '11 at 12:02