Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nbf (Not Before) token claim validation #37

Closed
wants to merge 2 commits into from

Conversation

jhurdlow
Copy link

Added code and tests to support validation of 'nbf' claims in payload per section 4.1.5 of the JWT specification.

Jason Hurdlow added 2 commits March 28, 2016 14:06
Added code and tests to support validation of 'nbf' claims in payload
per section 4.1.5 of JWT specification.
To match usage.
@@ -173,6 +173,25 @@ private static void Verify(string decodedCrypto, string decodedSignature, string
throw new SignatureVerificationException("Token has expired.");
}
}
// verify nbf claim https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.5
if (payloadData.ContainsKey("nbf") && payloadData["nbf"] != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to use here:

object nbfObj;
if (payloadData.TryGetValue("nbf", out nbfObj) && nbfObj is int)
{
    int nbf = (int)nbfObj;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing as you suggest would remove symmetry with the 'exp' claim validation behavior. If that was done I would expect both to be changed, and they would lose the "Claim X must be an integer" exception (unless you nested the 'is int' check).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, consistency makes sense. I submitted a refactoring PR to improve the code here and there but the author never cared to review it.
P.S. you still can have proper exception by splitting the if condition into 2:

object nbfObj;
if (payloadData.TryGetValue("nbf", out nbfObj))
{
    if (!nbfObj is int)
        throw new SignatureVerificationException("Claim 'nbf' must be an integer.");
    int nbf = (int)nbfObj;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, do you still care about this pr? Would you mind to review/refactor it once again?

@abatishchev
Copy link
Member

Please rebase on the latest

@abatishchev
Copy link
Member

Can you please create a new branch based on the v2 codebase, see #67? Thanks!

@abatishchev
Copy link
Member

Redone in #81 for the v2 codebase

@abatishchev abatishchev closed this Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants