After connecting to my Rails app via Facebook I have #_=_ added on to my URL.
I tried specifying a redirect_uri as specified by FB but it didn't work.
Javascript workaround to remove the symbols doesn't help. I tried everything with no results.
Any pointers on how to solve this?
My setup:
gem 'rails', '3.0.11'
gem "devise", '1.5.2'
gem "omniauth", '1.0.1'
gem 'omniauth-facebook', '1.0.0rc2'
module Facebook
CONFIG = YAML.load_file(Rails.root.join("config/facebook.yml"))[Rails.env]
FB_APP_ID = CONFIG['app_id']
FB_APP_SECRET = CONFIG['secret_key']
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Facebook::FB_APP_ID, Facebook::FB_APP_SECRET,
:scope => 'offline_access, email, publish_stream',
:display => 'touch'
end
The #_=_
fragment is being intentionally added by Facebook as described under Change in Sessions Redirect Behavior. Explicitly setting the redirect_uri in your request allegedly takes care of this problem, but there's apparently a bug that persists the unwanted fragment even when the redirect_uri is specified.
Assuming this bug isn't resolved, a workaround may be to replace the hash location using Javascript:
window.location.hash = ""
This doesn't replace the actual hash character, but will get rid of everything following it.
Perhaps this is a cleaner answer and the one I used to solve this issue.
You may have # anchors in your URLs that are desirable and this is especially true if you can end up being forwarded to any page on the site after facebook login. So removing everything in # may cause problems.
This solution will only remove the fubar facebook #= string from the URL and leave other parts of the hash intact.
Add this JS to your header or global JS include.
(function() {
"use strict";
if (window.location && window.location.hash) {
if (window.location.hash === '#_=_') {
window.location.hash = '';
return;
}
var facebookFubarLoginHash = RegExp('_\=_', 'g');
window.location.hash = window.location.hash.replace(facebookFubarLoginHash, '');
}
}());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With