Skip to content

Commit

Permalink
Added byte[] key overload for non-generic version of DecodeToObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Rasmussen committed May 26, 2015
1 parent 0a3558e commit 6398313
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion JWT/JWT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,26 @@ public static string Decode(string token, string key, bool verify = true)
/// <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)
public static object DecodeToObject(string token, byte[] key, bool verify = true)
{
var payloadJson = JsonWebToken.Decode(token, key, verify);
var payloadData = JsonSerializer.Deserialize<Dictionary<string, object>>(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)
{
return DecodeToObject(token, Encoding.UTF8.GetBytes(key), verify);
}

/// <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>
Expand Down

0 comments on commit 6398313

Please sign in to comment.