jwt-auth 4.0.1 → 4.0.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: 350e77e8646205ed02b1db78d49c026fb117559d0a9a6678ab32d72ec2149b7c
4
- data.tar.gz: 1b2083fc8e144347d541a5255422e1e3322784d3b57292f6fe2d9c064d91da62
3
+ metadata.gz: f4ee309e4680b104875e55bdf95fa0f54e104be4596d5a2f8249cc37e8257c95
4
+ data.tar.gz: a8816bfbfe5b1211e4ad6d81a1f902387043c3b4ea38c856811e79012e44454c
5
5
  SHA512:
6
- metadata.gz: 9e3fbe6dffa6da9dbb3df74b23a2375606313ad9c6e572e8cd1a21f74f9999098e0db2a66d7b6d56984359d317dbdc6c644ff3ac3e32a8534368acb0b1f4b50b
7
- data.tar.gz: 5ae2ac9c28f0a43fb3f4d14d2711a0e95821197b9397c92079e7ac6c62ce6d01600fb538b247e7f1824a38e5cee4ccfed5edf80626403779a19665495aaa157f
6
+ metadata.gz: 02da9f0ef071a5844531310379c1a5778ddda6f0ea7f450052449e2b6cdf46b05c2bdc667c6e14f5cc6eff97dbcd97e5038f03719e9e0f87f1736fd3210825eb
7
+ data.tar.gz: '09978d0bb5d5430f73adafc7dc2f2e6c0c0d934b952e8fc93c5a8a9f6e8116677c120d8e91820af83aa25c5ddd380d08de8f63ab8adfa0a17941b3ecb8127184'
data/README.md CHANGED
@@ -34,6 +34,8 @@ JWT::Auth.configure do |config|
34
34
  end
35
35
  ```
36
36
 
37
+ Do not try to set the `model` configuration property in the initializer, as this property is already set by including the `Authenticatable` concern in your model.
38
+
37
39
  Include model methods in your user model:
38
40
 
39
41
  ```ruby
@@ -12,7 +12,7 @@ module JWT
12
12
 
13
13
  included do
14
14
  JWT::Auth.configure do |config|
15
- config.model = const_get name
15
+ config.model = name
16
16
  end
17
17
  end
18
18
  end
@@ -54,23 +54,31 @@ module JWT
54
54
  JWT::Auth.token_lifetime
55
55
  end
56
56
 
57
- def self.from_token(token)
58
- begin
59
- @decoded_payload = JWT.decode(token, JWT::Auth.secret).first
60
- rescue JWT::DecodeError
61
- @decoded_payload = {}
57
+ class << self
58
+ def from_token(token)
59
+ begin
60
+ @decoded_payload = JWT.decode(token, JWT::Auth.secret).first
61
+ rescue JWT::DecodeError
62
+ @decoded_payload = {}
63
+ end
64
+
65
+ token = self.new
66
+ token.issued_at = @decoded_payload['iat']
67
+ token.token_version = @decoded_payload['ver']
68
+
69
+ if @decoded_payload['sub']
70
+ find_method = model.respond_to?(:find_by_token) ? :find_by_token : :find_by
71
+ token.subject = model.send find_method, :id => @decoded_payload['sub'], :token_version => @decoded_payload['ver']
72
+ end
73
+
74
+ token
62
75
  end
63
76
 
64
- token = self.new
65
- token.issued_at = @decoded_payload['iat']
66
- token.token_version = @decoded_payload['ver']
77
+ private
67
78
 
68
- if @decoded_payload['sub']
69
- find_method = JWT::Auth.model.respond_to?(:find_by_token) ? :find_by_token : :find_by
70
- token.subject = JWT::Auth.model.send find_method, :id => @decoded_payload['sub'], :token_version => @decoded_payload['ver']
79
+ def model
80
+ const_get JWT::Auth.model
71
81
  end
72
-
73
- token
74
82
  end
75
83
  end
76
84
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JWT
4
4
  module Auth
5
- VERSION = '4.0.1'
5
+ VERSION = '4.0.2'
6
6
  end
7
7
  end
@@ -13,6 +13,6 @@ RSpec.describe JWT::Auth do
13
13
 
14
14
  expect(subject.token_lifetime).to eq 24.hours
15
15
  expect(subject.secret).to eq 'mysecret'
16
- expect(subject.model).to eq User
16
+ expect(subject.model).to eq 'User'
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2019-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -278,8 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  - !ruby/object:Gem::Version
279
279
  version: '0'
280
280
  requirements: []
281
- rubyforge_project:
282
- rubygems_version: 2.7.3
281
+ rubygems_version: 3.0.1
283
282
  signing_key:
284
283
  specification_version: 4
285
284
  summary: JWT-based authentication for Rails API