gpt4 book ai didi

android - 错误decodin签名JWT认证Android

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:21 24 4
gpt4 key购买 nike

我将 Django 与 rest_framework 一起使用,并激活了 JSONWebTokenAuthentication 。当我为登录用户做一个帖子时,一切似乎都工作正常,我得到了一个 token 。如果我在 jwt.io 中验证该 token 我得到了签名验证。但是,当我将任何 get 或 post 发送到服务器中的端点并在 header 中输入“授权:JWT”时,我得到以下信息。

06-26 12:20:58.832    5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Authorization: JWT {token:<token>}
06-26 12:20:58.842 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ ---> END HTTP (no body)

06-26 12:20:59.322 5293-7833/com.infortec.angel.montalbanwebser

D/RETROFIT﹕ : HTTP/1.0 403 FORBIDDEN
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Allow: GET, POST, HEAD, OPTIONS
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Content-Type: application/json
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Date: Fri, 26 Jun 2015 10:19:34 GMT
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Server: WSGIServer/0.1 Python/2.7.3
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ Vary: Accept, Cookie
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ X-Android-Received-Millis: 1435314059321
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ X-Android-Response-Source: NETWORK 403
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ X-Android-Selected-Transport: http/1.1
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ X-Android-Sent-Millis: 1435314059296
06-26 12:20:59.332 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ X-Frame-Options: SAMEORIGIN
06-26 12:20:59.342 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ {"detail":"Error decoding signature."}
06-26 12:20:59.342 5293-7833/com.infortec.angel.montalbanwebser D/RETROFIT﹕ <--- END HTTP (38-byte body)

{"detail":"Error decoding signature."}

编辑:我正在使用 RequestInterceptor 添加我的 header 。

 public class TokenRequestInterceptor implements RequestInterceptor{

@Override
public void intercept(RequestFacade request) {
request.addHeader("Content-Type", "application/json");
request.addHeader("Authorization", "JWT " + Utils.token);
}
}

Utils.token 是一个静态字段,当我在身份验证后从服务器检索 token 时,我会在其中存储 token 。

最佳答案

D/RETROFIT﹕ Authorization: JWT {token:<token>}

我认为您的问题是您将 token 作为 json 对象发送,而不是发送 token 本身:

D/RETROFIT﹕ Authorization: JWT <token>

如果您想将 token 作为 json 发送,您应该将其发送到正文中而不是授权 header 中。

$ curl -X POST -H "Content-Type: application/json" -d '{"token":"<TOKEN>"}' URL

关于android - 错误decodin签名JWT认证Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31070911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com