A user recently reported problems when using an external cache, varnish, and Drupal for Facebook. We were able to fix the problem by enabling the fb_hash setting. But that feature is something of a hack, and it got me experimenting with what I hope is a better and more reliable way to get facebook login and logout working.

I'm hoping this relatively large patch solved a few problems. Making login and logout work better when using Drupal's aggressive cache, and when user has disabled third-party cookies in their browser.

I've pushed the patch to www.drupalforfacebook.org, to better test it. And if all goes well I hope to push it to the git repo soon.

PLEASE TEST THIS. Either by testing www.drupalforfacebook.org, or by applying the patch to your own dev site. Please let me know if you encounter any problems, or even if you don't. Thanks.

Comments

Dave Cohen’s picture

StatusFileSize
new37.11 KB

I'm still looking for reviews of this patch.

Here's the D7 version. Please apply to a test server and let me know if you run into problems. If you do, please tell me exactly which browser you are running, and whether it is configure to accept third-party cookies or not. Thanks.

jcoltrane’s picture

Dear Dave,

I am runnign the 7.x.3.3-beta3 version. I have the issue reported [when third party cookies are turned off - login redirection happens to the site but the login isn't registered in the site]. I am happy to test this patch, but need to know

a) Will this work for the version I am running?
b) What is the command i need to run to patch. I copied the patch file to the fb module directory and ran patch -p1 < 'the filename of the patch', but the patch command complained as follows before i aborted the command.

sudo patch -p1 < fb_login_status_d7.diff
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: fb.theme.css
|===================================================================
|--- fb.theme.css (revision 4260)
|+++ fb.theme.css (working copy)
--------------------------
File to patch: <^C here>

Cheers.

Dave Cohen’s picture

Try patch with -p0, I think that's what I try when it doesn't work with no options.

Dave Cohen’s picture

Status: Needs review » Fixed

I didn't get much review of this. Still, pushed to .dev builds on D6 and D7.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jherencia’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Active

@Dave Cohen

This patch has broken some of my FB apps. Paths which finish in drupal_goto statements that lead to pages with forms are broken because forms could not be submitted, reporting that the form token generated is not valid.

I'm going to try to find exaclty which part has been modified but I cannot do it right now, probably in a few days.

Dave Cohen’s picture

It would help to give really specific instructions how to reproduce. Are there pages/forms like you describe in drupal core? I.e. how can I reproduce that?

jherencia’s picture

StatusFileSize
new599 bytes

Here is a module that explains exactly what is failing. It works in beta3 but it doesn't in dev branch because of this issue fix.

.info

name = FB 1679924
description = Issue 1679924 example.
core = 7.x

dependencies[] = fb
dependencies[] = fb_canvas

.module

<?php

function fb_1679924_menu() {
  $items = array();
  $items['redirection'] = array(
    'title' => 'Redirection',
    'page callback' => 'fb_1679924_redirection',
    'access arguments' => array('access content'),
  );
  $items['destination'] = array(
    'title' => 'Destination',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('fb_1679924_destination_form'),
    'access arguments' => array('access content'),
  );
  return $items;
}

function fb_1679924_redirection() {
  fb_canvas_goto('destination');
}

function fb_1679924_destination_form($form, &$form_state) {
  $form['text'] = array(
    '#type' => 'textfield',
    '#title' => 'Text',
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

function fb_1679924_destination_form_submit($form, &$form_state) {
  drupal_set_message('It worked');
}
Dave Cohen’s picture

Status: Active » Postponed (maintainer needs more info)

All I get is "it worked". Am I missing something? Are you using canvas pages? Connect?

Whatever the problem is, I'm not convinced it is related to the patches in this thread.

jherencia’s picture

Status: Needs review » Postponed (maintainer needs more info)

Yes, I'm using canvas pages.

In the app I'm testing this when I try to submit the form I have the message: "The form has become outdated. Copy any unsaved work in the form below and then reload this page." because validation fails.

If I add to the form $form['#token'] = FALSE it works.

I know the problem is in this commit:
http://drupalcode.org/project/fb.git/commit/bf5a2d8256274139acaa37bb20e6...
because everything works perfectly well before and does not after.

Dave Cohen’s picture

Status: Postponed (maintainer needs more info) » Needs work

Looks like this affects much more than the redirect situation you describe. It affects all forms on canvas pages.

I made what I thought was a safe change to fix a problem where logging out of facebook did not log user out of canvas pages. But the same change breaks form submits, because the session is not the same when the form is rendered as when it is submitted. Frustrating.

You might get away with this change in the short term. I'm going to look into this a bit more.

Change a line near the bottom of fb_settings.inc from
$unique_id = fb_settings(FB_SETTINGS_TYPE) . fb_settings(FB_SETTINGS_ID) . '_' . fb_settings(FB_SETTINGS_FBU);
to
$unique_id = fb_settings(FB_SETTINGS_TYPE) . fb_settings(FB_SETTINGS_ID);

Dave Cohen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.31 KB

Please revert the change #11 or any other changes you've made and try this patch instead.

jherencia’s picture

Status: Postponed (maintainer needs more info) » Needs work

I'm testing git dev version + the patch and this is what I've found, all the tests using the form and module provided in #8:

  • The first time I tested: GET /redirection -> 301 /destination -> POST (submit form) /destination -> 200 /destination with JavaScript Reload -> 200 /destination with "It worked" in the messages. I don't like very much the flow, but it worked.
  • I think it should have changed the session or something, and the when flow is: GET /redirection ->
    301 /destination - POST (submit form) /destination -> 200 /destination (no "it worked" in message, but submit functions are executed, tested in other forms) -> GET /destination (vía F5/Cmd+R) "It worked" shown.

It seems that there is a problem with flash messages, but the execution flow works. I don't like pretty much the first attempt and JavaScript reloads.
In beta3 I never saw any of the infitite reloads that I found in the past. In that version everything works just fine: no Javascript reloads and form submittion and flash messages worked as expected.

Dave Cohen’s picture

I'm pretty sure I don't understand everything you said in #13, but it is not working.

My patch above works better in D6, where I first tested it. It works in D7 when the devel module is showing redirection pages. But in normal drupal, it works fine when the form is submitted, then drupal does a redirect which loses the signed_request and therefore the session.

Drupal's last redirect after the submit handler is called redirects the canvas iframe. Ideally it change the top frame, to a URL rewritten to start with apps.facebook.com/.... There's code in fb_canvas.module that attempts to fix redirection when on canvas pages. Search for FB_OP_EXIT to find it. I suspect that's not working in D7. I'll look into it further when I have some time.

Dave Cohen’s picture

StatusFileSize
new445 bytes

jherencia, this patch fixes for me. You too?

Dave Cohen’s picture

Status: Needs work » Needs review
socialnicheguru’s picture

Issue summary: View changes

there is no function fb_canvas_redirect any longer

Dave Cohen’s picture

Status: Needs review » Fixed

It became fb_iframe_redirect(), as it is used in both canvas pages and page tabs.

Marking fixed, to keep the issue queue sane.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.