I'm learning about how to implement security with regards to authentication, especially JWT tokens. My understanding is that the JWT token, once signed by the server, is given back to the user, whom should keep the token until he or she logs out.
var token = jwt.sign(user, 'secret');
signs the user object with the secret 'secret'
in Javascript, and user
might look something like this:
user = {
name: 'bob',
password: 'bobpassword'
}
when verifying, we simply call jwt.verify(token, 'secret')
to verify that the corresponding token is the user.
However, wouldn't this signature/token be the same every time? Our secret here is always 'secret'
, so should we change the secret every login? Then how are we to store the secret so it's secure? Or should we add some type of random string to user
every time?
I'm simply looking for the proper approach here in terms of security.