Decode the JWT

You application login page needs to decode the JWT passed to it and leverage the information as needed. You need two pieces of information to decode the JWT:

  1. encodedJWT = The JWT passed to the page.
  2. secret = The JWT signing secret key for your application used to decode the endcoded JWT. This value is stored on the installed package.

Check out our downloadable SDKs to see coding examples in a variety of languages. Below are examples of just the JWT decoding piece, leveraging external libraries referenced in the Resources section below.

C# Example of Decoding a JWT 

1using JWT; // install from https://github.com/johnsheehan/jwt
2using Newtonsoft.Json.Linq;
3
4namespace Example
5{
6    public class ExampleClass
7    {
8        string encodedJWT = "jwttokengoeshere";
9        string secret = "mysecret";
10        string decodedJWT = JWT.JsonWebToken.Decode(encodedJWT, secret);
11        JObject parsedJWT = JObject.Parse(decodedJWT);
12    }
13}

node.js Example of Decoding a JWT 

1var jwt = require("jwt-simple"); // install with: 'npm install jwt-simple'
2var encodedJWT = "jwttokengoeshere";
3var secret = "mysecret";
4var decodedJWT = jwt.decode(encodedJWT, secret);

PHP Example of Decoding a JWT 

1<?php
2require_once 'JWT.php'; // install from https://github.com/luciferous/jwt
3$encodedJWT = 'jwttokengoeshere';
4$secret = 'mysecret';
5$decodedJWT = JWT::decode($encodedJWT, $secret);
6?>

Ruby Example of Decoding a JWT 

1require "jwt"
2@encodedJWT = 'jwttokengoeshere';
3@secret = 'mysecret';
4@decodedJWT = JWT.decode(@encodedJWT.to_s,nil,@secret)

Related Items