devise_token_auth不返回访问令牌 [英] devise_token_auth is not returning the access-token

查看:67
本文介绍了devise_token_auth不返回访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序,该应用程序过去只是和设计一起使用香草Rails前端.我正尝试将其更改为前端有角度的api服务器,为此,我决定使用devise_token_auth和ng-token-auth.

I have a rails application that used to just use the vanilla rails front end along with devise. I'm trying to change it to an api server with an angular front end, to that end I've decided to use devise_token_auth and ng-token-auth.

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

I can use them to sign in fine, but when I try to navigate to to any other page the cookies are being deleted.

我认为问题在于devise_token_auth不会以初始登录返回访问令牌.

I think the problem is that devise_token_auth isnt returning the access-token with the initial sign in.

我已经有

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中设置并

set up in my application.rb and

protect_from_forgery with: :null_session

在我的application_controller.rb中,这似乎是最常见的解决此类问题的方法,但它们并没有为我工作

in my application_controller.rb, which seem to be the most commonly reported solutions for this sort of problem but they arent working for me

推荐答案

原来该问题是由active_model_serializer引起的.在此处找到解决方案: https://github.com/lynndylanhurley/devise_token_auth/issues/600,在我的application_controller.rb

Turns out the problem was being caused by active_model_serializer. Found the solution here: https://github.com/lynndylanhurley/devise_token_auth/issues/600 , added serialization_scope :view_context to my application_controller.rb

这篇关于devise_token_auth不返回访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