/// <summary> /// Given a JWT, decode it and return the payload as an object (by deserializing it with <see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>). /// </summary> /// <typeparam name="T">The <see cref="Type"/> to return</typeparam> /// <param name="token">The JWT.</param> /// <param name="key">The key that was used to sign the JWT.</param> /// <param name="verify">Whether to verify the signature (default is true).</param> /// <returns>An object representing the payload.</returns> /// <exception cref="SignatureVerificationException">Thrown if the verify parameter was true and the signature was NOT valid or if the JWT was signed with an unsupported algorithm.</exception> public static T DecodeToObject <T>(string token, string key, bool verify = true) { var payloadJson = JsonWebToken.Decode(token, key, verify); var payloadData = JsonConvert.DeserializeObject <T>(payloadJson); return(payloadData); }
/// <summary> /// Given a JWT, decode it and return the payload as an object (by deserializing it with <see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>). /// </summary> /// <param name="token">The JWT.</param> /// <param name="key">The key that was used to sign the JWT.</param> /// <param name="verify">Whether to verify the signature (default is true).</param> /// <returns>An object representing the payload.</returns> /// <exception cref="SignatureVerificationException">Thrown if the verify parameter was true and the signature was NOT valid or if the JWT was signed with an unsupported algorithm.</exception> public static object DecodeToObject(string token, string key, bool verify = true) { var payloadJson = JsonWebToken.Decode(token, key, verify); var payloadData = jsonSerializer.Deserialize <Dictionary <string, object> >(payloadJson); return(payloadData); }