Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use POST /sign_in to sign in. GET is not supported. Omniauth-facebook

I've ng-token-auth for frontend and devise_token_auth on the backend . Now i've to implement omniauth-facebook & omniauth-goole logins in my website .Yet i've done facebook login with the following functions

in config.js (ng-token-auth)

$scope.handleBtnClick = function() {
  console.log('here its')
  $auth.authenticate('facebook')
    .then(function(resp) {
      // handle success
    })
    .catch(function(resp) {
      // handle errors
    });
};

At this point , login occurs successfully , but when it redirects it shows me following error in my browser page

{"errors":["Use POST /sign_in to sign in. GET is not supported."]}

routes.rb

mount_devise_token_auth_for 'User', at: 'auth',:controllers => { :omniauth_callbacks => 'omniauth' }

devise.rb

 config.omniauth :facebook,  'APP_KEY', 'APP_SECRET',{ :scope => 'email' }

omniauth controller

class OmniauthController < Devise::OmniauthCallbacksController
        def facebook
            byebug
            @user = User.from_omniauth(request.env["omniauth.auth"])
            sign_in_and_redirect @user
        end
    end

ANd here are my server logs

Started GET "/omniauth/facebook?auth_origin_url=http%3A%2F%2Flocalhost%3A3000%2F%23%2F&omniauth_window_type=sameWindow&resource_class=User" for 127.0.0.1 at 2016-03-12 18:34:33 +0500 I, [2016-03-12T18:34:33.203521 #5978] INFO -- omniauth: (facebook) Request phase initiated.

Started GET "/omniauth/facebook/callback?code=AQARGivLmOz......" for 127.0.0.1 at 2016-03-12 18:34:34 +0500 I, [2016-03-12T18:34:34.189285 #5978] INFO -- omniauth: (facebook) Callback phase initiated. I, [2016-03-12T18:34:36.790185 #5978] INFO -- omniauth: (facebook) Callback phase initiated. E, [2016-03-12T18:34:36.790636 #5978] ERROR -- omniauth: (facebook) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected Processing by Devise::OmniauthCallbacksController#failure as HTML Parameters: {"code"=>"AQARGivLmOzsdLxe ..... "} Redirected to http://localhost:3000/auth/sign_in Completed 302 Found in 10ms (ActiveRecord: 0.0ms)

Started GET "/auth/sign_in" for 127.0.0.1 at 2016-03-12 18:34:36 +0500 Processing by DeviseTokenAuth::SessionsController#new as HTML Completed 405 Method Not Allowed in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)

like image 394
Mani Avatar asked Mar 12 '16 13:03

Mani


1 Answers

This worked for me:

mount_devise_token_auth_for 'User', at: 'auth',:controllers => { :omniauth_callbacks => 'omniauth' }, via: [:get, :post]
like image 132
luissimo Avatar answered Nov 15 '22 22:11

luissimo