-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'origin/clock_skew_tolerance' of https://github.com/jaco…
…pofar/node-jsonwebtoken into jacopofar-origin/clock_skew_tolerance
- Loading branch information
Showing
5 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,14 +43,16 @@ There are no default values for `expiresIn`, `notBefore`, `audience`, `subject`, | |
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
batmat
|
||
The header can be customized via the `option.header` object. | ||
|
||
Generated JWTs will include an `iat` claim by default unless `noTimestamp` is specified. | ||
Generated jwts will include an `iat` (issued at) claim by default unless `noTimestamp` is specified. If `iat` is inserted in the payload, it will be used instead of the real timestamp for calculating other things like `exp` given a timespan in `options.expiresIn`. | ||
|
||
Example | ||
|
||
```js | ||
// sign with default (HMAC SHA256) | ||
var jwt = require('jsonwebtoken'); | ||
var token = jwt.sign({ foo: 'bar' }, 'shhhhh'); | ||
//backdate a jwt 30 seconds | ||
var older_token = jwt.sign({ foo: 'bar', iat: Math.floor(Date.now() / 1000) - 30 }, 'shhhhh'); | ||
|
||
// sign with RSA SHA256 | ||
var cert = fs.readFileSync('private.key'); // get private key | ||
|
@@ -81,6 +83,8 @@ encoded public key for RSA and ECDSA. | |
* `ignoreExpiration`: if `true` do not validate the expiration of the token. | ||
* `ignoreNotBefore`... | ||
* `subject`: if you want to check subject (`sub`), provide a value here | ||
* `clockTolerance`: number of second to tolerate when checking the `nbf` and `exp` claims, to deal with small clock differences among different servers | ||
|
||
|
||
```js | ||
// verify a token symmetric - synchronous | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var jwt = require('../index'); | ||
var expect = require('chai').expect; | ||
|
||
describe('iat', function() { | ||
|
||
it('should work with a numeric iat not changing the expiration date', function () { | ||
var token = jwt.sign({foo: 123, iat: Math.floor(Date.now() / 1000) - 30}, '123', { expiresIn: 10 }); | ||
var result = jwt.verify(token, '123'); | ||
expect(result.exp).to.be.closeTo(Math.floor(Date.now() / 1000) + 10, 0.2); | ||
}); | ||
|
||
|
||
it('should throw if iat is not a number', function () { | ||
expect(function () { | ||
jwt.sign({foo: 123, iat:'hello'}, '123'); | ||
}).to.throw(/"iat" must be a number/); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?