--- fbconnect.module	2009-06-03 06:51:06.000000000 -0700
+++ fbconnectNew.module	2009-09-10 15:09:12.000000000 -0700
@@ -52,9 +52,39 @@ function fbconnect_menu() {
     'file' => 'fbconnect.pages.inc',
   );
   
+  $items['fbconnect/unlink'] = array(
+    'page callback' => 'fbconnect_unlink_page',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  
   return $items;
 }
 
+/**
+ * The post-remove callback for facebook. Unlinks facebook account
+ * from the linked drupal one.
+ */
+function fbconnect_unlink_page() {
+  if ($conf = fbconnect_get_config()) {  
+    $sig = ''; 
+    ksort($_POST); 
+    foreach ($_POST as $key => $val) { 
+      if (substr($key, 0, 7) == 'fb_sig_') { 
+         $sig .= substr($key, 7) . '=' . $val; 
+      } 
+    } 
+    
+    $sig .= $conf['secret_api_key']; 
+    $verify = md5($sig); 
+    if ($verify == $_POST['fb_sig']) { 
+      // fb_sig_user has removed the application
+      if ($uid = _is_fbconnect_user($_POST['fb_sig_user'])) {
+        db_query('DELETE FROM {fbconnect_users} WHERE uid = %d', $uid['uid']);
+      }   
+    }
+  }   
+}
 
 /**
  * Implementation of hook_block().
