使用POST/sign_in登录.不支持GET.Omniauth Facebook的

Imr*_*qvi 12 ruby-on-rails devise omniauth ruby-on-rails-4

我在前端使用了ng-token-auth,在后端使用了devise_token_auth.现在我要在我的网站上实现omniauth-facebookomniauth-goole登录.但是我已经用以下功能完成了facebook登录

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
    });
};
Run Code Online (Sandbox Code Playgroud)

此时,登录成功,但是当它重定向时,它会在浏览器页面中显示以下错误

{"errors":["使用POST/sign_in登录.不支持GET."]}

的routes.rb

mount_devise_token_auth_for 'User', at: 'auth',:controllers => { :omniauth_callbacks => 'omniauth' }
Run Code Online (Sandbox Code Playgroud)

devise.rb

 config.omniauth :facebook,  'APP_KEY', 'APP_SECRET',{ :scope => 'email' }
Run Code Online (Sandbox Code Playgroud)

omn​​iauth控制器

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

这里是我的服务器日志

开始获取"/ 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)请求阶段已启动.

开始获取"/ 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)回调阶段已启动.I,[2016-03-12T18:34:36.790185#5978] INFO - omniauth:(facebook)回调阶段已启动.E,[2016-03-12T18:34:36.790636#5978]错误 - omniauth:(facebook)身份验证失败!csrf_detected:OmniAuth :: Strategies :: OAuth2 :: CallbackError,csrf_detected | CSRF检测到Devise :: OmniauthCallbacksController处理失败作为HTML参数:{"code"=>"AQARGivLmOzsdLxe ....."}重定向到 http:// localhost:3000/auth/sign_in已完成302在10ms内找到(ActiveRecord: 0.0ms)

在2016-03-12 18:34:36开始GET"/ auth/sign_in"为127.0.0.1 +0500由DeviseTokenAuth处理:: SessionsController #new为HTML完成405方法不允许在1ms(视图:0.2ms | ActiveRecord: 0.0ms)

Die*_*mez 0

我想我已经找到了一个可能的解决方案。经过一番研究,这似乎是 Facebook 的错误。调试应用程序和设计后,我发现我遇到了这个错误: "error":{"message":"This IP can't make requests for that application.","type":"OAuthException"原因,设计正在重定向到错误处理为了解决这个问题,我必须在facebook上添加我的公共IP(高级设置,允许的ips)才能解决问题。希望这有帮助