jot-helpers 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc26447c9872c1d17b36833b09579b6e77d3d4bfa93d5c0b9ae8363b9b09fba6
4
- data.tar.gz: 6e1302e38689ce87a205ffbcc9baefe45b9d158c31974d0b6bf63850dc0e73a6
3
+ metadata.gz: a587295210595b3561634de5170dc2dc7ce37a47ea1ce61db7ebcede1a7dbad9
4
+ data.tar.gz: fc9c02f97af24c90ae7150d5f7f1ad945f79a85416220e30d8ec0bb86577529f
5
5
  SHA512:
6
- metadata.gz: 41c4c490d189fbad84250dca4174059e4476d4ae32df8a729086ef46a13875f51fe75ca3e72e002b518d48dfe95bd0ae015b6c974810de9c67e116361e9cceb9
7
- data.tar.gz: b2b8fd2207ec30782a69f754430de4afa22b291e0c62ccfb86e87d93353f61d3dfcb6f9c47a22c24e9c03c3f9b51d3c85781cfe98e634d1abba92d16416e8621
6
+ metadata.gz: ca5d28c55edc69017aafddb218b5ccea2287b17a37a7739c07db15f60c98e70fa101a58e71df34168baebaf222d81228a4df8f6a6f79617441b2fd0c4e68c719
7
+ data.tar.gz: 2acc4fd85f00662e3cf14c6198ec968d1cfd877d4a16b395edd0d75c6c16e6bbc3f3c66866b7f664ce0ff90d753d4b244a20acec06b13f0ea189d4d4d9b416f9
data/README.md CHANGED
@@ -13,6 +13,12 @@ Jot.configure do |config|
13
13
  end
14
14
  ```
15
15
 
16
+ You may wish to also specify the expiration time for tokens as well. The default is 1 hour, but it can be overridden:
17
+
18
+ ```ruby
19
+ config.expiration_time_in_seconds = 1500 # 25 minutes
20
+ ```
21
+
16
22
  ## Usage
17
23
 
18
24
  Encode a payload:
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -1,7 +1,10 @@
1
1
  class Jot
2
2
  class Configuration
3
- attr_accessor :algorithm, :secret
4
-
3
+ attr_accessor :algorithm, :secret, :expiration_time_in_seconds
5
4
 
5
+ # Defaults to 1 hour
6
+ def expiration_time_in_seconds
7
+ @expiration_time_in_seconds || 3600
8
+ end
6
9
  end
7
10
  end
data/lib/jot/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Jot
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/jot.rb CHANGED
@@ -16,7 +16,8 @@ class Jot
16
16
  end
17
17
 
18
18
  def self.encode(payload)
19
- JWT.encode(payload, config.secret, config.algorithm)
19
+ exp = payload[:exp] || Time.now + config.expiration_time_in_seconds
20
+ JWT.encode(payload.merge(exp: exp.to_i), config.secret, config.algorithm)
20
21
  end
21
22
 
22
23
  def self.decode(payload, verify: true)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jot-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: timecop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Provides helper methods for working with JSON Web Tokens (JWTs)
42
56
  email:
43
57
  - me@ryanbigg.com