has_jwt_token 0.2.1 → 0.3.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: 445d49f22461e8ad189d361639f786cea6723f1e7126a8510e0089879e6c9272
4
- data.tar.gz: '03580907964370e9611b4aff79526bf2f0ef2aa59e4c8728d8770d3e4448af45'
3
+ metadata.gz: 5f65ddcc420900fb05201c00e4746e04716fe0e68c56fdab6be0e0a1d3dba793
4
+ data.tar.gz: 863fd49dd42eb153bcb01b620b23c5d4296fe52f9b32c0ccd4d321259eb83025
5
5
  SHA512:
6
- metadata.gz: a6d5ab98751e620b5f0f46b4283e127a9e7151e4d615d60bb194186d28cf24a36c426fe0612df17d7d40eee26f30e0a53904034694003d5184a83a669e5d67d7
7
- data.tar.gz: d2d841bdb59c585d0bd52aa90b94b6d69d64ac309a1753431c954172b0996455290cef3411d2811ea59216a3184cea9de736d5eb92ad95fdec109b2696428b0d
6
+ metadata.gz: 736405aa694b3df816877239461d0c52f100518384a609013a6af183bfa23d2ad54c44d445049cc5a9cecac169697f90c85311abcd22c588a5aa514556409974
7
+ data.tar.gz: 55fe4be0b427574b5d54913684a71bb2452c1d8f071ad0a93f6841d69b0c60ec6f68a8b1a8977804fa809a1a63ff66bfbeaf5fcb0b7b61a649e840e3096dbc6f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 3.1.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- has_jwt_token (0.2.1)
4
+ has_jwt_token (0.3.0)
5
5
  bcrypt
6
6
  jwt
7
7
  rails (>= 5.0, < 7.0)
@@ -9,182 +9,184 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (6.0.3.4)
13
- actionpack (= 6.0.3.4)
12
+ actioncable (6.1.6)
13
+ actionpack (= 6.1.6)
14
+ activesupport (= 6.1.6)
14
15
  nio4r (~> 2.0)
15
16
  websocket-driver (>= 0.6.1)
16
- actionmailbox (6.0.3.4)
17
- actionpack (= 6.0.3.4)
18
- activejob (= 6.0.3.4)
19
- activerecord (= 6.0.3.4)
20
- activestorage (= 6.0.3.4)
21
- activesupport (= 6.0.3.4)
17
+ actionmailbox (6.1.6)
18
+ actionpack (= 6.1.6)
19
+ activejob (= 6.1.6)
20
+ activerecord (= 6.1.6)
21
+ activestorage (= 6.1.6)
22
+ activesupport (= 6.1.6)
22
23
  mail (>= 2.7.1)
23
- actionmailer (6.0.3.4)
24
- actionpack (= 6.0.3.4)
25
- actionview (= 6.0.3.4)
26
- activejob (= 6.0.3.4)
24
+ actionmailer (6.1.6)
25
+ actionpack (= 6.1.6)
26
+ actionview (= 6.1.6)
27
+ activejob (= 6.1.6)
28
+ activesupport (= 6.1.6)
27
29
  mail (~> 2.5, >= 2.5.4)
28
30
  rails-dom-testing (~> 2.0)
29
- actionpack (6.0.3.4)
30
- actionview (= 6.0.3.4)
31
- activesupport (= 6.0.3.4)
32
- rack (~> 2.0, >= 2.0.8)
31
+ actionpack (6.1.6)
32
+ actionview (= 6.1.6)
33
+ activesupport (= 6.1.6)
34
+ rack (~> 2.0, >= 2.0.9)
33
35
  rack-test (>= 0.6.3)
34
36
  rails-dom-testing (~> 2.0)
35
37
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.0.3.4)
37
- actionpack (= 6.0.3.4)
38
- activerecord (= 6.0.3.4)
39
- activestorage (= 6.0.3.4)
40
- activesupport (= 6.0.3.4)
38
+ actiontext (6.1.6)
39
+ actionpack (= 6.1.6)
40
+ activerecord (= 6.1.6)
41
+ activestorage (= 6.1.6)
42
+ activesupport (= 6.1.6)
41
43
  nokogiri (>= 1.8.5)
