android - 错误decodin签名JWT认证Android

标签 android django retrofit

我将 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/

相关文章:

Android:对合并的游标进行排序

python - 将自定义按钮添加到 django cms ckeditor

android - 如何使用 Retrofit2 获取带有邮政编码 JSON 正文的地址列表

java - Retrofit 中的自定义超时消息

Android Studio焦点-切换到ClassFile

android - Android Studio Kotlin二维Button数组得到java.lang.ArrayIndexOutOfBoundsException:length = 0;索引= 0

android - exoplayer准备好后如何重新添加媒体源?

python - 属性错误 : Manager isn't accessible via Section instances

python - Django REST API 'get' 函数

android - Retrofit 接口(interface)中 Call 和 Observable Response 的区别