I'm using jwt-simple to create an api key. Basically what it does is encode(secret+data)
and sends it attaching with the request. I'm aware that the server will decode(encode(secret+data))
and verify that it is a valid request.
Sample code found in jwt-simple
documentation:
var jwt = require('jwt-simple');
var payload = { foo: 'bar' };
var secret = 'xxx';
// encode
var token = jwt.encode(payload, secret);
// decode
var decoded = jwt.decode(token, secret);
console.log(decoded); //=> { foo: 'bar' }
My questions are:
- Wouldn't someone be able to access the API if they know the token generated by
encode(data+key)
? Is that why I should use HTTPS over HTTP? - I think I need to store the secret of each user on the server as well, since it will be needed to decode. Where should I store it if I'm not correct?
- How would I send multiple API requests? Is there a better way other than sending the API key for every request?
Thanks in advance.