【问题标题】:Thingsboard REST api always responds with status 401Thingsboard REST api 始终以状态 401 响应
【发布时间】:2017-03-27 19:30:03
【问题描述】:

首先我使用 curl 命令获得了一个令牌,如 here 所示。然后用这个token授权swagger,尝试了一些endpoints,但是都回复了

    {
      "status": 401,
      "message": "Authentication failed",
      "errorCode": 10,
      "timestamp": 1490619586352
    }

在服务器端我得到这个异常:

2017-03-27 13:31:16,149 [http-nio-0.0.0.0-8080-exec-9] ERROR o.t.s.s.s.m.token.RawAccessJwtToken - Invalid JWT Token io.jsonwebtoken.MalformedJwtException: Unable to read JSON value: ��!L��ȉ

我也用 curl 尝试了这个,结果相同,使用以下语法:

curl -X GET --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'X-Authorization: MY_TOKEN' 'http://MY_SERVER:MY_PORT/api/tenants?limit=3'

我为我的服务器适当地更改了 MY_TOKEN、MY_SERVER 和 MY_PORT。

【问题讨论】:

    标签: thingsboard


    【解决方案1】:

    似乎其中一个标头缺少参数(Bearer)。应该是--header 'X-Authorization: Bearer MY_TOKEN'。当我添加它时,响应符合预期。所以 curl 的完整命令是: curl -X GET --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'X-Authorization: Bearer MY_TOKEN' 'http://MY_SERVER:MY_PORT/api/tenants?limit=3'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2016-12-27
      • 1970-01-01
      • 2018-12-04
      相关资源
      最近更新 更多