错误解码签名JWT认证Android

Error decodin signature JWT authentication Android

我将 Django 与 rest_framework 一起使用,并且我激活了 JSONWebTokenAuthentication 。当我为登录用户执行 Post 时,一切似乎都正常,我得到了一个令牌。如果我在 jwt.io 中验证该令牌,我将获得签名验证。但是,当我将任何 get 或 post 发送到服务器中的端点并在 header 中输入 "Authorization: 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 是一个静态字段,我在身份验证后从服务器检索令牌时将其存储在其中。

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

我认为您的问题是您将令牌作为 json object 发送,而不是发送令牌本身:

D/RETROFIT﹕ Authorization: JWT <token>

如果您想将令牌作为 json 发送,您应该在 body 中发送,而不是在授权 header 中发送。

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