Skip to content

Commit

Permalink
Modify Comments.
Browse files Browse the repository at this point in the history
Remove Refs. not in use.
  • Loading branch information
arichika committed Dec 21, 2015
1 parent b7bbac3 commit 00944f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
42 changes: 21 additions & 21 deletions src/JwtDnx/JwtDnx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static string Encode(IDictionary<string, object> extraHeaders, object pay
/// <summary>
/// Creates a JWT given a payload, the signing key, and the algorithm to use.
/// </summary>
/// <param name="payload">An arbitrary payload (must be serializable to JSON via <see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>).</param>
/// <param name="payload">An arbitrary payload.</param>
/// <param name="key">The key used to sign the token.</param>
/// <param name="algorithm">The hash algorithm to use.</param>
/// <returns>The generated JWT.</returns>
Expand All @@ -85,7 +85,7 @@ public static string Encode(object payload, byte[] key, JwtHashAlgorithm algorit
/// Creates a JWT given a set of arbitrary extra headers, a payload, the signing key, and the algorithm to use.
/// </summary>
/// <param name="extraHeaders">An arbitrary set of extra headers. Will be augmented with the standard "typ" and "alg" headers.</param>
/// <param name="payload">An arbitrary payload (must be serializable to JSON via <see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>).</param>
/// <param name="payload">An arbitrary payload.</param>
/// <param name="key">The key bytes used to sign the token.</param>
/// <param name="algorithm">The hash algorithm to use.</param>
/// <returns>The generated JWT.</returns>
Expand All @@ -97,7 +97,7 @@ public static string Encode(IDictionary<string, object> extraHeaders, object pay
/// <summary>
/// Creates a JWT given a payload, the signing key, and the algorithm to use.
/// </summary>
/// <param name="payload">An arbitrary payload (must be serializable to JSON via <see cref="System.Web.Script.Serialization.JavaScriptSerializer"/>).</param>
/// <param name="payload">An arbitrary payload.</param>
/// <param name="key">The key used to sign the token.</param>
/// <param name="algorithm">The hash algorithm to use.</param>
/// <returns>The generated JWT.</returns>
Expand Down Expand Up @@ -152,29 +152,29 @@ private static void Verify(string decodedCrypto, string decodedSignature, string
{
if (decodedCrypto != decodedSignature)
{
throw new SignatureVerificationException(string.Format("Invalid signature. Expected {0} got {1}", decodedCrypto, decodedSignature));
throw new SignatureVerificationException(
$"Invalid signature. Expected {decodedCrypto} got {decodedSignature}");
}

// verify exp claim https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.4
var payloadData = JsonSerializer.Deserialize<Dictionary<string, object>>(payloadJson);
if (payloadData.ContainsKey("exp") && payloadData["exp"] != null)
if (!payloadData.ContainsKey("exp") || payloadData["exp"] == null) return;

// safely unpack a boxed int
int exp;
try
{
exp = Convert.ToInt32(payloadData["exp"]);
}
catch (Exception)
{
throw new SignatureVerificationException("Claim 'exp' must be an integer.");
}

var secondsSinceEpoch = Math.Round((DateTime.UtcNow - UnixEpoch).TotalSeconds);
if (secondsSinceEpoch >= exp)
{
// safely unpack a boxed int
int exp;
try
{
exp = Convert.ToInt32(payloadData["exp"]);
}
catch (Exception)
{
throw new SignatureVerificationException("Claim 'exp' must be an integer.");
}

var secondsSinceEpoch = Math.Round((DateTime.UtcNow - UnixEpoch).TotalSeconds);
if (secondsSinceEpoch >= exp)
{
throw new SignatureVerificationException("Token has expired.");
}
throw new SignatureVerificationException("Token has expired.");
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/JwtDnx/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.0.0-*",
"description": "JwtDnx Class Library",
"authors": [ "@arichika(arichika.taniguchi)" ],
"version": "1.0.1-*",
"description": "JwtDnx is JWT / JWS Implementation for .NET DNX (like ASP.NET 5 MVC 6)",
"authors": [ "@arichika (arichika.taniguchi)" ],
"tags": [ "" ],
"projectUrl": "https://github.com/SiroccoHub/JwtDnx",
"licenseUrl": "https://github.com/SiroccoHub/JwtDnx/blob/master/LICENSE.txt",
Expand All @@ -14,10 +14,6 @@
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516"
}
}
Expand Down

0 comments on commit 00944f1

Please sign in to comment.