Skip to content

Commit c267eec

Browse files
committed
latest
1 parent fc68375 commit c267eec

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

introduction/index.html

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
44
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
55
})(window,document,'script','dataLayer','GTM-PT2SNS');</script><!-- End Google Tag Manager —>--><nav class="navbar closed"><div class="container"><div class="top-mobile"><div class="menu-trigger"><span></span></div><a href="/" class="brand"><img src="/img/pic_logo.svg" class="icon"><img src="/img/logo.svg" class="logo"></a></div><nav class="menu"><a href="/#debugger" class="scrollto">Debugger</a><a href="/#libraries" class="scrollto">Libraries</a><a href="/introduction" class="active">Introduction</a><a href="https://ask.auth0.com/category/jwt" target="_blank">Ask</a><a href="http://swag.auth0.com/" target="_blank">Get a T-shirt!</a></nav><div class="social"><a href="https://auth0.com/" target="_blank" class="a0"><img src="/img/ico_a0_white.svg"></a><a href="https://twitter.com/auth0" target="_blank" class="twitter"><img src="/img/ico_twitter.svg"></a></div><a href="https://auth0.com/" target="_blank" class="supported">Supported by<img src="/img/ico_logo.svg"></a></div></nav><section class="banner-jwt"><div class="container"><a href="/" class="logo"><img src="/img/pic_logo.svg"></a><h1>Introduction to JSON Web Tokens</h1></div></section><section class="video-content"><div class="container"><iframe src="//fast.wistia.net/embed/iframe/dxfz716cw9?videoFoam=true&amp;controlsVisibleOnLoad=false&amp;vmode=transparent&amp;preload=metadata&amp;playerColor=292929" allowtransparency="true" frameborder="0" scrolling="no" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen class="intro-video wistia_embed"></iframe></div></section><section class="plain-text"><div class="container"><h2 id="what-is-json-web-token-">What is JSON Web Token?</h2>
6-
<p>JSON Web Token (JWT) is an open standard (<a href="https://tools.ietf.org/html/rfc7519">RFC 7519</a>) 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 <strong>HMAC</strong> algorithm) or a public/private key pair using <strong>RSA</strong>.</p>
6+
<p>JSON Web Token (JWT) is an open standard (<a href="https://tools.ietf.org/html/rfc7519">RFC 7519</a>) 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 <strong>HMAC</strong> algorithm) or a public/private key pair using <strong>RSA</strong>.</p>
77
<p>Let&#39;s explain some concepts of this definition further.</p>
88
<ul>
9-
<li><p><strong>Compact</strong>: Because of its size, it can be sent through an URL, POST parameter, or inside an HTTP header. Additionally, due to its size its transmission is fast.</p>
9+
<li><p><strong>Compact</strong>: Because of its smaller size, JWTs can be sent through an URL, POST parameter, or inside an HTTP header. Additionally, the smaller size means transmission is fast.</p>
1010
</li>
11-
<li><p><strong>Self-contained</strong>: The payload contains all the required information about the user, to avoid querying the database more than once.</p>
11+
<li><p><strong>Self-contained</strong>: The payload contains all the required information about the user, avoiding the need to query the database more than once.</p>
1212
</li>
1313
</ul>
1414
<h2 id="when-should-you-use-json-web-tokens-">When should you use JSON Web Tokens?</h2>
15-
<p>There are some scenarios where JSON Web Tokens are useful:</p>
15+
<p>Here are some scenarios where JSON Web Tokens are useful:</p>
1616
<ul>
17-
<li><p><strong>Authentication</strong>: This is the typical 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 among systems of different domains.</p>
17+
<li><p><strong>Authentication</strong>: 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.</p>
1818
</li>
19-
<li><p><strong>Information Exchange</strong>: JSON Web Tokens are a good way of securely transmitting information between parties, because as they can be signed, for example using public/private key pairs, you can be sure that 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&#39;t changed.</p>
19+
<li><p><strong>Information Exchange</strong>: JSON Web Tokens are a good way of securely transmitting information between parties, because as they can be signed, for example using public/private key pairs, you can be sure that 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&#39;t been tampered with.</p>
2020
</li>
2121
</ul>
22-
<h2 id="which-is-the-json-web-token-structure-">Which is the JSON Web Token structure?</h2>
22+
<h2 id="what-is-the-json-web-token-structure-">What is the JSON Web Token structure?</h2>
2323
<p>JSON Web Tokens consist of three parts separated by dots (<code>.</code>), which are:</p>
2424
<ul>
2525
<li>Header</li>
@@ -30,7 +30,7 @@ <h2 id="which-is-the-json-web-token-structure-">Which is the JSON Web Token stru
3030
<p><code>xxxxx.yyyyy.zzzzz</code></p>
3131
<p>Let&#39;s break down the different parts.</p>
3232
<h3 id="header">Header</h3>
33-
<p>The header <em>typically</em> consists of two parts: the type of the token, which is JWT, and the hashing algorithm such as HMAC SHA256 or RSA.</p>
33+
<p>The header <em>typically</em> consists of two parts: the type of the token, which is JWT, and the hashing algorithm being used, such as HMAC SHA256 or RSA.</p>
3434
<p>For example:</p>
3535
<pre><code>{
3636
&quot;alg&quot;: &quot;HS256&quot;,
@@ -41,7 +41,7 @@ <h3 id="payload">Payload</h3>
4141
<p>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.
4242
There are three types of claims: <em>reserved</em>, <em>public</em>, and <em>private</em> claims.</p>
4343
<ul>
44-
<li><p><strong>Reserved claims</strong>: These are a set of predefined claims, which are not mandatory but recommended, thought to provide a set of useful, interoperable claims. Some of them are: <strong>iss</strong> (issuer), <strong>exp</strong> (expiration time), <strong>sub</strong> (subject), <strong>aud</strong> (audience), among others.</p>
44+
<li><p><strong>Reserved claims</strong>: These is a set of predefined claims which are not mandatory but recommended, to provide a set of useful, interoperable claims. Some of them are: <strong>iss</strong> (issuer), <strong>exp</strong> (expiration time), <strong>sub</strong> (subject), <strong>aud</strong> (audience), and others.</p>
4545
<blockquote>
4646
<p>Notice that the claim names are only three characters long as JWT is meant to be compact.</p>
4747
</blockquote>
@@ -60,36 +60,36 @@ <h3 id="payload">Payload</h3>
6060
</code></pre><p>The payload is then <strong>Base64Url</strong> encoded to form the second part of the JSON Web Token.</p>
6161
<h3 id="signature">Signature</h3>
6262
<p>To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.</p>
63-
<p>For example if you want to use the HMAC SHA256 algorithm, the signature will be created in the following way.</p>
63+
<p>For example if you want to use the HMAC SHA256 algorithm, the signature will be created in the following way:</p>
6464
<pre><code>HMACSHA256(
6565
base64UrlEncode(header) + &quot;.&quot; +
6666
base64UrlEncode(payload),
6767
secret)
68-
</code></pre><p>The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message was&#39;t changed in the way.</p>
68+
</code></pre><p>The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn&#39;t changed along the way.</p>
6969
<h3 id="putting-all-together">Putting all together</h3>
70-
<p>The output is three Base64 strings separated by dots that can be easily passed in HTML and HTTP environments, while being more compact compared to XML-based standards such as SAML.</p>
70+
<p>The output is three Base64 strings separated by dots that can be easily passed in HTML and HTTP environments, while being more compact when compared to XML-based standards such as SAML.</p>
7171
<p>The following shows a JWT that has the previous header and payload encoded, and it is signed with a secret.
7272
<img src="https://cdn.auth0.com/content/jwt/encoded-jwt3.png" alt="Encoded JWT"></p>
73-
<p>If you want to play with JWT and put these concepts to practice, you can use <a href="http://jwt.io">jwt.io Debugger</a> to decode, verify and generate JWTs.</p>
73+
<p>If you want to play with JWT and put these concepts into practice, you can use <a href="http://jwt.io">jwt.io Debugger</a> to decode, verify, and generate JWTs.</p>
7474
<p><img src="https://cdn.auth0.com/blog/legacy-app-auth/legacy-app-auth-5.png" alt="JWT.IO Debugger"></p>
7575
<h2 id="how-do-json-web-tokens-work-">How do JSON Web Tokens work?</h2>
7676
<p>In authentication, when the user successfully logs in using his 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.</p>
77-
<p>Whenever the user wants to access a protected route or resource, it should send the JWT, typically in the <strong>Authorization</strong> header using the <strong>Bearer</strong> schema. Therefore the content of the header should look like the following.</p>
77+
<p>Whenever the user wants to access a protected route or resource, the user agent should send the JWT, typically in the <strong>Authorization</strong> header using the <strong>Bearer</strong> schema. The content of the header should look like the following:</p>
7878
<pre><code>Authorization: Bearer &lt;token&gt;
79-
</code></pre><p>This is a stateless authentication mechanism as the user state is never saved in the server memory.
80-
The server&#39;s protected routes will check for a valid JWT in the Authorization header, and if there is, the user will be allowed. As JWTs are self-contained, all the necessary information is there, reducing the need of going back and forward to the database.</p>
81-
<p>This allows to fully rely on data APIs that are stateless and even make requests to downstream services. It doesn&#39;t matter which domains are serving your APIs, as Cross-Origin Resource Sharing (CORS) won&#39;t be an issue as it doesn&#39;t use cookies.</p>
79+
</code></pre><p>This is a stateless authentication mechanism as the user state is never saved in server memory.
80+
The server&#39;s protected routes will check for a valid JWT in the Authorization header, and if it&#39;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.</p>
81+
<p>This allows you to fully rely on data APIs that are stateless and even make requests to downstream services. It doesn&#39;t matter which domains are serving your APIs, so Cross-Origin Resource Sharing (CORS) won&#39;t be an issue as it doesn&#39;t use cookies.</p>
8282
<p>The following diagram shows this process:</p>
8383
<p><img src="https://cdn.auth0.com/content/jwt/jwt-diagram.png" alt="How does a JSON Web Token works"></p>
8484
<h2 id="why-should-we-use-json-web-tokens-">Why should we use JSON Web Tokens?</h2>
85-
<p>Let&#39;s talk about the benefits of <strong>JSON Web Tokens (JWT)</strong> comparing it to <strong>Simple Web Tokens (SWT)</strong> and <strong>Security Assertion Markup Language Tokens (SAML)</strong>.</p>
86-
<p>As JSON is less verbose than XML, when it is encoded its size is also smaller; making JWT more compact than SAML. This makes JWT a good choice to be passed in HTML and HTTP environments.</p>
87-
<p>Security-wise, SWT can only be symmetric signed by a shared secret using the HMAC algorithm. While JWT and SAML tokens can also use a public/private key pair in the form of a X.509 certificate to sign them. However, signing XML with XML Digital Signature without introducing obscure security holes is very difficult compared to the simplicity of signing JSON.</p>
88-
<p>JSON parsers are common in most programming languages, because they map directly to objects, conversely XML doesn&#39;t have a natural document-to-object mapping. This makes it easier to work with JWT than SAML assertions.</p>
89-
<p>Regarding usage, JWT is used at an Internet scale. This highlights the ease of client side processing of the JSON Web token on multiple platforms, especially, mobile.</p>
85+
<p>Let&#39;s talk about the benefits of <strong>JSON Web Tokens (JWT)</strong> when compared to <strong>Simple Web Tokens (SWT)</strong> and <strong>Security Assertion Markup Language Tokens (SAML)</strong>.</p>
86+
<p>As JSON is less verbose than XML, when it is encoded its size is also smaller, making JWT more compact than SAML. This makes JWT a good choice to be passed in HTML and HTTP environments.</p>
87+
<p>Security-wise, SWT can only be symmetricly signed by a shared secret using the HMAC algorithm. However, JWT and SAML tokens can use a public/private key pair in the form of a X.509 certificate for signing. Signing XML with XML Digital Signature without introducing obscure security holes is very difficult when compared to the simplicity of signing JSON.</p>
88+
<p>JSON parsers are common in most programming languages because they map directly to objects. Conversely, XML doesn&#39;t have a natural document-to-object mapping. This makes it easier to work with JWT than SAML assertions.</p>
89+
<p>Regarding usage, JWT is used at Internet scale. This highlights the ease of client-side processing of the JSON Web token on multiple platforms, especially mobile.</p>
9090
<p><img src="https://cdn.auth0.com/content/jwt/comparing-jwt-vs-saml2.png" alt="Comparing the length of an encoded JWT and an encoded SAML">
9191
<em>Comparison of the length of an encoded JWT and an encoded SAML</em></p>
92-
<p>If you want to read more about JSON Web Tokens and even start using them to perform authentication in your own applications, browse to the <a href="http://auth0.com/learn/json-web-tokens">JSON Web Token landing page</a> in Auth0.</p>
92+
<p>If you want to read more about JSON Web Tokens and even start using them to perform authentication in your own applications, browse to the <a href="http://auth0.com/learn/json-web-tokens">JSON Web Token landing page</a> at Auth0.</p>
9393
</div></section><section class="go-tool"><div class="container"><p>Get started with JWT today</p><a href="/#debugger" class="btn btn-success">Start using the tool</a></div></section><div class="tokens-created"><div class="container"><img src="/img/pic_logo_ft.svg"><p>JWT.io is brought to you by Auth0.</p><p>A cloud service, APIs and tools that eliminate the friction of identity for your applications and APIs.</p><a href="https://auth0.com/signup" target="_blank" class="btn btn-success">Create free account</a><div class="token"><h5>TOKENS CREATED</h5></div><div class="counter"></div></div></div><footer><div class="container"><div class="columns"><div class="column"><a href="https://auth0.com/" target="_blank">Supported by<img src="/img/ico_logo.svg"></a></div><div class="column pull-request"><span>Missing something?</span><a href="https://github.com/jsonwebtoken/jsonwebtoken.github.io/tree/master/views" target="_blank">Send a Pull Request</a></div><div class="column social-counter"><a href="https://twitter.com/auth0" data-show-count="true" class="twitter-follow-button">Follow @auth0</a></div></div></div></footer><!--Bootstrap core JavaScript
9494
==================================================--><!-- Placed at the end of the document so the pages load faster--><script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script src="/js/bootstrap.min.js"></script><script src="//fast.wistia.net/assets/external/E-v1.js" async></script><!-- build:js dist/js/app.js--><script src="/vendor/zepto/zepto.js"></script><script src="/vendor/jsonlint/lib/jsonlint.js"></script><script src="/vendor/json-sans-eval-min/index.js"></script><script src="/vendor/codemirror/lib/codemirror.js"></script><script src="/vendor/codemirror/mode/javascript/javascript.js"></script><script src="/vendor/codemirror/addon/lint/lint.js"></script><script src="/vendor/codemirror/addon/lint/javascript-lint.js"></script><script src="/vendor/codemirror/addon/lint/json-lint.js"></script><script src="/vendor/jsrsasign/index.js"></script><script src="/vendor/jws.js/index.js"></script><script src="/js/jwt_mode.js"></script><script src="/js/jwt.js"></script><script src="/js/isotope.pkgd.min.js"></script><script src="/js/flipclock.js"></script><script src="/js/accordion.js"></script><script src="/js/highlight.min.js"></script><script src="/js/app.js"></script><!-- endbuild--><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
9595
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

0 commit comments

Comments
 (0)