forked from johntango/hashDemoBlockies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignHMAC.js
35 lines (27 loc) · 912 Bytes
/
signHMAC.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// sign with default (HMAC SHA256)
var jwt = require('jsonwebtoken');
var token = jwt.sign({ foo: 'bar' }, 'shhhhh');
console.log('token:');
console.log(token);
// verify a token symmetric - synchronous
var decoded = jwt.verify(token, 'shhhhh');
console.log('--------------');
console.log('decoded.foo:'); // bar
console.log(decoded.foo); // bar
console.log('--------------');
console.log('decoded:'); // bar
console.log(decoded);
console.log('--------------');
// verify a token symmetric - asynchronous
jwt.verify(token, 'shhhhh', function(err, decoded) {
console.log('--------------');
console.log('decoded.foo:'); // bar
console.log(decoded.foo); // bar
console.log('--------------');
});
// without verification
decoded = jwt.decode(token, {complete: true});
console.log('decoded.header:');
console.log(decoded.header);
console.log('decoded.payload:');
console.log(decoded.payload);