You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73Lines changed: 73 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3056,6 +3056,79 @@ async function logFetch(url) {
3056
3056
</div>
3057
3057
3058
3058
#### 72Q. ***How to use JSON Web Token (JWT) for authentication in Node.js?***
3059
+
3060
+
JSON Web Token (JWT) is an open standard that defines a compact and self-contained way of securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.
3061
+
3062
+
There are some advantages of using JWT for authorization:
3063
+
3064
+
* Purely stateless. No additional server or infra required to store session information.
3065
+
* It can be easily shared among services.
3066
+
3067
+
JSON Web Tokens consist of three parts separated by dots (.), which are:
3068
+
3069
+
***Header** - Consists of two parts: the type of token (i.e., JWT) and the signing algorithm (i.e., HS512)
3070
+
***Payload** - Contains the claims that provide information about a user who has been authenticated along with other information such as token expiration time.
3071
+
***Signature** - Final part of a token that wraps in the encoded header and payload, along with the algorithm and a secret
The `jwt.sign()` method takes a payload and the secret key defined in `config.js` as parameters. It creates a unique string of characters representing the payload. In our case, the payload is an object containing only the id of the user.
0 commit comments