使用AngularJS和Rails的Token Auth无法从请求标头获取访问令牌

use*_*502 5 ruby-on-rails request-headers devise angularjs

我按照本教程设置了Angular和Rails的令牌认证:https://www.airpair.com/ruby-on-rails/posts/authentication-with-angularjs-and-ruby-on-rails

我正在尝试使用gem current_user提供的帮助器devise_token_auth.即使通过Angular(使用ng-token-auth)成功验证用户,也current_user总是false在Rails中返回.根据devise_token_auth文档(https://github.com/lynndylanhurley/devise_token_auth),"客户端应在每个请求的标题中包含身份验证信息".这些将是"访问令牌","到期","令牌类型","uid"和"客户端".

我认为我的问题是:在http:// localhost:3000 /#/ whatever(angular/client side),但在http:// localhost:3000时,我可以在Web检查器的网络选项卡中看到这些auth标头/ api/whatever(rails/server side),auth头不存在.因此request.headers['access-token'],例如,将返回零.

我在几个地方阅读了类似/相同的问题,主要是在这里:https://github.com/lynndylanhurley/devise_token_auth/issues/74,但还没有成功.

我通常不会问很多问题,所以希望这是有道理的.另外,我是Angular的新品牌,并且只在Rails游戏中使用了几年,所以如果这是一个愚蠢的问题......我的不好;)