Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#_=_ added to URL by facebook

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
like image 964
tomek Avatar asked Dec 02 '11 21:12

tomek


2 Answers

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.

like image 126
zeantsoi Avatar answered Nov 17 '22 12:11

zeantsoi


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,     '');
    }
}()); 
like image 36
David Wartell Avatar answered Nov 17 '22 12:11

David Wartell