-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtok.js
More file actions
48 lines (48 loc) · 1.06 KB
/
Copy pathtok.js
File metadata and controls
48 lines (48 loc) · 1.06 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const Uuid = require("node-uuid");
const jwt = require("jsonwebtoken");
const Moment = require('moment')
module.exports = function(options) {
this.add("role:token,cmd:send", (msg, res) => {
let tokenSign = jwt.sign(
{
data: "foobar"
},
"secret",
{ expiresIn: 5 }
);
let tokenVerify = jwt.verify(tokenSign, "secret");
res({
v1: Uuid.v1(),
v4: Uuid.v4(),
tokenSign,
tokenVerify
});
});
this.add("role:token,cmd:verify", (msg, res, body) => {
const expiration = Moment().add(1, 'hours').toISOString()
this.act(
{
role: "token",
cmd: "generate",
data: {
role: "token"
},
cache: true,
expired_at: expiration
},
(err, data) => {
this.act(
{
role: "token",
cmd: "check",
token: data.token,
cache: true
},
function(err, respond) {
res({ generate: data, check: respond, expiration });
}
);
}
);
});
};