Archive
[node express] JWT
livemehere
2022. 4. 4. 04:03
json web token
사용할때 유의할 점은 token에 모든걸담으면안됩니다.
token은 공식사이트에서나, 그냥 decode() 함수를 이용해서 모두 노출이 될수있고,
만약 token이 수정됬는지를 판단하는 것을 verify()로 검증 할 수 있습니다.
즉, 토큰을 검증된 수단으로, 서버에게 인증할 수단으로 사용해야하지, 모든데이터, 많은데이터를 담으면 그대로 노출되는 것입니다.
const jwt = require("jsonwebtoken");
const secretKey = "koha";
const token = jwt.sign(
{
id: "kong12",
username: "kong",
age: 25,
},
secretKey,
{ expiresIn: "1 days" }
);
const result = jwt.decode(token);
console.log(result);
const result2 = jwt.verify(token, secretKey, (err, decoded) => {
if (err) console.log(err);
console.log(decoded);
});
반응형