title: Facebook Javascript SDK and OmniAuth
body: <p>I have successfully integrated the OmniAuth Facebook login flow into my rails application on the server side. However, I am also trying to get this to work using the Facebook Javascript SDK on the client side and am running into some issues.</p>
  
  <p>EDIT: THIS ISSUE ONLY SEEMS TO BE HAPPENING IN CHROME AND NOT IN SAFARI OR FIREFOX</p>
  
  <p><strong>Sessions Controller</strong> - This works on the server side flow</p>
  
  <pre><code>def create
  
        auth = request.env['omniauth.auth']
        #if an authorization does not exisit, it will create a new authorization record. it will also create a new user record if a user is not currently logged in
        unless @auth = Authorization.find_from_hash(auth)
          # Create a new user or add an auth to existing user, depending on
          # whether there is already a user signed in.
          @auth = Authorization.create_from_hash(auth, current_user)
  
          #add the friends array to user record. as of now only doing this on the initial user create
          @friends = []
          FbGraph::User.me(@auth.user.authorization.facebook_token).fetch.friends.each do |t|
            @friends &lt;&lt; t.identifier
          end
          u = @auth.user
          u.facebook_friends = @friends
          u.save
  
        end
  
        #store a new auth token if needed (if the new token in the hash does not match the one stored in the database for authorization)
        Authorization.check_if_new_auth_token_is_needed(auth)
  
        # Log the authorizing user in.
        self.current_user = @auth.user
  
        redirect_to root_url
  
    end
  </code></pre>
  
  <p>If I simply hit the /auth/facebook path, the user will be logged in</p>
  
  <p>Routes</p>
  
  <pre><code>match '/auth/:provider/callback', :to =&gt; 'sessions#create'
  </code></pre>
  
  <p>Now on the homepage view I am trying to now run a client side flow login</p>
  
  <p><strong>Homepage View</strong></p>
  
  <pre><code>&lt;script&gt;
  $(function() {
    $('a').click(function(e) {
      e.preventDefault();
      FB.login(function(response) {
        if (response.authResponse) {
          $('#connect').html('Connected! Hitting OmniAuth callback (GET /auth/facebook/callback)...');
          // since we have cookies enabled, this request will allow omniauth to parse
          // out the auth code from the signed request in the fbsr_XXX cookie
          $.getJSON('/auth/facebook/callback', function(json) {
            $('#connect').html('Connected! Callback complete.');
            $('#results').html(JSON.stringify(json));
          });
        }
      }, { scope: 'email,publish_stream' }); 
    });
  });
  &lt;/script&gt;
  &lt;p id="connect"&gt;
            &lt;a href="#"&gt;Connect to FB&lt;/a&gt;
          &lt;/p&gt;
  
          &lt;p id="results" /&gt;
  </code></pre>
  
  <p>I'm getting the following error in my log</p>
  
  <blockquote>
    <p>{"error":{"message":"Missing authorization
    code","type":"OAuthException","code":1}}</p>
  </blockquote>
  
  <p>Basically, Omniauth is not picking up on the facebook signed request from the FB.login action (as <a href="https://github.com/mkdynamic/omniauth-facebook/blob/master/example/config.ru" rel="nofollow">https://github.com/mkdynamic/omniauth-facebook/blob/master/example/config.ru</a> says it's supposed to).</p>
  
  <p><strong>Any ideas on how I can get this to work properly or what I may be doing incorrectly?</strong></p>