无法解码令牌:令牌是无效的JWS

时间:2016-11-07 17:46:45

标签: laravel-5.2 jwt restful-authentication lumen-5.3

如何解决JWT身份验证

{
    "message": "Could not decode token: The token \"eyJ0eiJ9.eyJzFiZjFlYTJmMWUiLCJzdWIiOjd9.nKQh9u5-yO2l1uTH5Zs\" is an invalid JWS",
  "status_code": 401,
  "debug": {
    "line": 50,
    "file": "/home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Auth/Provider/JWT.php",
    "class": "Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException",
    "trace": [
        "#0 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Auth/Auth.php(82): Dingo\\Api\\Auth\\Provider\\JWT->authenticate(Object(Dingo\\Api\\Http\\Request), Object(Dingo\\Api\\Routing\\Route))",
        "#1 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Http/Middleware/Auth.php(50): Dingo\\Api\\Auth\\Auth->authenticate(Array)",
        "#2 [internal function]: Dingo\\Api\\Http\\Middleware\\Auth->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
        "#3 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
        "#4 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#5 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
        "#6 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Http/Middleware/PrepareController.php(45): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#7 [internal function]: Dingo\\Api\\Http\\Middleware\\PrepareController->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
        "#8 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
        "#9 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#10 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
        "#11 [internal function]: Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#12 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
        "#13 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(626): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
        "#14 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(475): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))",
        "#15 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(449): Laravel\\Lumen\\Application->handleFoundRoute(Array)",
        "#16 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(380): Laravel\\Lumen\\Application->handleDispatcherResponse(Array)",
        "#17 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(629): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()",
        "#18 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(382): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))",
        "#19 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Routing/Adapter/Lumen.php(103): Laravel\\Lumen\\Application->dispatch(Object(Dingo\\Api\\Http\\Request))",
        "#20 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Routing/Router.php(574): Dingo\\Api\\Routing\\Adapter\\Lumen->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')",
        "#21 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Http/Middleware/Request.php(123): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
        "#22 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#23 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
        "#24 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
        "#25 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
        "#26 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Http/Middleware/Request.php(124): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
        "#27 /home/vagrant/Code/Laravel/ddd/vendor/dingo/api/src/Http/Middleware/Request.php(100): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))",
        "#28 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
        "#29 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
        "#30 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
        "#31 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
        "#32 [internal function]: Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
        "#33 /home/vagrant/Code/Laravel/ddd/vendor/illuminate/pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
        "#34 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(626): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
        "#35 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(382): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))",
        "#36 /home/vagrant/Code/Laravel/ddd/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(327): Laravel\\Lumen\\Application->dispatch(NULL)",
        "#37 /home/vagrant/Code/Laravel/ddd/public/index.php(28): Laravel\\Lumen\\Application->run()",
        "#38 {main}"
    ]
  }
}

1 个答案:

答案 0 :(得分:1)

令牌“eyJ0eiJ9.eyJzFiZjFlYTJmMWUiLCJzdWIiOjd9.nKQh9u5-yO2l1uTH5Zs”确实无效,因为其解码的头只包含“tz”条目,但正确的JWS应该包含一个包含“alg”值的头: https://tools.ietf.org/html/rfc7515#section-4.1.1

你可以解码,例如在jwt.io