springboot-simpleAPI icon indicating copy to clipboard operation
springboot-simpleAPI copied to clipboard

JWT Token does not begin with Bearer String

Open nejatian opened this issue 5 years ago • 3 comments

hi I can successfully authenticate my user but when I call another API I got this error: JWT Token does not begin with Bearer String and my postman shows this error:

{
    "timestamp": "2020-04-13T19:06:35.593+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/api/v1/acl/role"
}

I have checked my code in debugger and I saw header that is understood by code but this section of code doesn't work:

try {
                username = jwtTokenUtil.getUsernameFromToken(jwtToken);
            }

can you give me a help please?

nejatian avatar Apr 13 '20 19:04 nejatian

Hello nejatian, Thanks for creating an issue. JWT Token does not begin with Bearer String is a warning. I made some mistake when do that, just fixed it and push to master branch :). { "timestamp": "2020-04-13T19:06:35.593+0000", "status": 404, "error": "Not Found", "message": "No message available", "path": "/api/v1/acl/role" } This error happens because wrong path : "/api/v1/acl/role". Please check whether you define this path in the Request mapping. jwtTokenUtil.getUsernameFromToken(jwtToken) should work if we provide the Authorization Header and value starts with Bearer string. Hope you can find the answer by now. Thanks.

cuongld2 avatar Apr 14 '20 03:04 cuongld2

thank you for your responding, I recognize that one of my colleagues has changed the API path and I didn't notice that. you saved my time. thanks.

nejatian avatar Apr 14 '20 12:04 nejatian

Hi again, I have a question. I have changed the authentication field from username to email and I get the token, but whenever I try other APIs I put the given token in the header and I got this error: "message": "User not found with username: admin" I don't know how to validate my token with email?!

nejatian avatar May 02 '20 22:05 nejatian