cuongld2 / springboot-simpleAPI

23 stars 16 forks source link

JWT Token does not begin with Bearer String #4

Open nejatian opened 4 years ago

nejatian commented 4 years ago

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?

cuongld2 commented 4 years ago

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.

nejatian commented 4 years ago

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 commented 4 years ago

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?!