<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: My Botsy</title>
    <description>The latest articles on DEV Community by My Botsy (@mybotsy).</description>
    <link>https://dev.to/mybotsy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4220879%2Fad6e1b3f-eef2-4b21-8a23-15451f0b5bf1.png</url>
      <title>DEV Community: My Botsy</title>
      <link>https://dev.to/mybotsy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mybotsy"/>
    <language>en</language>
    <item>
      <title>How to Check If a JWT Is Expired (the exp Claim Explained)</title>
      <dc:creator>My Botsy</dc:creator>
      <pubDate>Sun, 01 Nov 2026 16:19:50 +0000</pubDate>
      <link>https://dev.to/mybotsy/how-to-check-if-a-jwt-is-expired-the-exp-claim-explained-5fe0</link>
      <guid>https://dev.to/mybotsy/how-to-check-if-a-jwt-is-expired-the-exp-claim-explained-5fe0</guid>
      <description>&lt;p&gt;A JWT is expired when the current time is equal to or later than its &lt;code&gt;exp&lt;/code&gt; claim. &lt;code&gt;exp&lt;/code&gt; is a plain number of &lt;strong&gt;seconds&lt;/strong&gt; since 1 January 1970 UTC, so &lt;code&gt;1793372400&lt;/code&gt; means October 30, 2026 at 15:00:00 UTC. To check a token, decode its middle part, read &lt;code&gt;exp&lt;/code&gt;, and compare it with the clock.&lt;/p&gt;

&lt;p&gt;That sounds trivial, but most "why is my token rejected?" bugs I've seen come from a handful of traps around that one number. Here's what the spec says, and the pitfalls, tested against PyJWT 2.15.1, jsonwebtoken 9.0.3 and jose 6.2.14.&lt;/p&gt;

&lt;h2&gt;
  
  
  What RFC 7519 says
&lt;/h2&gt;

&lt;p&gt;There are three time claims, all optional, all NumericDate values (seconds, not milliseconds):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;exp&lt;/strong&gt;: the token "MUST NOT be accepted for processing" on or after this moment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nbf&lt;/strong&gt; (not before): must not be accepted before this moment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iat&lt;/strong&gt; (issued at): when it was created. It invalidates nothing by itself, but &lt;code&gt;exp - iat&lt;/code&gt; tells you the token's lifetime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The RFC also allows "some small leeway, usually no more than a few minutes, to account for clock skew". That's why two services can disagree about a token that expired a few seconds ago.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 1: exp in milliseconds
&lt;/h2&gt;

&lt;p&gt;Writing &lt;code&gt;Date.now()&lt;/code&gt; straight into &lt;code&gt;exp&lt;/code&gt; is the classic bug. A token with &lt;code&gt;"exp":1793462400000&lt;/code&gt; was &lt;strong&gt;accepted&lt;/strong&gt; by both jsonwebtoken and jose, so in practice it never expires. PyJWT rejected it, but only because of its &lt;code&gt;iat&lt;/code&gt; check, not &lt;code&gt;exp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Fix: divide by 1000 when you issue the token, and multiply by 1000 when you build a JavaScript &lt;code&gt;Date&lt;/code&gt; from &lt;code&gt;exp&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 2: exp as a string
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;"exp":"1798761600"&lt;/code&gt; (with quotes) breaks the standard. jsonwebtoken rejects it with &lt;code&gt;invalid exp value&lt;/code&gt;, jose with &lt;code&gt;"exp" claim must be a number&lt;/code&gt;, and PyJWT accepts and still enforces it. Same token: passes in one service, fails in another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 3: clock skew and leeway
&lt;/h2&gt;

&lt;p&gt;A token that expired 20 seconds earlier was rejected by all three libraries with no tolerance, and accepted by all three with 30 seconds (&lt;code&gt;leeway=30&lt;/code&gt; in PyJWT, &lt;code&gt;clockTolerance: 30&lt;/code&gt; in jsonwebtoken and jose). Keep it small: every second you allow extends the life of every token, including stolen ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 4: &lt;code&gt;base64 --decode&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;JWTs use base64url (&lt;code&gt;-&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt; instead of &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;, no padding). The popular one-liner &lt;code&gt;cut -d. -f2 | base64 --decode | jq .exp&lt;/code&gt; works until a payload contains one of those characters or needs padding, then it fails or prints garbage. Use a base64url-aware decoder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 5: decoding is not verifying
&lt;/h2&gt;

&lt;p&gt;Reading &lt;code&gt;exp&lt;/code&gt; tells you when a token &lt;em&gt;claims&lt;/em&gt; to expire. It says nothing about whether the signature is valid. Never trust a decoded payload for an authorization decision without verifying it with the key.&lt;/p&gt;

&lt;h2&gt;
  
  
  No exp at all
&lt;/h2&gt;

&lt;p&gt;A payload like &lt;code&gt;{"sub":"svc-reporting","iat":1790856000}&lt;/code&gt; was accepted by all three libraries. A leaked token like that works until the key is rotated. In PyJWT, &lt;code&gt;options={"require": ["exp"]}&lt;/code&gt; turns it into &lt;code&gt;MissingRequiredClaimError&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking expiry in code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Node, jsonwebtoken&lt;/span&gt;
&lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;clockTolerance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// throws TokenExpiredError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Python, PyJWT
&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;algorithms&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HS256&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;leeway&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;require&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick manual check without verifying (debugging only):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;atob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/-/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/_/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exp&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exp&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;expired&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;valid&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  If you just want to eyeball a token
&lt;/h2&gt;

&lt;p&gt;I help run a small free tools site, and we built a &lt;a href="https://mybotsy.com/jwt-decoder" rel="noopener noreferrer"&gt;browser-only JWT decoder&lt;/a&gt; that shows the exp/nbf/iat dates in your time zone and in UTC, flags millisecond and string values, and never sends the token anywhere. Even so, treat production tokens like passwords: paste test tokens, or tokens that are already expired.&lt;/p&gt;

&lt;p&gt;The full write-up, with worked examples of real decoder output, is &lt;a href="https://mybotsy.com/blog/how-to-check-if-a-jwt-is-expired" rel="noopener noreferrer"&gt;on our blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>jwt</category>
      <category>security</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
