While testing the connect stuff this morning I ran into the following situation that was causing an infinite redirect. Here is the block that was causing the redirect to occur:
FB_Connect.on_not_connected = function() {
//alert("FB_Connect.on_not_connected, settings fbu is " + Drupal.settings.fb_connect.fbu);
var status = {'changed': false, 'fbu': 0};
if ((FB_Connect.fbu > 0 || Drupal.settings.fb_connect.fbu > 0) &&
Drupal.settings.fb_connect.in_iframe != 1){
// This code will not be reached if fb_connect_logout_onclick (below) calls logoutAndRedirect.
// We've gone from connected to not connected.
status.changed = true;
}
Here is the state of the variables:
FB_Connect.fbu=0
Drupal.settings.fb_connect.fbu=<myfbid>
I'm not sure how I got into this situation (I'm on the latest codebase), but somehow it did. It appears that here Drupal thinks the user fbu is set, but facebook keeps saying it isn't and it loops over and over again since the above condition is true and it marks the status as changed. Even though I could not reproduce this, I thought it might be helpful to submit that piece of code for review. Should it really be refreshing in this scenario? If so, should there be a check to make sure the user is logged into drupal in addition to Drupal.settings.fb_connect.fbu being set?
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | fb_cache.diff | 631 bytes | Dave Cohen |
Comments
Comment #1
phoenix commentedWell, I noticed the same problem. I was logged in on my (development) site. When logging out, the site sometimes comes in this indefinite loop. But I don't know the reason. I don't have any drupal for facebook blocks on my pages. I only pasted code to have a facebook button on the login page.
$form['fb_connect_button'] = array(
'#type' => 'markup',
'#value' => 'Connect with Facebook',
'#prefix' => '
'#suffix' => '
',
'#weight' => 4, // LOG IN button weight is 2.
);
drupal_add_js(array('fb_connect' => array('destination' => url('facebook-login'))), 'setting');
Comment #2
Dave Cohen commentedwe can't read the markup unless you use
<code>.Do you get the infinite redirect without this
drupal_add_js(array('fb_connect' => array('destination' => url('facebook-login'))), 'setting');Do either of you have the global redirect module enabled?
Comment #3
reasonattlm commentedI experienced this on a fresh install of a facebook connect login implementation, and traced it to Boost by disabling modules one by one. After reading the DFF readme all the way.
Details to reproduce:
- Drupal 6.15 as of 2/10
- Latest DFF as of today
- Boost: use the out of the box parameters, don't change anything
- Create a facebook app at facebook and the app node in drupal per the instructions. Make sure it's auto-configuring correctly.
- Set the default theme to bluemarine (and make it facebook aware with the namespace declaration, etc)
- Put the DFF login block for the facebook app on every page, under the normal login block
- Create a node ('hello world') and set it to be the site home page
Now try to log in at the home page through the facebook app. Infinite loop. You'll also get a variety of other interesting infinite loops on logout cases if you play around with it.
Disabling the Boost module solves the immediate problem. But someone with more experience with facebook apps than I might say whether there is a way to keep Boost and sort this out. I suspect that might be an issue on a bluemarine-style theme with the login box on basically every page.
Comment #4
Hoesh commentedHad same problems, lots of redirection.
Something may be wrong with the cookies i guess.
The most fury that after i removed my application from my user on FB, disabled sandbox mode,
and deleted browser cookies, i connected to my site, and the system logs me as the drupal administrator
user, not my facebook user.
Is that how its supposed to be?
Comment #5
Dave Cohen commentedIf you are logged into drupal, as administrator or any registered user, then click the facebook connect button or authorize the app on facebook, Drupal for Facebook will map your facebook account to the registered user instead of creating a new local account. Possibly that's what you did?
But if you've really deleted all cookies, you should not be logged into your site or into facebook.
As for the infinite redirects, I still have not been able to reproduce it. I haven't tried boost module. And people report the global redirect module can cause this sort of thing, too. I think the bugs lie in those modules and not Drupal for Facebook, but if someone can show me a simple way to reproduce or a patch that solves the problem I'll consider it.
Comment #6
aronmalkine commentedThis is happening for me too - using both beta2 release and a dev release from 2/22/2010. Seems to me this is related to the facebook session expiring. If it happens with caching turned on it can appear to be related to boost or even normal facebook caching. Thought I had it solved when disabling these caches seemed to fix it ...but it keeps coming back if I step away for a few hours with a logged in account and click either reload or try to logout of fb_connect. Clearing cookies temporarily fixes it. I can verify that I'm seeing the same codeblock from ahansen1's post repeat over and over.
Comment #7
aronmalkine commentedTracked it back to:
This is always reaching the 'no destination' path and reloading the page. Is this function hoping something will automatically happen to logout the user on the next go-round when this happens?
Comment #8
Dave Cohen commentedIt's super-annoying that facebook forces these cookies on connect sites and gives us no way to get rid of them. At least there's none that I know of.
The "something will happen automatically" that the function is hoping for is that the cookies go away when they're no longer valid.
When Drupal's PHP executes, it sees the cookies, initializes facebook api and facebook api indicates the user is known. The facebook ID is stored as
Drupal.settings.fb_connect.fbu. Then in the javascript theFB_Connect.on_not_connected()is called. Since drupal has processed the page as if the user is logged in, a refresh is in order. But that refresh kicks off an infinite loop, it appears.Does this happen even with all caching off? Why am I not seeing it?
Comment #9
Dave Cohen commentedMaybe grasping at straws here... Can you test this patch?
Comment #10
ahansen1 commentedDave,
You never commented on the original code snippet I was included. Basically what I was seeing was that facebook thought the user was not logged in, but for whatever reason drupal did:
This caused the state to get set to "changed" causing the reload to happen in statusHandle. This would reload the page, facebook would tell us again that the user is 0 and we would go forever. I wondered why Drupal.settings.fb_connect.fbu being > 0 should trigger this state. Can't we change that to only reload when FB_Connect.fbu > 0?
Comment #11
Dave Cohen commentedThe fact that
Drupal.settings.fb_connect.fbu=<myfbid>means the page was loaded as if you are a known user, connected to facebook. The fact thatFB_Connect.fbu=0means the javascript has detected that you are actually not logged into facebook. Because the two are different, the page must be reloaded.Comment #12
Dave Cohen commentedI don't yet have a solution, but I have now reproduced the problem. Thanks for the added details.
Anyone know how to delete cookies from javascript?
Comment #13
aronmalkine commentedAny luck on this?
Comment #14
Dave Cohen commentedNo, no luck. It's been posted about in the forums...
http://forum.developers.facebook.com/viewtopic.php?id=34406
http://forum.developers.facebook.com/viewtopic.php?id=34766
Comment #15
aronmalkine commentedI read the posts on the facebook forum and seconded the requests.
Since this issue seems to be isolated to users who have de-authorized the corresponding fb app, is there a way we could make better use of the 'FB_APP_EVENT_POST_REMOVE' event to escape this loop?
Just a thought...
Comment #16
Dave Cohen commentedI just don't know of any way to get rid of those cookies. There's possibly a way, outside the facebook APIs. But I don't know what it is.
And it happens when a session times out, not just when de-authorized.
Comment #17
stieglitz commentedsubscribe
Comment #18
giorgio79 commented+1
Comment #19
stieglitz commentedI found this and my problems do indeed seem to be in IE but I have not actually proven this to be the case. My hosting service sent me a warning that I had exceeded my server usage...which I have to attribute to this module. I had asSumed a misconfiguration on my part but now I am not so sure. I am not sure if this helps or where to put it, but for what it is worth:
Comment #20
Dave Cohen commentedI've submitted an issue to facebook's queue: http://bugs.developers.facebook.com/show_bug.cgi?id=9029
... where they can ignore it completely.
It might help to have a consistant way to reproduce the problem. I can't find one. If anyone knows how to reproduce this every time, please let me know.
Comment #21
giorgio79 commentedThis may be related: http://bugs.developers.facebook.com/show_bug.cgi?id=7697
The most voted for bug with the keyword: loop :)
http://bugs.developers.facebook.com/buglist.cgi?quicksearch=loop
Comment #22
aronmalkine commentedDave, in comment #12 you said you've reproduced this. Then in #20 you say you can't. Can you or can't you?
We desperately need a work-around soon, we can't afford to wait for Facebook to fix this. Can we count how many times the app has automatically reloaded the same page for the user? There must be something that can be done.
Comment #23
Dave Cohen commentedI have seen it. When I posted that comment, I had my machine in that state. I could edit the fb_connect.js, for example to add an alert each time through the loop.
But I cannot make it happen on demand. I don't know exactly how I got it into that state, and I haven't seen it since.
Comment #24
rootdownmedia commentedI am experiencing this problem as well when normal caching is enabled. Quite annoying and a critical bug IMHO.
Comment #25
Dave Cohen commentedWhat are your settings on the facebook application node? Specifically have you designated the "primary" facebook connect app? And do create a local user when app is authorized?
Comment #26
Krazna commentedWe are building a site with facebook as enduser identification. During development we started experiencing this phenomena quite often. It seemed that facebook and drupal had different timeouts for the their session, especially in a way that facebook timed out faster. (perhaps this is something we need to fix on our product aswell).
My guess is that this caused a situation where user would be logged into drupal but not to facebook and when accessing pages where we have modules like "show facebook friends" etc would not be able to access the facebook for user's info -> hence it would try to reload it forever. I was able to stop the loop by opening a new tab in the browser and relogging to facebook.
This happened quite a lot with my laptop which goes to sleep mode and once i return, voila. I'm sorry i can't offer any definite technical details other than some module lists. We installed just the facebook module update so i'll be back in few days to report wether that fixed the problem (as there are some comments in the release notes on improving session handling).
It's naturally our common interest to get this sorted out so if there's some data or testing help, just ask.
drupal 6.15 & Modules
pathauto
pollfield
admin_language
advpoll
simplenews
cck
simplenews_register
date
devel
fb
token
fckeditor
views
votingapi
jquery_update
webform
webformblock
mollom
wysiwyg
Comment #27
Dave Cohen commentedthis may fix it!
(thanks to aronmalkine for the extra details about how to reproduce)
Comment #28
Dave Cohen commentedI believe this is fixed. Checked in the patch above for inclusion in beta4.
Comment #29
remedios commentedIf the above fix doesn't work, as it didn't for me, make sure that the RewriteRule in your-domain.com's .htaccess file isn't redundant with settings.php's $base_url. If they're redundant, you'll get an infinite loop.
See this node: http://drupal.org/node/741796
In sites/default/settings.php, you will have:
$base_url = 'http://www.MY-SITE.com'; // NO trailing slash!DON'T list the base URL as
$base_url = 'http://www.MY-SITE.com/subfolder';I'm noting this here because redirect loops seem to be a big problem for fb module users. For several days, I thought that this was an issue with one of my modules, since it only became a problem when I tried to connect to facebook via the modules. I'm a coding novice, so the logic loop between settings.php and .htaccess was not obvious.
Thanks for the awesome module!
Comment #30
Dave Cohen commentedHey I even encountered the really hard to reproduce case yesterday. While I had it going, I was able to find some javascript that deletes the bogus cookies that are sometimes left behind.
I think it's safe to say this is truly fixed, in the dev release and beta 5 (when it comes out).
Comment #31
ccshannon commentedI was having this same problem with my iFrame app (no Canvas, just pure iFrame): As an FB user, when submitting any form like node creation or comments (but not Views filters, those work fine), I get into an infinite reload of the result page.
Today I get up to try the new dev version as per #30, but something has changed before I even have a chance to try that: Now anytime I submit a form I get an 'Access Denied' page and I am no longer logged into the Drupal site. If I reload the page, then I am back at the form I was at previously: if it was a node form, the node create seems to have gone through, but if it's a comment submission, then the comment was NOT created/posted.
I installed the new dev version 2.x-dev, March 14, but I'm not seeing any difference. Again, this wasn't happening last night; it started today.
I am not using base_url in settings.php, as per #29, so that issue isn't relevant for me.
I can create a new issue for this, but seeing as the 'Access Denied' seems to have replace the 'infinite reload', I thought I would post here, first.
Comment #32
Dave Cohen commentedPlease submit a new issue, as this has to do with connect pages, not canvas pages.
In the new issue post what you see in the dff devel block.
Comment #33
ccshannon commentedYou got it. Will do.
Comment #35
jns120 commentedI'm still experiencing this issue using the dev release from April 20 2010. I've tried all the solutions presented but once I connect via facebook (without tieing that to an existing drupal account) my page continues to reload displaying each of three different facebook connect states in the main block. So for example the first page load shows me as logged in and gives me the log out button but with a blank avatar image, then page reloads and shows my FB avatar and log out button, then page reloads and shows original "connect" button.
Previous to trying the dev release I was using the rc1 release.
I've tried deleting all cookies, checking settings on both FB app and drupal FB app pages. Deleted all previous FB accounts in my drupal database.
Any ideas here? Thanks!
Comment #36
jns120 commentedComment #38
chazz commentedI have similar loop problem, I have selected option to create new account with mapping
When user click CONNECT WITH FACEBOOK, user is logged in and logged out after 2 seconds then logged in back again after 2 seconds and then he can browse the website without further log in loop
Comment #39
chazz commentedComment #40
Mauro Colella commentedJust wanted to add the results of my own tests to this one : I found that the problem occurs for me if block caching is active on Administer >> Site configuration >> Performance when using the Facebook login as a block. This "jams" the cookie clearing process by serving the cached block once again.
Also, I had to disable the Boost module to prevent a similar issue (but am not sure what causes this conflict with Boost).
Comment #41
Mauro Colella commented..Wrong thread. Sorry.
Comment #42
srinikasturi commentedThe problem is happening on my fresh install. I installed again afresh after uninstalling the previous DFF to see if this would go away. It isn't. So here are the issues:
1. FB connect is going into a loop on login
2. If you try loading up the app page in the browser, the site shows up in the iframe briefly, and then the loop kicks in, resulting in a white screen.
This is on the latest 3.x version. The site is second7.peppervillage.net, which still shows the login loop problem. The app is srinikas. Both are set up purely as test deployments for me to better understand the DFF modules.
Any help or advice is greately appreciated.
Thanks
Srini
Comment #43
Dasha_V - old commentedI had loop problem when update from the 2.x to 3.x versions.
Clearing Drupal's sessions table fixed it for me:
Comment #44
srinikasturi commentedyes, Dasha_V, that worked.
Thanks
Srini
Comment #45
brisath commentedSubscribing. I'm getting a looping in 3.x-dev version right now.
Comment #46
Dave Cohen commentedThis thread has been around a long time, and I'm sure there have been multiple causes and fixes along the way. Recently, facebook has made some changes to its canvas page signatures. For example, adding the signed_session parameter and json encoding the older session parameter (thanks, facebook, for that pleasant surprise). For connect pages, I wouldn't be surprised if that's changed as well, but I'm not sure exactly. Session handling is tricky enough, it doesn't help to have these unexpected changes and multiple "migrations" settings which make facebook send the apps different values.
Anyway, I've just checked into CVS (HEAD a.k.a. 6.x-3.x-dev) multiple changes which hopefully fix these issues. If you can still reproduce the problems with the latest, post details here. If you can reproduce the identical problem on http://drupalforfacebook.org, even better. That site and http://apps.facebook.com/drupalforfacebook are using the latest code. If the problem appear there, it will be easier for me to track down.
Comment #47
Dave Cohen commentedP.S.
When you get the latest modules/fb, also get the latest facebook-php-sdk from facebook! Update them both.
drupalforfacebook.org is running with all the "migrations" enabled.
Comment #48
brisath commentedI'm reporting that the upgrade to the latest 6.x-3.x-dev and latest facebook-php-sdk seems to have resolved my looping issue. Thanks Dave.
Comment #49
spinicrus commentedhi!,
here is what i did to overcome this issue. (i'll just paste the code). basically i just wanted to bypass the cache (i use an authcache & memcache solution):
(modifications are made in fb_connect.module), & i use 6.x-2.0-rc2:
somewhere after line 64:
define the function:
and finally, replace some code (i commented current code):
one more thing: authcache gives an option to define paths that may not be cached, so i just added my .js's scripts's path. "fb_connect/js/fbconnectalf.js*" (the one defined in hook_menu)
hope this helps.
cheers!
Comment #50
sadist commentedspinicrus, thanks for sharing. but I still couldn't manage to get it work with firefox. but at least it goes blank everytime after logged in, back logged off when I refreshed the browser.. that's the only difference.
I think this is critical issue as Firefox is 2nd most used web browser after ie?
Comment #51
olivo.marco commentedSame issue here, and #49 partially works: no more refreshes (not even under FF) but homepage, when logging in, is not refreshed and does not properly show the logged-in homepage.
The same happens when clicking the "connect with fb" button on any page: after the fb login, the page is loaded but not in the logged-in way. Only after an additional, manual refresh the page is shown properly.
Anyways, that seems to be a good patch!
Comment #52
Dave Cohen commentedHere's a patch I am currently testing. The idea is, instead of simply reloading the current URL, appending a parameter to the url including the user's facebook id. This should get around any problems caused by caching.
If you experience this problem, please apply this patch and let me know what if any effect it has.
Comment #53
Dave Cohen commentedI checked in the above code. I'm interested to hear if this is still a problem, but for now I will assume it is not.
Comment #55
millo_avissar commentedI had the same problem using 6.x-3.x-dev (jun 2010) with infinite refresh loop, on login using fb-connect,
clicking on another link, it sometimes came out of that loop.
and then the user was logged-in... and happy :)
Then, I upgraded to the latest version dated 2010-Oct-05,
and followed this guide: http://drupal.org/node/761886
having no errors in reports/status
Now, there is an even bigger problem I can not login at all.
pressing on the "connect with facebook" button, but nothing happens, and there is no record in the access log.
can't use the devel-block since am not logged in
any idea ?
Comment #56
Dave Cohen commentedplease don't report new problems in closed threads.
open firebug and look for javascript errors. If you still have a problem report a new issue.
Comment #57
mrfelton commentedThis problem is hitting me with the latest fb code, and the latest facebook sdk...
Start logged out of both facebook, and the website.
Clear all cookies
Truncate the drupal sessions table
Go to the website and click on the fbconnect button
fill in the facebook login form that pops up
It then logs me into the site, and redirects me to the url with ?_fb_user_fbu=571281371 appended
It continually reloads the page.
Each time the page reloads, firebug shows an ajax request being made to /fb/ajax/session_change. Details of the ajax request and responce are:
Request headers:
POST:
response
I do not have $base_url set in settings.php
I have all caching disabled
Comment #58
mrfelton commentedOne thing to note, is that if the devel module is not enabled, it seems to work ok. If I enable the devel module, it breaks (as above).
When the devel module is not enabled, the ajax request to /fb/ajax/session_change actually has something in the response... it has this:
So, Dave - I think those dpm statements need to go! Or, at least, do a function_exists() check before you call it.
Comment #59
Dave Cohen commentedAny dpm() outside of fb_devel.module got in there by accident. Sorry about that.
deleting it should solve the problem. I'll check in a fix tomorrow.
Comment #60
mrfelton commentedSure, but it's not the dpm() statements that are the problem - they do make it *look* like its working if you don't have devel installed though (because with the dpm statements return an error in the ajax request, as opposed to the empty array you get when devel is installed and there is no error).
Comment #61
Dave Cohen commentedAn empty array should not be a problem. If empty, fb.js will reload the page.
Comment #62
mrfelton commentedYes, the empty array causes fb.js to reload the page. But every time the page reloads, the array is still empty, resulting in another reload, and another, and another... the infinite loop that is the talk of this issue!
Comment #63
Dave Cohen commentedAll the data you posted looks correct, indicating that user 571281371 has connected. The problem would be that when the page reloads, it doesn't think the user is logged in.
When the browser refreshes the page, do you see the fbs_cdbbb743dbf4ce9985ebaf51b664a1a1 cookie in the header? Are you configured to reject third-party cookies?
Comment #64
mrfelton commentedwhen you say in the header, do you mean in the URL bar? If so, no I do not see that when it refreshes. I am not configured to reject 3rd party cookies.
Comment #65
mrfelton commentedOk - got it...
Do NOT add your IP address to the whitelist in the Facebook application advanced settings.
Adding a few debugging lines into the FB_JS.sessionSanityCheck function in fb.js revealed that an error was being returned from Facebook when trying to check if the user is logged in:
Searching on the facebook developer forum indicated that the server whitelist functionality is actually busted - so don't use it!
:D
Comment #66
Dave Cohen commentedThanks for the update.
I suppose in an ideal world, fb.js would log error messages. Or fb_devel.module would somehow detect errors like that if enabled. Patches along those lines are welcome. Otherwise, I'm flagging this fixed.
Comment #68
miccelito commentedI have also experienced the Facebook/Drupal Authorization Loop problem. Even I tried to change the settings in 'Drupal for Facebook' module but without success to solve anything.
Instead I solved it by adding a new action 'Redirect to URL' (The URL to which the user should be redirected: user) and then assigning it in Trigger (Trigger: After a user has logged in). Doing that the trigger will "override" the Facebook/Drupal Authorization Loop and logging in new user via FacebookConnect.
Comment #69
Alex Andrascu commentedI've hit this on 7.x too. It's looping infintly the fb/ajax/session_change callback
Comment #70
Dave Cohen commentedIf you can reproduce consistently in D7, please explain how in a new issue.
I don't feel like re-opening this long thread, there is another D6 report: [#427436969]
Comment #71
maxchock commentedme too... it loop infinity.... on 7.x
Comment #72
mareks commentedHi!
Not sure if it's the same issue but my case goes like this:
* As a Drupal admin. I disabled the a user "X" that had FB connect.
* "X" then logged in to FB and came to my Drupal site.
* User "X" faced the redirects loop and got the "Can't open the page" message.
Different browsers give different error messages, but the reason is probably the same.
Comment #73
mareks commentedTo make things worse. I just noticed that system had generated 2 more users with the same name with the _1 and _2 appendix.
Comment #74
giorgio79 commentedContinuation in 7x #1380534: Facebook/Drupal Authorization Loop