jw_tea 0.1.1 → 0.1.2

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: be5fc8ea9071f34c14ab250ccb7613933383b0df3e13b95c80676fb7e596e5e6
4
- data.tar.gz: 3fc7d7b8e8d961cd761e7bf859b5712e581c7df2788d9ea8836eb231e5fa7015
3
+ metadata.gz: 65c24051c28c8b21cc4d3074e135ae86097723ad7915e4811503db9bd46d4fe9
4
+ data.tar.gz: 7edf553c6ab0cf1424021559c81fc32ae9159d96e8a0ad3cdd0e02c4d314c60e
5
5
  SHA512:
6
- metadata.gz: 796012ecd7468fd498bffb07085e93847c9514ef1b92a476074f141381829e37e84a0f8c689f925af4dbcd556479f7833f3e9d08b1e47bb3e8e5648cd5a70ca0
7
- data.tar.gz: 2121342e948b5b6785b9fdbe7cf1e85e5b921f0db7005452bc8ea12a13c04c6b42d20782f87b79386c3821c2595487f478ac7c5bb136ae63fb4011a3a1cd89e7
6
+ metadata.gz: be97e0e3f6c90bf2e59f08aa5e18d02f5189e384e8458fda6216b910f8daa154acc9ac58f86f20ef59925aa0bd24567656694d17a880be5f4969c036091e23f2
7
+ data.tar.gz: 45bc055563ccc5c8d733515113e51a004a32c0cb76623928851972ca1db2516f02b43d807faa97d8f691cf04f1058ce75f02d99cdd1e402480d78627f1452d31
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jw_tea (0.1.1)
4
+ jw_tea (0.1.2)
5
5
  activesupport
6
6
  jwt
7
7
  redis
data/lib/jw_tea/kettle.rb CHANGED
@@ -13,12 +13,11 @@ module JWTea
13
13
  @expires_in = (expires_in || ::JWTea.configuration.default_expires_in).to_i
14
14
  end
15
15
 
16
- def brew(data, key: nil)
16
+ def brew(data)
17
17
  exp = @expires_in.seconds.from_now.to_i
18
- ::JWTea::Token.build(data, exp, @secret, @algorithm).tap do |token|
19
- key ||= token.key
20
- @store.save(key, token.jti, @expires_in)
21
- end
18
+ token = ::JWTea::Token.build(data, exp, @secret, @algorithm)
19
+ @store.save(token.jti, token.exp, @expires_in)
20
+ token
22
21
  end
23
22
 
24
23
  def pour(encoded_token)
@@ -3,15 +3,15 @@
3
3
  module JWTea
4
4
  module Stores
5
5
  class NullStore
6
- def save(_key, _value, _ttl_in_seconds)
6
+ def save(_jti, _exp, _ttl_in_seconds)
7
7
  nil
8
8
  end
9
9
 
10
- def exists?(_key, _value)
10
+ def exists?(_jti, _exp)
11
11
  true
12
12
  end
13
13
 
14
- def delete(_key)
14
+ def delete(_jti)
15
15
  nil
16
16
  end
17
17
  end
@@ -5,24 +5,34 @@ module JWTea
5
5
  module Stores
6
6
  class RedisStore
7
7
  OK = 'OK'
8
+ TEMPLATE = 'jti:%<jti>s'
8
9
 
9
10
  def initialize(*redis_options)
10
11
  @redis = ::Redis.new(*redis_options)
11
12
  end
12
13
 
13
- def save(key, value, ttl_in_seconds)
14
- result = @redis.setex(key, ttl_in_seconds, value.to_s)
14
+ def save(jti, exp, ttl_in_seconds)
15
+ key = key(jti)
16
+ result = @redis.setex(key, ttl_in_seconds, exp.to_s)
15
17
  result == OK
16
18
  end
17
19
 
18
- def exists?(key, value)
19
- @redis.get(key) == value.to_s
20
+ def exists?(jti, exp)
21
+ key = key(jti)
22
+ @redis.get(key) == exp.to_s
20
23
  end
21
24
 
22
- def delete(key)
25
+ def delete(jti)
26
+ key = key(jti)
23
27
  result = @redis.del(key)
24
28
  result == 1
25
29
  end
30
+
31
+ private
32
+
33
+ def key(jti)
34
+ format(TEMPLATE, jti: jti)
35
+ end
26
36
  end
27
37
  end
28
38
  end
data/lib/jw_tea/token.rb CHANGED
@@ -29,9 +29,5 @@ module JWTea
29
29
  def inspect
30
30
  to_s
31
31
  end
32
-
33
- def key
34
- @key ||= Digest::MD5.hexdigest(@payload.to_s)
35
- end
36
32
  end
37
33
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require 'jwt'
3
- require 'forwardable'
4
3
 
5
4
  module JWTea
6
5
  class Token
@@ -13,9 +12,6 @@ module JWTea
13
12
  end
14
13
  end
15
14
 
16
- extend Forwardable
17
- def_delegators :to_h, :to_s
18
-
19
15
  def initialize(data:, exp:, iat: nil, jti: nil)
20
16
  @data = data
21
17
  @exp = exp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JWTea
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jw_tea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Loyola
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt