-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgate.js
28 lines (22 loc) · 932 Bytes
/
gate.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
const header = {
"typ": "JWT", // 토큰 타입
"alg": "HS256" // 해싱 알고리즘
}
// Encode to base64
const encodeHeader = new Buffer(JSON.stringify(header)).toString('base64').replace(/=/g," ");
console.log(encodeHeader);
const payload = {
// registered claims
"iss": "localhost", // 토큰발급자
"exp": "1485270000000", // 토근 만료시간 (NumericDate): 항상 현재 시간보다 이후로 설정되어있어야 한다
// public claims
"http://localhost/jwt_claims/is_admin": true,
// private claims
"userId": "11028373727102",
"username": "stonehye"
};
const encodePayload = new Buffer(JSON.stringify(payload)).toString('base64').replace(/=/g," ");
console.log(encodePayload);
const crypto = require('crypto');
const signature = crypto.createHmac('sha256', 'secret').update(encodeHeader + '.' + encodePayload).digest('base64').replace(/=/g," ");
console.log(signature);