diff --git a/apisix/plugins/jwt-auth.lua b/apisix/plugins/jwt-auth.lua index eea71597b513..d1a9c0183a92 100644 --- a/apisix/plugins/jwt-auth.lua +++ b/apisix/plugins/jwt-auth.lua @@ -361,7 +361,8 @@ function _M.rewrite(conf, ctx) local jwt_obj = jwt:load_jwt(jwt_token) core.log.info("jwt object: ", core.json.delay_encode(jwt_obj)) if not jwt_obj.valid then - return 401, {message = jwt_obj.reason} + core.log.error("JWT token invalid: ", jwt_obj.reason) + return 401, {message = "JWT token invalid"} end local user_key = jwt_obj.payload and jwt_obj.payload.key @@ -392,7 +393,8 @@ function _M.rewrite(conf, ctx) core.log.info("jwt object: ", core.json.delay_encode(jwt_obj)) if not jwt_obj.verified then - return 401, {message = jwt_obj.reason} + core.log.error("JWT token verify failed: ", jwt_obj.reason) + return 401, {message = "JWT token verify failed"} end consumer_mod.attach_consumer(ctx, consumer, consumer_conf) diff --git a/t/plugin/jwt-auth.t b/t/plugin/jwt-auth.t index 87eb5802a064..9c2f74cc8f43 100644 --- a/t/plugin/jwt-auth.t +++ b/t/plugin/jwt-auth.t @@ -214,7 +214,9 @@ GET /hello GET /hello?jwt=invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2Mzg3MDUwMX0.pPNVvh-TQsdDzorRwa-uuiLYiEBODscp9wv0cwD6c68 --- error_code: 401 --- response_body -{"message":"invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"} +{"message":"JWT token invalid"} +--- error_log +JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 @@ -223,7 +225,9 @@ GET /hello?jwt=invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtl GET /hello?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2Mzg3MDUwMX0.pPNVvh-TQsdDzorRwa-uuiLYiEBODscp9wv0cwD6c68 --- error_code: 401 --- response_body -{"message":"'exp' claim expired at Tue, 23 Jul 2019 08:28:21 GMT"} +{"message":"JWT token verify failed"} +--- error_log +JWT token verify failed: 'exp' claim expired at Tue, 23 Jul 2019 08:28:21 GMT @@ -274,7 +278,9 @@ GET /hello Authorization: bearer invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTg3OTMxODU0MX0.fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs --- error_code: 401 --- response_body -{"message":"invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"} +{"message":"JWT token invalid"} +--- error_log +JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 @@ -425,7 +431,9 @@ hello world GET /hello?jwt=invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2Mzg3MDUwMX0.pPNVvh-TQsdDzorRwa-uuiLYiEBODscp9wv0cwD6c68 --- error_code: 401 --- response_body -{"message":"invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"} +{"message":"JWT token invalid"} +--- error_log +JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 @@ -436,7 +444,9 @@ GET /hello Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTg3OTMxODU0MX0.fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs --- error_code: 401 --- response_body -{"message":"signature mismatch: fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs"} +{"message":"JWT token verify failed"} +--- error_log +JWT token verify failed: signature mismatch: fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs