0
可以說,我創建令牌像這樣:JWT編碼如何實現安全性?
def create_token(userId):
payload = {
# subject
'sub': userId,
#issued at
'iat': datetime.utcnow(),
#expiry
'exp': datetime.utcnow() + timedelta(days=1)
}
token = jwt.encode(payload, SECRET_KEY, algorithm='HS256')
return token.decode('unicode_escape')
節點socket.io
io.sockets
.on('connection', socketioJwt.authorize({
secret: 'SOME SECRET',
timeout: 15000
}))
.on('authenticated', function(socket) {
console.log('hello! ', socket.decoded_token);
socket.on('message', function(message) {
console.log(message);
io.emit('message', message);
});
})
.on('error', function(error) {
console.log(error.type);
console.log(error.code);
});
現在,我將使用用戶ID,以確定誰發送一次身份驗證的郵件用戶。這種識別哪些用戶發送消息的方法有多安全?如何僞造令牌並冒充用戶?只知道密鑰?有什麼方法可以用來破解這種安全形式?我如何確保選擇的安全方法是安全的?