无法通过其令牌对用户进行身份验证,过滤器链停止为 :authenticate_user!呈现或重定向

问题描述

我正在尝试获取 current_user 但非用户通过 API 请求的标头进行身份验证。 标头包括 access-tokenclientuid,但它不进行身份验证并显示以下错误

如需参考,请查看此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."
 ]
}

登录时的标头响应:

enter image description here

请求配置文件、演示端点

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' \

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...