设计令牌身份验证和Omniauth CORS问题

时间:2017-11-12 21:56:05

标签: ruby-on-rails reactjs devise cors omniauth

我正在创建一个应用程序,其中SPA React前端与仅Rails 5 API后端集成。我已经设法通过在Rails应用程序中对公共端点进行api调用来连接这两个应用程序。所以我知道API正在运行。

我的下一步是集成Auth。我需要为FB,Github和Google实施Omniauth策略。我在rails应用程序上设置了Devise Token Auth gem并在各个提供程序上创建了应用程序密钥。我还设置了我的反应应用程序,以便在单击Sign in with ...按钮时调用各个端点。

当在前端点击按钮时似乎api设置正在调用OAuth提供程序,但是我在浏览器中看到错误,例如:...has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

我在我的rails应用程序中设置了Rack Cors gem并重新启动了我的服务器,但这没有任何区别。我注意到在Devise令牌auth repo here上报告了类似的问题,但还没有解决方案。

我很想知道我在这里遗失了什么?

我的CORS配置如下所示:

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*',
    :headers => :any,
    :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
    :methods => [:get, :post, :options, :delete, :put]
  end
end

0 个答案:

没有答案
相关问题