Skip to content

Commit f0e0954

Browse files
joshungerziluvatar
authored andcommitted
Update README.md (#461)
1 parent 092d55a commit f0e0954

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,32 @@ The header can be customized via the `options.header` object.
5555

5656
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`.
5757

58-
Example
58+
Sign with default (HMAC SHA256)
5959

6060
```js
61-
// sign with default (HMAC SHA256)
6261
var jwt = require('jsonwebtoken');
6362
var token = jwt.sign({ foo: 'bar' }, 'shhhhh');
64-
//backdate a jwt 30 seconds
65-
var older_token = jwt.sign({ foo: 'bar', iat: Math.floor(Date.now() / 1000) - 30 }, 'shhhhh');
63+
```
6664

65+
Sign with RSA SHA256
66+
```js
6767
// sign with RSA SHA256
68-
var cert = fs.readFileSync('private.key'); // get private key
68+
var cert = fs.readFileSync('private.key');
6969
var token = jwt.sign({ foo: 'bar' }, cert, { algorithm: 'RS256'});
70+
```
7071

71-
// sign asynchronously
72+
Sign asynchronously
73+
```js
7274
jwt.sign({ foo: 'bar' }, cert, { algorithm: 'RS256' }, function(err, token) {
7375
console.log(token);
7476
});
7577
```
7678

79+
Backdate a jwt 30 seconds
80+
```js
81+
var older_token = jwt.sign({ foo: 'bar', iat: Math.floor(Date.now() / 1000) - 30 }, 'shhhhh');
82+
```
83+
7784
#### Token Expiration (exp claim)
7885

7986
The standard for JWT defines an `exp` claim for expiration. The expiration is represented as a **NumericDate**:

0 commit comments

Comments
 (0)