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,以确定谁发送一次身份验证的邮件用户。这种识别哪些用户发送消息的方法有多安全?如何伪造令牌并冒充用户?只知道密钥?有什么方法可以用来破解这种安全形式?我如何确保选择的安全方法是安全的?