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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/jw_tea/kettle.rb +4 -5
- data/lib/jw_tea/stores/null_store.rb +3 -3
- data/lib/jw_tea/stores/redis_store.rb +15 -5
- data/lib/jw_tea/token.rb +0 -4
- data/lib/jw_tea/token/payload.rb +0 -4
- data/lib/jw_tea/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65c24051c28c8b21cc4d3074e135ae86097723ad7915e4811503db9bd46d4fe9
|
4
|
+
data.tar.gz: 7edf553c6ab0cf1424021559c81fc32ae9159d96e8a0ad3cdd0e02c4d314c60e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be97e0e3f6c90bf2e59f08aa5e18d02f5189e384e8458fda6216b910f8daa154acc9ac58f86f20ef59925aa0bd24567656694d17a880be5f4969c036091e23f2
|
7
|
+
data.tar.gz: 45bc055563ccc5c8d733515113e51a004a32c0cb76623928851972ca1db2516f02b43d807faa97d8f691cf04f1058ce75f02d99cdd1e402480d78627f1452d31
|
data/Gemfile.lock
CHANGED
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
|
16
|
+
def brew(data)
|
17
17
|
exp = @expires_in.seconds.from_now.to_i
|
18
|
-
::JWTea::Token.build(data, exp, @secret, @algorithm)
|
19
|
-
|
20
|
-
|
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(
|
6
|
+
def save(_jti, _exp, _ttl_in_seconds)
|
7
7
|
nil
|
8
8
|
end
|
9
9
|
|
10
|
-
def exists?(
|
10
|
+
def exists?(_jti, _exp)
|
11
11
|
true
|
12
12
|
end
|
13
13
|
|
14
|
-
def delete(
|
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(
|
14
|
-
|
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?(
|
19
|
-
|
20
|
+
def exists?(jti, exp)
|
21
|
+
key = key(jti)
|
22
|
+
@redis.get(key) == exp.to_s
|
20
23
|
end
|
21
24
|
|
22
|
-
def delete(
|
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
data/lib/jw_tea/token/payload.rb
CHANGED
@@ -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
|
data/lib/jw_tea/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|