42
- actionview (6.0.3.4)
43
- activesupport (= 6.0.3.4)
44
+ actionview (6.1.6)
45
+ activesupport (= 6.1.6)
44
46
  builder (~> 3.1)
45
47
  erubi (~> 1.4)
46
48
  rails-dom-testing (~> 2.0)
47
49
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.0.3.4)
49
- activesupport (= 6.0.3.4)
50
+ activejob (6.1.6)
51
+ activesupport (= 6.1.6)
50
52
  globalid (>= 0.3.6)
51
- activemodel (6.0.3.4)
52
- activesupport (= 6.0.3.4)
53
- activerecord (6.0.3.4)
54
- activemodel (= 6.0.3.4)
55
- activesupport (= 6.0.3.4)
56
- activestorage (6.0.3.4)
57
- actionpack (= 6.0.3.4)
58
- activejob (= 6.0.3.4)
59
- activerecord (= 6.0.3.4)
60
- marcel (~> 0.3.1)
61
- activesupport (6.0.3.4)
53
+ activemodel (6.1.6)
54
+ activesupport (= 6.1.6)
55
+ activerecord (6.1.6)
56
+ activemodel (= 6.1.6)
57
+ activesupport (= 6.1.6)
58
+ activestorage (6.1.6)
59
+ actionpack (= 6.1.6)
60
+ activejob (= 6.1.6)
61
+ activerecord (= 6.1.6)
62
+ activesupport (= 6.1.6)
63
+ marcel (~> 1.0)
64
+ mini_mime (>= 1.1.0)
65
+ activesupport (6.1.6)
62
66
  concurrent-ruby (~> 1.0, >= 1.0.2)
63
- i18n (>= 0.7, < 2)
64
- minitest (~> 5.1)
65
- tzinfo (~> 1.1)
66
- zeitwerk (~> 2.2, >= 2.2.2)
67
- ast (2.4.1)
68
- bcrypt (3.1.16)
67
+ i18n (>= 1.6, < 2)
68
+ minitest (>= 5.1)
69
+ tzinfo (~> 2.0)
70
+ zeitwerk (~> 2.3)
71
+ ast (2.4.2)
72
+ bcrypt (3.1.17)
69
73
  builder (3.2.4)
70
74
  coderay (1.1.3)
71
- concurrent-ruby (1.1.7)
75
+ concurrent-ruby (1.1.10)
72
76
  crass (1.0.6)
73
- diff-lcs (1.4.4)
74
- docile (1.3.2)
75
- erubi (1.9.0)
76
- factory_bot (6.1.0)
77
+ diff-lcs (1.5.0)
78
+ docile (1.4.0)
79
+ erubi (1.10.0)
80
+ factory_bot (6.2.1)
77
81
  activesupport (>= 5.0.0)
78
- globalid (0.4.2)
79
- activesupport (>= 4.2.0)
80
- i18n (1.8.5)
82
+ globalid (1.0.0)
83
+ activesupport (>= 5.0)
84
+ i18n (1.10.0)
81
85
  concurrent-ruby (~> 1.0)
82
- jwt (2.2.2)
83
- loofah (2.7.0)
86
+ jwt (2.3.0)
87
+ loofah (2.18.0)
84
88
  crass (~> 1.0.2)
85
89
  nokogiri (>= 1.5.9)
86
90
  mail (2.7.1)
87
91
  mini_mime (>= 0.1.1)
88
- marcel (0.3.3)
89
- mimemagic (~> 0.3.2)
92
+ marcel (1.0.2)
90
93
  method_source (1.0.0)
91
- mimemagic (0.3.5)
92
- mini_mime (1.0.2)
93
- mini_portile2 (2.4.0)
94
- minitest (5.14.2)
95
- nio4r (2.5.4)
96
- nokogiri (1.10.10)
97
- mini_portile2 (~> 2.4.0)
98
- parallel (1.19.2)
99
- parser (2.7.2.0)
94
+ mini_mime (1.1.2)
95
+ minitest (5.15.0)
96
+ nio4r (2.5.8)
97
+ nokogiri (1.13.6-x86_64-linux)
98
+ racc (~> 1.4)
99
+ parallel (1.22.1)
100
+ parser (3.1.2.0)
100
101
  ast (~> 2.4.1)
