我尝试使用 JWT token 访问 Stream feed,但每次都返回 404。
token header :
{
"alg": "HS256"
}
token 有效负载:
{
"resource": "feed",
"action": "read"
}
token 是使用 jjwt 生成的库并使用我的帐户仪表板中提供的 secret 进行签名。我还在 jwt.io 上验证了它,它是一个有效的 token
网址
GET: https://api.getstream.io/api/v1.0/feed/notification/666?api-key=...
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6ImZlZWQiLCJhY3Rpb24iOiJyZWFkIn0.MUZHXQg0UD6jFpCZN5Mn1e7wwys_1qYuVtfBKtHL8QU
回应
{
"exception": "GetStreamAPI404",
"detail": "sorry you've hit a 404"
}
我在这里遗漏了什么吗?无法弄清楚问题出在哪里。
最佳答案
为了执行正确的权限检查,您需要在 token 负载中包含 feed_id
字段。该字段的值必须与您尝试读取的 Feed 相同,且格式为 ${feed_group}:${feed_id}
。
例如,您的问题 ( https://api.getstream.io/api/v1.0/feed/notification/666?api-key= ) 中的请求的有效负载应为:
{
"resource": "feed",
"action": "read",
"feed_id": "notification:666"
}
注意:API URL 必须以斜杠结尾(例如/api/v1.0/feed/notification/666/?api_key=...)
身份验证 HTTP header :
授权必须仅包含 JWT token
stream-auth-type 必须与值 jwt 一起发送
关于getstream-io - 使用 JWT 访问 Stream REST Api 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39916749/