Skip to content

Commit 7a0b1a6

Browse files
committed
More conceptual fixes for the introduction.
1 parent 337e445 commit 7a0b1a6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

views/website/md/introduction.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ JSON Web Token (JWT) is an open standard ([RFC 7519](https://tools.ietf.org/html
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

8-
Let's explain some concepts further.
9-
10-
- **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.
11-
12-
- **Self-contained**: The payload may contain extra information about the user, avoiding the need to query the database more than once.
13-
148
## When should you use JSON Web Tokens?
159
Here are some scenarios where JSON Web Tokens are useful:
1610

17-
- **Authentication**: This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains.
11+
- **Authorization**: This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains.
1812

1913
- **Information Exchange**: JSON Web Tokens are a good way of securely transmitting information between parties. Because JWTs can be signed—for example, using public/private key pairs—you can be sure the senders are who they say they are. Additionally, as the signature is calculated using the header and the payload, you can also verify that the content hasn't been tampered with.
2014

@@ -107,13 +101,17 @@ Whenever the user wants to access a protected route or resource, the user agent
107101
Authorization: Bearer <token>
108102
```
109103

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.
104+
This can be, in certain cases, a stateless authorization 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 contains the necessary data, the need to query the database for certain operations may be reduced, though this may not always be the case.
105+
106+
If the token is sent in the `Authorization` header, Cross-Origin Resource Sharing (CORS) won't be an issue as it doesn't use cookies.
111107

112-
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.
108+
The following diagram shows how a JWT is obtained and used to access APIs or resources:
113109

114-
The following diagram shows this process:
110+
![How does a JSON Web Token works](https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png)
115111

116-
![How does a JSON Web Token works](https://cdn.auth0.com/content/jwt/jwt-diagram.png)
112+
1. The application or client requests authorization to the authorization server. This is performed through one of the different authorization flows. For example, a typical [OpenID Connect](http://openid.net/connect/) compliant web application will go through the `/oauth/authorize` endpoint using the [authorization code flow](http://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth).
113+
2. When the authorization is granted, the authorization server returns an access token to the application.
114+
3. The application uses the access token to access a protected resource (like an API).
117115

118116
Do note that with signed tokens, all the information contained within the token is exposed to users or other parties, even though they are unable to change it. This means you should not put secret information within the token.
119117

0 commit comments

Comments
 (0)