问题描述
我正在尝试获取 current_user 但非用户通过 API 请求的标头进行身份验证。
标头包括 access-token
、client
和 uid
,但它不进行身份验证并显示以下错误:
如需参考,请查看此repo
Filter chain halted as :authenticate_user! rendered or redirected
Completed 401 Unauthorized in 398625ms (Views: 0.3ms | ActiveRecord: 2.6ms | Allocations: 1598457)
回复:
{
"errors": [
"You need to sign in or sign up before continuing."
]
}
登录时的标头响应:
请求配置文件、演示端点
curl --location --request GET 'http://localhost:3000/tweets' \
--header 'client: TeS-DWwybwxqh9l3ZMn__A' \
--header 'uid: sahsantoshh@gmail.com' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer e1tO5DawJq0iISdsgOk-fg'
解决方法
请求丢失,访问令牌和到期
实际请求是
curl --location --request GET 'http://localhost:3000/tweets' \
--header 'Content-Type: application/json' \
--header 'client: TeS-DWwybwxqh9l3ZMn__A' \
--header 'uid: sahsantoshh@gmail.com' \
--header 'expiry: 1616149988' \
--header 'access-token: sjdinlkiijklnlaosihda' \