philiprehberger-jwt_kit 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cd6d9f8d91d59046e8427bb209a93e9220a3ff0398ef1c84758a9396fae2eb7
4
- data.tar.gz: 9fc834f733af1020130928f51ee99ff24d94f468c64ab86a638d7859dbba658e
3
+ metadata.gz: '09b9eb684b43c1e022244bc53c710d7ac590f454dde228d2bc2cf7ba6217810e'
4
+ data.tar.gz: 78e35b5e7712bde020b168ea4ba9077b2fc12c0735a967042339aab148b24254
5
5
  SHA512:
6
- metadata.gz: 2751b52e541a834214dee62b4eaa136798d7f244900c206e063738dae3fd2ae90a2c350916ca82dcf714558028eeecb96ea4ac269a02ede7d6bb7c7c5116b7f2
7
- data.tar.gz: 44de4708a12b6bf7b0317a98db9a05d3375a5083791cd126458b9f63f716942a054a4de5327a6a13c918fe1421936a72f5e19451c402f9dbb75070d234169b47
6
+ metadata.gz: 41bbac9795276d4770337b6b71d660a53fc7ddee64460acb262fa302c40845e798af3db2889ada71ff1149e957283671d2fabf1ef98fcc1ceb98cf1b9ba8f2bd
7
+ data.tar.gz: 3d74d20e81228260558cb80a2cb69b2986f9c276798a1cec102fbe41abc41311b123e204683354b2bbf8810d917fb79dfce24ab2c3d90cc88f4743180f8d85f3
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-05-31
11
+
12
+ ### Added
13
+ - `JwtKit.time_to_expiry(token)` returns the seconds remaining until the token's `exp` claim. Negative for already-expired tokens; `nil` for malformed tokens or tokens without a numeric `exp`. Pairs with `expired?` for pre-emptive refresh scheduling.
14
+ - README now includes the standard package card image after the badges.
15
+
10
16
  ## [0.5.0] - 2026-04-26
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/philiprehberger-jwt_kit.svg)](https://rubygems.org/gems/philiprehberger-jwt_kit)
5
5
  [![Last updated](https://img.shields.io/github/last-commit/philiprehberger/rb-jwt-kit)](https://github.com/philiprehberger/rb-jwt-kit/commits/main)
6
6
 
7
+ ![philiprehberger-jwt_kit](https://raw.githubusercontent.com/philiprehberger/rb-jwt-kit/main/package-card.webp)
8
+
7
9
  Opinionated JWT toolkit for Ruby — secure by default, with support for encoding, validation, refresh tokens, revocation, and key rotation
8
10
 
9
11
  ## Requirements
@@ -117,6 +119,16 @@ Philiprehberger::JwtKit.expired?(token) # => false
117
119
  # Use to decide whether to refresh before the authoritative decode
118
120
  ```
119
121
 
122
+ ### Time to Expiry
123
+
124
+ Get the seconds remaining until the token's `exp` claim. Negative when expired, `nil` when the token is malformed or has no numeric `exp`. Useful for scheduling pre-emptive refreshes rather than reacting after the fact:
125
+
126
+ ```ruby
127
+ Philiprehberger::JwtKit.time_to_expiry(token) # => 3599
128
+ # refresh when fewer than 60 seconds remain
129
+ Philiprehberger::JwtKit.refresh(refresh_token) if Philiprehberger::JwtKit.time_to_expiry(token).to_i < 60
130
+ ```
131
+
120
132
  ### Audience Validation
121
133
 
122
134
  ```ruby
@@ -224,6 +236,7 @@ Callbacks fire only after a successful operation. Exceptions raised inside a cal
224
236
  | `JwtKit.revoked?(token)` | Checks if a token has been revoked |
225
237
  | `JwtKit.peek(token)` | Decode header and payload without signature verification |
226
238
  | `JwtKit.expired?(token)` | Check `exp` claim without verifying the signature |
239
+ | `JwtKit.time_to_expiry(token)` | Seconds remaining until `exp`; negative when expired, nil when unknown |
227
240
  | `JwtKit.revocation_store=` | Set a custom revocation store |
228
241
  | `MemoryStore#cleanup!(max_age:)` | Remove revocation entries older than max_age seconds |
229
242
  | `Configuration#on_encode { \|token, payload\| ... }` | Register a callback fired after a successful encode |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module JwtKit
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -73,6 +73,23 @@ module Philiprehberger
73
73
  true
74
74
  end
75
75
 
76
+ # Seconds remaining until a token's `exp` claim. Does not verify the
77
+ # signature. Returns a negative integer for already-expired tokens and
78
+ # `nil` for malformed tokens or tokens without a numeric `exp` claim.
79
+ # Useful for scheduling a refresh before expiration rather than after.
80
+ #
81
+ # @param token [String] JWT token
82
+ # @return [Integer, nil] seconds remaining, or nil when undeterminable
83
+ def time_to_expiry(token)
84
+ payload = peek(token)[:payload]
85
+ exp = payload['exp']
86
+ return nil unless exp.is_a?(Numeric)
87
+
88
+ exp.to_i - Time.now.to_i
89
+ rescue DecodeError
90
+ nil
91
+ end
92
+
76
93
  # Encodes a payload into a signed JWT token.
77
94
  #
78
95
  # @param payload [Hash] custom claims
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-jwt_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-27 00:00:00.000000000 Z
11
+ date: 2026-06-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A complete JWT toolkit for Ruby. Encode and decode tokens with automatic
14
14
  claim management (exp, iat, iss, jti), generate access/refresh token pairs, validate