CyberSource/cybersource-rest-samples-csharp

Sample code for generating jwtBody not working well

hien-ngo opened this issue · 0 comments

jwtBody = "{\n\"digest\":\"" + digest + "\", \"digestAlgorithm\":\"SHA-256\", \"iat\":\"" + DateTime.Now.ToUniversalTime().ToString("r") + "\"}";

As you see in line 174, the code was performed manual JSON creation so when submitting the code to CYBS, it threw a bad_request error and I spend around half-day to identifying what is going wrong.
After that, I've found that the code block should be:
var obj = new { digest = digest, digestAlgorithm = "SHA-256", iat = DateTime.Now.ToUniversalTime().ToString("r") }; jwtBody = JsonConvert.SerializeObject(obj);
Because when you perform the code by using manual JSON, it was not correct when generating the JWT token, and it always thrown bad_request. After I changed it to above code block, it's working normally.