101
- pry (0.13.1)
102
+ pry (0.14.1)
102
103
  coderay (~> 1.1)
103
104
  method_source (~> 1.0)
105
+ racc (1.6.0)
104
106
  rack (2.2.3)
105
107
  rack-test (1.1.0)
106
108
  rack (>= 1.0, < 3)
107
- rails (6.0.3.4)
108
- actioncable (= 6.0.3.4)
109
- actionmailbox (= 6.0.3.4)
110
- actionmailer (= 6.0.3.4)
111
- actionpack (= 6.0.3.4)
112
- actiontext (= 6.0.3.4)
113
- actionview (= 6.0.3.4)
114
- activejob (= 6.0.3.4)
115
- activemodel (= 6.0.3.4)
116
- activerecord (= 6.0.3.4)
117
- activestorage (= 6.0.3.4)
118
- activesupport (= 6.0.3.4)
119
- bundler (>= 1.3.0)
120
- railties (= 6.0.3.4)
109
+ rails (6.1.6)
110
+ actioncable (= 6.1.6)
111
+ actionmailbox (= 6.1.6)
112
+ actionmailer (= 6.1.6)
113
+ actionpack (= 6.1.6)
114
+ actiontext (= 6.1.6)
115
+ actionview (= 6.1.6)
116
+ activejob (= 6.1.6)
117
+ activemodel (= 6.1.6)
118
+ activerecord (= 6.1.6)
119
+ activestorage (= 6.1.6)
120
+ activesupport (= 6.1.6)
121
+ bundler (>= 1.15.0)
122
+ railties (= 6.1.6)
121
123
  sprockets-rails (>= 2.0.0)
122
124
  rails-dom-testing (2.0.3)
123
125
  activesupport (>= 4.2.0)
124
126
  nokogiri (>= 1.6)
125
- rails-html-sanitizer (1.3.0)
127
+ rails-html-sanitizer (1.4.2)
126
128
  loofah (~> 2.3)
127
- railties (6.0.3.4)
128
- actionpack (= 6.0.3.4)
129
- activesupport (= 6.0.3.4)
129
+ railties (6.1.6)
130
+ actionpack (= 6.1.6)
131
+ activesupport (= 6.1.6)
130
132
  method_source
131
- rake (>= 0.8.7)
132
- thor (>= 0.20.3, < 2.0)
133
- rainbow (3.0.0)
133
+ rake (>= 12.2)
134
+ thor (~> 1.0)
135
+ rainbow (3.1.1)
134
136
  rake (12.3.3)
135
- regexp_parser (1.8.2)
136
- rexml (3.2.4)
137
- rspec (3.9.0)
138
- rspec-core (~> 3.9.0)
139
- rspec-expectations (~> 3.9.0)
140
- rspec-mocks (~> 3.9.0)
141
- rspec-core (3.9.3)
142
- rspec-support (~> 3.9.3)
143
- rspec-expectations (3.9.3)
137
+ regexp_parser (2.4.0)
138
+ rexml (3.2.5)
139
+ rspec (3.11.0)
140
+ rspec-core (~> 3.11.0)
141
+ rspec-expectations (~> 3.11.0)
142
+ rspec-mocks (~> 3.11.0)
143
+ rspec-core (3.11.0)
144
+ rspec-support (~> 3.11.0)
145
+ rspec-expectations (3.11.0)
144
146
  diff-lcs (>= 1.2.0, < 2.0)
145
- rspec-support (~> 3.9.0)
146
- rspec-mocks (3.9.1)
147
+ rspec-support (~> 3.11.0)
148
+ rspec-mocks (3.11.1)
147
149
  diff-lcs (>= 1.2.0, < 2.0)
148
- rspec-support (~> 3.9.0)
149
- rspec-support (3.9.4)
150
- rubocop (0.93.1)
150
+ rspec-support (~> 3.11.0)
151
+ rspec-support (3.11.0)
152
+ rubocop (1.29.0)
151
153
  parallel (~> 1.10)
152
- parser (>= 2.7.1.5)
154
+ parser (>= 3.1.0.0)
153
155
  rainbow (>= 2.2.2, < 4.0)
154
- regexp_parser (>= 1.8)
155
- rexml
156
- rubocop-ast (>= 0.6.0)
156
+ regexp_parser (>= 1.8, < 3.0)
157
+ rexml (>= 3.2.5, < 4.0)
158
+ rubocop-ast (>= 1.17.0, < 2.0)
157
159
  ruby-progressbar (~> 1.7)
158
- unicode-display_width (>= 1.4.0, < 2.0)
159
- rubocop-ast (1.0.1)
160
- parser (>= 2.7.1.5)
161
- rubocop-performance (1.8.1)
162
- rubocop (>= 0.87.0)
160
+ unicode-display_width (>= 1.4.0, < 3.0)
161
+ rubocop-ast (1.17.0)
162
+ parser (>= 3.1.1.0)
163
+ rubocop-performance (1.13.3)
164
+ rubocop (>= 1.7.0, < 2.0)
163
165
  rubocop-ast (>= 0.4.0)
164
- rubocop-rspec (1.44.1)
165
- rubocop (~> 0.87)
166
- rubocop-ast (>= 0.7.1)
167
- ruby-progressbar (1.10.1)
168
- simplecov (0.19.0)
166
+ rubocop-rspec (2.10.0)
167
+ rubocop (~> 1.19)
168
+ ruby-progressbar (1.11.0)
169
+ simplecov (0.21.2)
169
170
  docile (~> 1.1)
170
171
  simplecov-html (~> 0.11)
172
+ simplecov_json_formatter (~> 0.1)
171
173
  simplecov-html (0.12.3)
172
- sprockets (4.0.2)
174
+ simplecov_json_formatter (0.1.4)
175
+ sprockets (4.0.3)
173
176
  concurrent-ruby (~> 1.0)
174
177
  rack (> 1, < 3)
175
- sprockets-rails (3.2.2)
176
- actionpack (>= 4.0)
177
- activesupport (>= 4.0)
178
+ sprockets-rails (3.4.2)
179
+ actionpack (>= 5.2)
180
+ activesupport (>= 5.2)
178
181
  sprockets (>= 3.0.0)
179
- thor (1.0.1)
180
- thread_safe (0.3.6)
181
- tzinfo (1.2.7)
182
- thread_safe (~> 0.1)
183
- unicode-display_width (1.7.0)
184
- websocket-driver (0.7.3)
182
+ thor (1.2.1)
183
+ tzinfo (2.0.4)
184
+ concurrent-ruby (~> 1.0)
185
+ unicode-display_width (2.1.0)
186
+ websocket-driver (0.7.5)
185
187
  websocket-extensions (>= 0.1.0)
186
188
  websocket-extensions (0.1.5)
187
- zeitwerk (2.4.0)
189
+ zeitwerk (2.5.4)
188
190
 
189
191
  PLATFORMS
190
192
  ruby
@@ -201,4 +203,4 @@ DEPENDENCIES
201
203
  simplecov
202
204
 
203
205
  BUNDLED WITH
204
- 2.1.4
206
+ 2.2.22
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  HasJwtToken provides JWT authetication for models which are kean to use `has_secure_password` in Rails app and wants to use it to grant jwt tokens.
4
4
 
5
- This gem is build on top of [Ruby's JWT](https://github.com/jwt/ruby-jwt) gem and it implements `JWT.encode` and `JWT.decode` methods.
5
+ This gem is build on top of [Ruby's JWT](https://github.com/jwt/ruby-jwt) gem and it implements `JWT.encode` and `JWT.decode` (with validation enabled) methods.
6
6
 
7
7
  ## Installation
8
8
 
@@ -53,7 +53,7 @@ end
53
53
  user = User.last
54
54
 
55
55
  user.authenicate(password) # => user with @token
56
- user.auhtenticate_with_jwt(token) # => user with @token
56
+ User.find_with_jwt(token) # => user with @token
57
57
  ```
58
58
 
59
59
  ## Roadmap
@@ -1,22 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Authenticatable
4
- def authenticate(password)
5
- super(password).tap do |authenticated|
6
- @token = authenticated && encode || nil
3
+ require 'has_jwt_token/jwt_proxy'
4
+
5
+ module HasJwtToken
6
+ module Authenticatable
7
+ module ClassMethods
8
+ def find_with_jwt(jwt_token)
9
+ payload = decode!(jwt_token)
10
+ find_by(authenticate_by => payload[authenticate_by])
11
+ &.tap { |model| model.token = model.encode }
12
+ rescue JWT::DecodeError
13
+ raise HasJwtToken::InvalidToken, 'Invalid token has been provided.'
14
+ end
15
+
16
+ private
17
+
18
+ def authenticate_by
19
+ @authenticate_by ||= begin
20
+ auth_by_attr = has_jwt_token.authenticate_by.to_s
21
+ return auth_by_attr if column_names.include?(auth_by_attr)
22
+
23
+ raise HasJwtToken::BadConfiguration, "#{auth_by_attr.inspect} must be one of model attributes."
24
+ end
25
+ end
26
+
27
+ def decode!(token)
28
+ HasJwtToken::JwtProxy.decode!(
29
+ token: token,
30
+ algorithm: has_jwt_token.algorithm,
31
+ secret: has_jwt_token.secret
32
+ )
33
+ end
7
34
  end
8
- end
9
35
 
10
- def authenticate_with_jwt(jwt_token)
11
- authenticated = decode!(jwt_token)
36
+ def self.included(base)
37
+ base.extend(ClassMethods)
38
+ end
39
+
40
+ def authenticate(password)
41
+ super(password).tap do |authenticated|
42
+ @token = authenticated && encode || nil
43
+ end
44
+ end
45
+
46
+ def encode
47
+ HasJwtToken::JwtProxy.encode(
48
+ algorithm: algorithm,
49
+ payload: model_payload.merge(claims_payload),
50
+ secret: secret,
51
+ header_fields: header_fields
52
+ )
53
+ end
54
+
55
+ private
56
+
57
+ delegate :algorithm, :secret, :model_payload, :claims_payload, :header_fields, to: :has_jwt_token
12
58
 
13
- if authenticated
14
- @token = encode
15
- self
16
- else
17
- @token = nil
59
+ def has_jwt_token
60
+ @has_jwt_token ||= self.class.has_jwt_token(self)
18
61
  end
19
- rescue JWT::DecodeError
20
- nil
21
62
  end
22
63
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HasJwtToken
4
+ HasJwtTokenError = Class.new(StandardError)
5
+
6
+ class InvalidToken < HasJwtTokenError; end
7
+ class BadConfiguration < HasJwtTokenError; end
8
+ end
@@ -7,9 +7,7 @@ module HasJwtToken
7
7
  def has_jwt_token(model = nil)
8
8
  @has_jwt_token ||= JwtConfiguration.new
9
9
  yield(@has_jwt_token) if block_given?
10
- @has_jwt_token.tap do |config|
11
- config.model = model if model
12
- end
10
+ @has_jwt_token.tap { |jwt| jwt.model = model if model }
13
11
  end
14
12
  end
15
13
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module HasJwtToken
4
4
  class JwtConfiguration
5
+ DEFAULT_AUTH_ATTRIBUTE = :id
5
6
  CLAIMS = {
6
7
  expiration_time: :exp,
7
8
  not_before_time: :nbf,
@@ -57,7 +58,8 @@ module HasJwtToken
57
58
  end
58
59
  end
59
60
 
60
- def payload(name = nil, value = nil)
61
+ def payload(name = nil, value: nil, auth_by: false)
62
+ @authenticate_by = name if auth_by
61
63
  @payload[name] = value || ->(model) { model.respond_to?(name) && model.public_send(name) } if name
62
64
  end
63
65
 
@@ -77,5 +79,9 @@ module HasJwtToken
77
79
  val.is_a?(Proc) ? val.call : val
78
80
  end
79
81
  end
82
+
83
+ def authenticate_by
84
+ @authenticate_by || DEFAULT_AUTH_ATTRIBUTE
85
+ end
80
86
  end
81
87
  end
@@ -4,31 +4,14 @@ require 'jwt'
4
4
 
5
5
  module HasJwtToken
6
6
  class JwtProxy
7
- attr_reader :algorithm, :payload, :secret, :header_fields
7
+ class << self
8
+ def encode(payload:, secret: '', algorithm: '', header_fields: {})
9
+ JWT.encode(payload, secret, algorithm, header_fields)
10
+ end
8
11
 
9
- def initialize(algorithm: '', payload: {}, secret: '', header_fields: {})
10
- @algorithm = algorithm
11
- @payload = payload
12
- @secret = secret
13
- @header_fields = header_fields
14
- end
15
-
16
- def encode
17
- JWT.encode(payload, secret, algorithm, header_fields)
18
- end
19
-
20
- def decode(token)
21
- JWT.decode(token, secret, false, algorithm: algorithm)[0]
22
- end
23
-
24
- def decode!(token)
25
- JWT.decode(token, secret, true, algorithm: algorithm)[0]
26
- end
27
-
28
- def valid?(token)
29
- decode!(token) && true
30
- rescue JWT::DecodeError
31
- false
12
+ def decode!(token:, secret: '', algorithm: '')
13
+ JWT.decode(token, secret, true, algorithm: algorithm)[0]
14
+ end
32
15
  end
33
16
  end
34
17
  end
@@ -4,18 +4,16 @@ require 'active_model'
4
4
  require 'bcrypt'
5
5
  require 'has_jwt_token/authenticatable'
6
6
  require 'has_jwt_token/has_jwt_model_configuration'
7
- require 'has_jwt_token/jwt_tokenable'
8
7
 
9
8
  module HasJwtToken
10
9
  module Model
11
- attr_reader :token
10
+ attr_accessor :token
12
11
 
13
12
  def self.included(base)
14
13
  base.include(ActiveModel::SecurePassword)
15
14
  base.has_secure_password
16
15
  base.include(Authenticatable)
17
16
  base.extend(HasJwtModelConfiguration)
18
- base.include(JwtTokenable)
19
17
  end
20
18
  end
21
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HasJwtToken
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/has_jwt_token.rb CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'active_support/core_ext/module/delegation'
4
4
  require 'has_jwt_token/version'
5
+ require 'has_jwt_token/errors'
5
6
  require 'has_jwt_token/model'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_jwt_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jokūbas Pučinskas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-06 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -167,10 +167,10 @@ files:
167
167
  - has_jwt_token.gemspec
168
168
  - lib/has_jwt_token.rb
169
169
  - lib/has_jwt_token/authenticatable.rb
170
+ - lib/has_jwt_token/errors.rb
170
171
  - lib/has_jwt_token/has_jwt_model_configuration.rb
171
172
  - lib/has_jwt_token/jwt_configuration.rb
172
173
  - lib/has_jwt_token/jwt_proxy.rb
173
- - lib/has_jwt_token/jwt_tokenable.rb
174
174
  - lib/has_jwt_token/model.rb
175
175
  - lib/has_jwt_token/version.rb
176
176
  homepage: https://github.com/pucinsk/has_jwt_token
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.1.2
197
+ rubygems_version: 3.3.7
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Fast running JWT implentation for Rails apps!
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'has_jwt_token/jwt_proxy'
4
-
5
- module HasJwtToken
6
- module JwtTokenable
7
- delegate :algorithm, :secret, :claims_payload, :header_fields, to: :has_jwt_token
8
-
9
- def encode
10
- with_jwt_configuration(&:encode)
11
- end
12
-
13
- def decode(token)
14
- with_jwt_configuration { |jwt| jwt.decode(token) }
15
- end
16
-
17
- def decode!(token)
18
- with_jwt_configuration { |jwt| jwt.decode!(token) }
19
- end
20
-
21
- def has_jwt_token
22
- self.class.has_jwt_token(self)
23
- end
24
-
25
- private
26
-
27
- def payload
28
- @payload ||= has_jwt_token.model_payload.merge(claims_payload)
29
- end
30
-
31
- def with_jwt_configuration
32
- yield(jwt_proxy)
33
- end
34
-
35
- def jwt_proxy
36
- @jwt_proxy ||= JwtProxy.new(
37
- algorithm: algorithm,
38
- payload: payload,
39
- secret: secret,
40
- header_fields: header_fields
41
- )
42
- end
43
- end
44
- end