arun11299 / cpp-jwt

JSON Web Token library for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decoding error

Farrukhqazi opened this issue · comments

I might be doing something wrong but when I try the following code, it fails as an InvalidAlgorithmError.

  auto enc_str_new = "eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.vj7aQzrGKx5sAoigWCLRy2bZk_HV2lbLndVKlp2GMotYQp65g1NgCDz3zRbsUxZf";
auto dec_obj = jwt::decode(enc_str_new, algorithms({"HS256"}), secret(key));

Ideally I should be able to setup my code in order to receive the jwt token from a client and be able to decode and validate if its an authorized request?

Hi,
In the "algorithms" parameter you have to explicitly mention the list of possible algorithms using which the string could have been encoded with. In your specific case, it was encoded using HS384. You can check this at http://jwt.calebb.net/.

So, changing you code to something like below should make it work.

auto dec_obj = jwt::decode(enc_str_new, algorithms({"HS256", "HS384"}), secret(key));

Please reopen if you still see an issue.