Skip to content

Instantly share code, notes, and snippets.

@sadrakgunadi
Created January 25, 2019 14:40
Show Gist options
  • Save sadrakgunadi/d809bfe6f536906b9ba0a8f40adfc0a9 to your computer and use it in GitHub Desktop.
Save sadrakgunadi/d809bfe6f536906b9ba0a8f40adfc0a9 to your computer and use it in GitHub Desktop.
Decode JWT

Decode JWT

Includes types that provide support for creating, serializing and validating JSON Web Tokens.

Code

string strJWT = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJwZG0yeG9TbWowOXY4R2xWSjlBRm9iNkw3Ylk5aVVXMVdmanhlMWFIeTdrIn0.eyJqdGkiOiIwMGZlYmM3Ny0wMzA2LTQ1ZTItODk3NS0yZjIwOTIyN2JhZDMiLCJleHAiOjE1NDc3ODE2NzksIm5iZiI6MCwiaWF0IjoxNTQ3NzgxMDc5LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvbWFzdGVyIiwic3ViIjoiZWZiOTJhY2YtMmUzZS00YWUwLTg0NzUtOTA0NjE5YTVmOTkzIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibXlhcHAiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiIxZWIzNTViNi04YTI3LTQ0OWQtOTYzYy0yZTM2MDU2YmVkNjYiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC8iXSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJuYW1lIjoiU2FkcmFrIEd1bmFkaSIsInByZWZlcnJlZF91c2VybmFtZSI6InNhZHJhayIsImdpdmVuX25hbWUiOiJTYWRyYWsiLCJmYW1pbHlfbmFtZSI6Ikd1bmFkaSIsImVtYWlsIjoic2FkcmFrZ3VuYWRpQGdtYWlsLmNvbSJ9.a27L5tlh0AzhrDLOokl_vU-j2hkq3lFYedetM6Pts5sQADKQ3LTcHkrD11tDRnssnT5DM-1O94K2gzDi9DfZaPqL2Vo3oEC8PQ5os8SezVFm1QZc_YdocwUUYPwLvUnTq2VIcW4JyGEW_gKIxMtWBBCNcWBPTE-_s_CcN9-TL1GyOXbJdb4Y8c1orRtvaH2bE6bLW1lcDoUUL4PJrPSQPuh-rtGf6dExVGwuQouTAKHLReG-4C88ZimFLnKBdEiX8ff1V3aAXPGfPO5LFs1Qdr6IrIzLztXIqOqZ6FcISr7bM5eGheafjIa_q2dGvrGbcZW3UvCYbr_md5CrFtVwwA";

var handler = new JwtSecurityTokenHandler();
var tokenS = handler.ReadToken(strJWT) as JwtSecurityToken;

//contain all information about JWT Token data
IEnumerable < Claim > currentUser = tokenS.Claims;

var userDict = currentUser.ToDictionary(o = >o.Type, o = >o.Value);

//parse to JSON
string _jwtJson = JsonConvert.SerializeObject(userDict, Formatting.Indented);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment