Posts

Showing posts from June, 2020

JWT Token Auth | JSON Web Tokens in Node.JS

Image
When you create a REST service or any backend server for a website or an app, there is one talk about this new trending method for authenticating the user who is requesting your servers for data.   Previously there were only a few ways to know where is the request coming from. That could be storing  cookies, sessions in browsers, and using them to identify the user. So this method evolved, the trick is to create a string that has info of the user and data about the user.   So JWT has payload, header, and signature which has info of the user and other important data. Why JSON you ask? because JSON is less verbose than XML and when encoded the size is small to easily use in HTTP transmissions. The authorization token is passed as:   Authorization: Bearer <token> How it works? User signs in with username and password.  The server creates a JWT using one of the algorithms (HMAC, RSA, or ECDSA). Then this token is sent to the user and every