admin管理员组文章数量:1396811
Just started looking a JWT and the examples I have seen first require the user to do a POST request with the body of the request containing the username and password in plain text. After this request has been authenticated, a JWT is sent which is then used is further requests.
Clearly I am missing something here but have I not just sent unsecure data on my first request? Is this where I would need HTTPS?
Just started looking a JWT and the examples I have seen first require the user to do a POST request with the body of the request containing the username and password in plain text. After this request has been authenticated, a JWT is sent which is then used is further requests.
Clearly I am missing something here but have I not just sent unsecure data on my first request? Is this where I would need HTTPS?
Share Improve this question edited Feb 12, 2017 at 15:04 webdeb 13.2k5 gold badges29 silver badges44 bronze badges asked Feb 12, 2017 at 14:29 JD.JD. 15.6k22 gold badges92 silver badges165 bronze badges 2- 1 Yes, you should send the username/password over https – webdeb Commented Feb 12, 2017 at 15:03
- @webdeb Thanks. What if I make a call to the server which will give me a web token and then I send the username/password. Would that work? Also if I have https, do I just do the first call with HTTPS and then the rest are done with web tokens? – JD. Commented Feb 12, 2017 at 16:18
2 Answers
Reset to default 5JWT doesn't give you security out of the box it's main point is to make sure that the Token wasn't changed by untrusted authority. It just verifies that the data inside is correct.
However, the JWT itself, the data block of it is readable by anyone, you can just parse it on the client, and read the userName / email / from it, if you want to, so an attacker could read it too, if the data block itself is not encrypted.
HTTPS would encrypt all the data wich is passed between client <-> server. It has nothing to do with authentication, its just a protocol, you should use it anyway, either with JWT or not.
JWT are used for authenticating a user that already authenticated himself to the server before, and are really useful in stateless environments, not really in stateful environments.
The purpose of JWT is to store enough data on the user, so that the server that receives it can use it to decide if the user is legit and what he can do. They are really useful in distributed environments, because then you can just pass the JWT from one server to another, and as long as they all hold the signing key, they will be able to authenticate the user only based on the token.
The username and password are only required for the server in the first request, so the server can authenticate the user against a database of users for example, and then, every request after will use the token, making the server to be able to authenticate the user without another round trip to the database on every request.
As far as HTTPS goes, I would say - use it for everything. In today's wireless networks everywhere, your data is much more exposed than before.
本文标签: javascriptUsing JWT to send usernamepassword to authenticateStack Overflow
版权声明:本文标题:javascript - Using JWT to send username, password to authenticate - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744134825a2592349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论