jwt

Sever/Node.js 2019. 1. 1. 23:45
반응형


https://velopert.com/2389


https://victorydntmd.tistory.com/116


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"
};
 
//https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_method_buffer_from_str_encoding
// (node:4148) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please
// use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
var buf = Buffer.from(JSON.stringify(header));
var encoedHeader = buf.toString('base64');
 
console.log('header: ', encoedHeader);
 
const payload = {
    "iss""velopert.com",
    "exp""1485270000000",
    "https://velopert.com/jwt_claims/is_admin"true,
    "userId""11028373727102",
    "username""velopert"
};
 
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64').replace('=''');
console.log('payload: ', encodedPayload);
 
 
const crypto = require('crypto');
const signature = crypto.createHmac('sha256''secret').update(encoedHeader + '.' + encodedPayload).digest('base64').replace('=''');
console.log('signature: ' , signature);
cs



PS D:\workspace\node\study-11> node test.js

header:  eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9

payload:  eyJpc3MiOiJ2ZWxvcGVydC5jb20iLCJleHAiOiIxNDg1MjcwMDAwMDAwIiwiaHR0cHM6Ly92ZWxvcGVydC5jb20vand0X2NsYWltcy9pc19hZG1pbiI6dHJ1ZSwidXNlcklkIjoiMTEwMjgzNzM3MjcxMDIiLCJ1c2VybmFtZSI6InZlbG9wZXJ0In0

signature:  WE5fMufM0NDSVGJ8cAolXGkyB5RmYwCto1pQwDIqo2w



https://jwt.io/




반응형

'Sever > Node.js' 카테고리의 다른 글

jwt 스터디 2차  (0) 2019.01.03
jwt 스터디 1차  (0) 2019.01.02
Node.js Passport login  (0) 2018.12.20
Study : Express, RESTful API  (0) 2018.10.24
카페24 node.js + mysql + unity 연동 (CRUD, RestfulAPI)  (4) 2018.10.22
: