Skip to content

Commit 337e445

Browse files
committed
Conceptual fixes in the introduction.
1 parent 1d5ce27 commit 337e445

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jwt.io",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/jsonwebtoken/jsonwebtoken.github.io"

views/website/md/introduction.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
**NEW:** get the [JWT Handbook for free](https://auth0.com/e-books/jwt-handbook) and learn JWTs in depth!
22

33
## What is JSON Web Token?
4-
JSON Web Token (JWT) is an open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the **HMAC** algorithm) or a public/private key pair using **RSA**.
4+
JSON Web Token (JWT) is an open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the **HMAC** algorithm) or a public/private key pair using **RSA** or **ECDSA**.
55

66
Although JWTs can be encrypted to also provide secrecy between parties, we will focus on *signed* tokens. Signed tokens can verify the *integrity* of the claims contained within it, while encrypted tokens *hide* those claims from other parties. When tokens are signed using public/private key pairs, the signature also certifies that only the party holding the private key is the one that signed it.
77

88
Let's explain some concepts further.
99

1010
- **Compact**: Because of their smaller size, JWTs can be sent through a URL, POST parameter, or inside an HTTP header. Additionally, the smaller size means transmission is fast.
1111

12-
- **Self-contained**: The payload contains all the required information about the user, avoiding the need to query the database more than once.
12+
- **Self-contained**: The payload may contain extra information about the user, avoiding the need to query the database more than once.
1313

1414
## When should you use JSON Web Tokens?
1515
Here are some scenarios where JSON Web Tokens are useful:
@@ -48,7 +48,7 @@ Then, this JSON is **Base64Url** encoded to form the first part of the JWT.
4848

4949
### Payload
5050

51-
The second part of the token is the payload, which contains the claims. Claims are statements about an entity (typically, the user) and additional metadata.
51+
The second part of the token is the payload, which contains the claims. Claims are statements about an entity (typically, the user) and additional data.
5252
There are three types of claims: *registered*, *public*, and *private* claims.
5353

5454
- [**Registered claims**](https://tools.ietf.org/html/rfc7519#section-4.1): These are a set of predefined claims which are not mandatory but recommended, to provide a set of useful, interoperable claims. Some of them are: **iss** (issuer), **exp** (expiration time), **sub** (subject), **aud** (audience), and [others](https://tools.ietf.org/html/rfc7519#section-4.1).
@@ -99,18 +99,15 @@ If you want to play with JWT and put these concepts into practice, you can use [
9999
![JWT.io Debugger](https://cdn.auth0.com/blog/legacy-app-auth/legacy-app-auth-5.png)
100100

101101
## How do JSON Web Tokens work?
102-
In authentication, when the user successfully logs in using their credentials, a JSON Web Token will be returned and must be saved locally (typically in local storage, but cookies can be also used), instead of the traditional approach of creating a session in the server and returning a cookie.
103-
104-
> There are security considerations that must be taken into account with regards to the way tokens are stored. These are enumerated in [Where to Store Tokens](https://auth0.com/docs/security/store-tokens).
102+
In authentication, when the user successfully logs in using their credentials, a JSON Web Token will be returned. Since tokens are credentials, great care must be taken to prevent security issues. In general, you should not keep tokens longer than required.
105103

106104
Whenever the user wants to access a protected route or resource, the user agent should send the JWT, typically in the **Authorization** header using the **Bearer** schema. The content of the header should look like the following:
107105

108106
```
109107
Authorization: Bearer <token>
110108
```
111109

112-
This is a stateless authentication mechanism as the user state is never saved in server memory.
113-
The server's protected routes will check for a valid JWT in the Authorization header, and if it's present, the user will be allowed to access protected resources. As JWTs are self-contained, all the necessary information is there, reducing the need to query the database multiple times.
110+
This can be, in certain cases, a stateless authentication mechanism. The server's protected routes will check for a valid JWT in the `Authorization` header, and if it's present, the user will be allowed to access protected resources. If the JWT is self-contained, all the necessary information is there, reducing the need to query the database multiple times.
114111

115112
This allows you to fully rely on data APIs that are stateless and even make requests to downstream services. It doesn't matter which domains are serving your APIs, so Cross-Origin Resource Sharing (CORS) won't be an issue as it doesn't use cookies.
116113

0 commit comments

Comments
 (0)