Reputation: 714
I'm newbie in Node.js and just want to create RESTful API with it for my game in Unity3D. Just at the end of the game I want some information like name and phone number, etc from player if he/she wants to share. I know how to implement this server but my problem is with security. I've search a lot about security in Node.js but I've not figured it out yet. In my searches I've saw there is a npm package which is JWT and figured out how to use it. As I know we send a request to the server and in response it returns a bearer token which we can set our header with it and use GET, POST or other methods. My problem is that anyone can send a request to that URL and get that token and do other things (I think I made a mistake). So what is the solution for security of this type of server ?
Upvotes: 0
Views: 1193
Reputation: 2395
Well there are multiple authentication strategies (basic, oauth, token, cookies). Since you have already chosen the JWT strategy I will try to explain it.
jwt.sign({ id: user.id, role: user.role }, 'secret', { expiresIn: 60 * 60})
jwt.verify(token, 'your secret')
Usually I use this package: https://github.com/auth0/node-jsonwebtoken where you can also set the encryption algorithm and more options.
Another explanation containing images: https://stackoverflow.com/a/45978644/4120554
Upvotes: 3