fork download
  1. using JWT;
  2. using JWT.Algorithms;
  3. using JWT.Serializers;
  4. using JWT.Exceptions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text.Json;
  8.  
  9. string responsePayload = "{\"payload\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjaGFudElEIjoiMDE0MDAyMDI0MDExMTEyIiwiaW52b2ljZU5vIjoiSU5WMTIzNDU2IiwiZGVzY3JpcHRpb24iOiJpdGVtIDEiLCJhbW91bnQiOjEwMDAsImN1cnJlbmN5Q29kZSI6IlRIQiIsInBheW1lbnRDaGFubmVsIjpbIkNDIl19.IeJ2WVmHyhYrKsEfX-EOXxoAFQKkYGUUYz0VO3YmuAY "}";
  10.  
  11. var responseJSON = JsonSerializer.Deserialize<Dictionary<string, string>>(responsePayload);
  12. string responseToken = responseJSON["payload"];
  13.  
  14. string secret = "109B5916B12617F59A52ACB95E2183095FC15625E33F4342D6D185F5AA512BFC ";
  15.  
  16. try
  17. {
  18. var algorithm = new HMACSHA256Algorithm();
  19. var decoder = new JwtDecoder(new JsonNetSerializer(), new JwtValidator(new UtcDateTimeProvider()), new JwtBase64UrlEncoder(), algorithm);
  20.  
  21. var payload = decoder.Decode(responseToken, secret, verify: true);
  22. }
  23. catch catch (Exception ex)
  24. {
  25. Console.WriteLine($"An error occurred: {ex.Message}");
  26. }
  27.  
Success #stdin #stdout 0.02s 25924KB
stdin
Standard input is empty
stdout
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using JWT.Exceptions;
using System;
using System.Collections.Generic;
using System.Text.Json;

string responsePayload = "{\"payload\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjaGFudElEIjoiMDE0MDAyMDI0MDExMTEyIiwiaW52b2ljZU5vIjoiSU5WMTIzNDU2IiwiZGVzY3JpcHRpb24iOiJpdGVtIDEiLCJhbW91bnQiOjEwMDAsImN1cnJlbmN5Q29kZSI6IlRIQiIsInBheW1lbnRDaGFubmVsIjpbIkNDIl19.IeJ2WVmHyhYrKsEfX-EOXxoAFQKkYGUUYz0VO3YmuAY "}";

var responseJSON = JsonSerializer.Deserialize<Dictionary<string, string>>(responsePayload);
string responseToken = responseJSON["payload"];

string secret = "109B5916B12617F59A52ACB95E2183095FC15625E33F4342D6D185F5AA512BFC ";

try
{
  var algorithm = new HMACSHA256Algorithm();
  var decoder = new JwtDecoder(new JsonNetSerializer(), new JwtValidator(new UtcDateTimeProvider()), new JwtBase64UrlEncoder(), algorithm);

  var payload = decoder.Decode(responseToken, secret, verify: true);
}
catch catch (Exception ex)
{
    Console.WriteLine($"An error occurred: {ex.Message}");
}