【问题标题】:devise_token_auth is not returning the access-tokendevise_token_auth 没有返回访问令牌
【发布时间】:2017-02-01 17:50:26
【问题描述】:

我有一个 Rails 应用程序,它过去只使用 vanilla rails 前端和设计。我正在尝试将其更改为具有角度前端的 api 服务器,为此我决定使用 devise_token_auth 和 ng-token-auth。

我可以使用它们很好地登录,但是当我尝试导航到任何其他页面时,cookie 将被删除。

我认为问题在于 devise_token_auth 没有返回带有初始登录的访问令牌。

我已经有了

config.middleware.insert_before 0, "Rack::Cors" do
  allow do
    origins '*'   #note to self, tighten this up, this isnt secure enough
    resource '*',
    :headers => :any,
    :methods => [:get, :post, :delete, :put, :options, :head],
    :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
    :max_age => 0
  end
end

在我的 application.rb 中设置和

protect_from_forgery with: :null_session

在我的 application_controller.rb 中,这似乎是此类问题最常报告的解决方案,但它们对我不起作用

【问题讨论】:

    标签: ruby-on-rails angularjs devise


    【解决方案1】:

    原来问题是由 active_model_serializer 引起的。在这里找到解决方案:https://github.com/lynndylanhurley/devise_token_auth/issues/600 ,将serialization_scope :view_context 添加到我的application_controller.rb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多