如何使用 devise_token_auth rails gem 正确验证用户身份?
how to properly authenticate user with devise_token_auth rails gem?
我正在尝试为 URL 编写一个简单的测试,它应该只对登录用户可见(我使用 before_action :authenticate_user!
来实现)。
即使我(认为)我正确分配了所有 headers 我总是得到 JSON 响应 {"errors":["Authorized users only."]}
我的测试看起来像这样(登录(以获取 header 信息)然后访问受保护的 URL 以及所需的所有 headers)
post "/api/v1/auth/sign_in", {:email => user.email, password: 'password'}
header_hash = {
'access-token' => response.headers['access-token'],
'uid' => response.headers['uid'],
'client' => response.headers['client'],
'expiry' => response.headers['expiry']
}
get "/api/v1/subscription_status", nil , header_hash
我做错了什么?
我不知道身份验证令牌在默认情况下会根据每个请求更改。
conf/device_token_auth.rb
config.change_headers_on_each_request = false
我将此设置设为 false,然后我得到了预期的响应。
我正在尝试为 URL 编写一个简单的测试,它应该只对登录用户可见(我使用 before_action :authenticate_user!
来实现)。
即使我(认为)我正确分配了所有 headers 我总是得到 JSON 响应 {"errors":["Authorized users only."]}
我的测试看起来像这样(登录(以获取 header 信息)然后访问受保护的 URL 以及所需的所有 headers)
post "/api/v1/auth/sign_in", {:email => user.email, password: 'password'}
header_hash = {
'access-token' => response.headers['access-token'],
'uid' => response.headers['uid'],
'client' => response.headers['client'],
'expiry' => response.headers['expiry']
}
get "/api/v1/subscription_status", nil , header_hash
我做错了什么?
我不知道身份验证令牌在默认情况下会根据每个请求更改。
conf/device_token_auth.rb
config.change_headers_on_each_request = false
我将此设置设为 false,然后我得到了预期的响应。