From 337e445efffe28c27dac80f0ff03b9d106e327dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20E=2E=20Peyrott?= Date: Wed, 13 Jun 2018 22:11:37 -0300 Subject: [PATCH 1/3] Conceptual fixes in the introduction. --- package.json | 2 +- views/website/md/introduction.md | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 3046d2b4..a09be833 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jwt.io", - "version": "3.1.0", + "version": "3.1.1", "repository": { "type": "git", "url": "https://github.com/jsonwebtoken/jsonwebtoken.github.io" diff --git a/views/website/md/introduction.md b/views/website/md/introduction.md index b863ccc0..05de3616 100755 --- a/views/website/md/introduction.md +++ b/views/website/md/introduction.md @@ -1,7 +1,7 @@ **NEW:** get the [JWT Handbook for free](https://auth0.com/e-books/jwt-handbook) and learn JWTs in depth! ## What is JSON Web Token? -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**. +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**. 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. @@ -9,7 +9,7 @@ Let's explain some concepts further. - **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. -- **Self-contained**: The payload contains all the required information about the user, avoiding the need to query the database more than once. +- **Self-contained**: The payload may contain extra information about the user, avoiding the need to query the database more than once. ## When should you use JSON Web Tokens? 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. ### Payload -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. +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. There are three types of claims: *registered*, *public*, and *private* claims. - [**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,9 +99,7 @@ If you want to play with JWT and put these concepts into practice, you can use [ ![JWT.io Debugger](https://cdn.auth0.com/blog/legacy-app-auth/legacy-app-auth-5.png) ## How do JSON Web Tokens work? -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. - -> 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). +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. 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: @@ -109,8 +107,7 @@ Whenever the user wants to access a protected route or resource, the user agent Authorization: Bearer ``` -This is a stateless authentication mechanism as the user state is never saved in server memory. -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. +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. 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. From 7a0b1a6d947f1fd4c6712c640b0a36c5c13868e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20E=2E=20Peyrott?= Date: Thu, 14 Jun 2018 13:55:57 -0300 Subject: [PATCH 2/3] More conceptual fixes for the introduction. --- views/website/md/introduction.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/views/website/md/introduction.md b/views/website/md/introduction.md index 05de3616..d07d67bb 100755 --- a/views/website/md/introduction.md +++ b/views/website/md/introduction.md @@ -5,16 +5,10 @@ JSON Web Token (JWT) is an open standard ([RFC 7519](https://tools.ietf.org/html 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. -Let's explain some concepts further. - -- **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. - -- **Self-contained**: The payload may contain extra information about the user, avoiding the need to query the database more than once. - ## When should you use JSON Web Tokens? Here are some scenarios where JSON Web Tokens are useful: -- **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. +- **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. - **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. @@ -107,13 +101,17 @@ Whenever the user wants to access a protected route or resource, the user agent Authorization: Bearer ``` -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. +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. + +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. -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. +The following diagram shows how a JWT is obtained and used to access APIs or resources: -The following diagram shows this process: +![How does a JSON Web Token works](https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png) -![How does a JSON Web Token works](https://cdn.auth0.com/content/jwt/jwt-diagram.png) +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). +2. When the authorization is granted, the authorization server returns an access token to the application. +3. The application uses the access token to access a protected resource (like an API). 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. From aba64871060a331e1733cc747e83e586d35a28a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20E=2E=20Peyrott?= Date: Thu, 14 Jun 2018 14:00:06 -0300 Subject: [PATCH 3/3] Typo --- views/website/md/introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/website/md/introduction.md b/views/website/md/introduction.md index d07d67bb..ec180855 100755 --- a/views/website/md/introduction.md +++ b/views/website/md/introduction.md @@ -107,7 +107,7 @@ If the token is sent in the `Authorization` header, Cross-Origin Resource Sharin The following diagram shows how a JWT is obtained and used to access APIs or resources: -![How does a JSON Web Token works](https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png) +![How does a JSON Web Token work](https://cdn2.auth0.com/docs/media/articles/api-auth/client-credentials-grant.png) 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). 2. When the authorization is granted, the authorization server returns an access token to the application.