Rails从角度进行令牌认证

时间:2013-09-04 03:19:39

标签: ruby-on-rails authentication angularjs

我使用rails-api开发了一个API。

为了实现te API身份验证,我遵循了railscast:http://railscasts.com/episodes/352-securing-an-api

在示例中,它使用authenticate_or_request_with_http_token中的ActionController::HttpAuthentication::Token::ControllerMethods来检查是否存在身份验证令牌。

我不知道怎么做是将此令牌从Angular发送到API。我必须把它放在标题中吗?什么标题?是否必须以某种方式编码?

1 个答案:

答案 0 :(得分:3)

刚刚找到解决方案:

  • 必须像var authorizationHeader = 'Token token="' + token + '"'
  • 一样发送令牌
  • 该字符串必须在AUTHORIZATION标题中设置。