Empty Payload / Payload not displaying
Closed this issue · 3 comments
S00083446 commented
I am getting a blank payload when trying to read. I did have to change the input and output to work from a Console App. Do you know why I might be getting an empty payload.
S00083446 commented
.WriteLine("Enter JWT");
string jwtInput = Console.ReadLine();
string jwtOutput = "";
//and the output will be placed in a control called txtJwtOut
JwtSecurityTokenHandler jwtHandler = new JwtSecurityTokenHandler();
// string jwtInput = txtJwtIn.Text;
//Check if readable token (string is in a JWT format)
bool readableToken = jwtHandler.CanReadToken(jwtInput);
if (readableToken != true)
{
Console.WriteLine("The token doesn't seem to be in a proper JWT format."); ;
}
if (readableToken == true)
{
JwtSecurityToken token = jwtHandler.ReadJwtToken(jwtInput);
//Extract the headers of the JWT
JwtHeader headers = token.Header;
string jwtHeader = "{";
foreach (KeyValuePair<string, object> h in headers)
{
jwtHeader += '"' + h.Key + "\":\"" + h.Value + "\",";
}
jwtHeader += "}";
Console.WriteLine("Header:\r\n" + JToken.Parse(jwtHeader).ToString(Formatting.Indented));
//Extract the payload of the JWT
IEnumerable<Claim> claims = token.Claims;
string jwtPayload = "{";
foreach (Claim c in claims)
{
jwtPayload += '"' + c.Type + "\":\"" + c.Value + "\",";
}
jwtPayload += "}";
jwtOutput += "\r\nPayload:\r\n" + JToken.Parse(jwtPayload).ToString(Formatting.Indented);
Console.WriteLine(jwtOutput.ToString());
Console.ReadLine();
}
ahelland commented
Right off the bat I don't know why that's happening.
I have a slightly different implementation of the parsing here though that you can try: https://gist.github.com/ahelland/f7151b665c09193bae5e1f05766260a4
S00083446 commented
Thanks for the response. Will try this implementation in the morning.
On 17 Jun 2019 21:26, Andreas Helland <notifications@github.com> wrote:
Right off the bat I don't know why that's happening.
I have a slightly different implementation of the parsing here though that you can try: https://gist.github.com/ahelland/f7151b665c09193bae5e1f05766260a4
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#3?email_source=notifications&email_token=AGCGFLCUMKXLHZGJ4EHEIKDP27XQJA5CNFSM4HXKT36KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX4LFHY#issuecomment-502837919>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AGCGFLFZWSAHFV2QQF2FNV3P27XQJANCNFSM4HXKT36A>.