cow_auth 0.5.3 → 0.6.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: 1455b64dcd0206bf8ffd9a4539f4de942952ede5dad80c60b0f86186814735fc
4
- data.tar.gz: fc0e8de3a619e761b9fcdc525622d8056f20f939e60592064ada6f76adbcf9a3
3
+ metadata.gz: 64a895f28d740efa94c2a8b5684cd97997d4d17cf50376b9859b869ed16b2a07
4
+ data.tar.gz: 52cba6f14267edb2b7c8e764421a1ec53aef72e96650bbf104be2de2119804f4
5
5
  SHA512:
6
- metadata.gz: 5d2fc711916cb332f6279cee78459af32a0610264a95ab4899db92d693d6083acbef67491c2ed296e102f8423b5e0ebd50cabbc749ce3cd61eaa06cdd4bed0d4
7
- data.tar.gz: 964cf902670e4f7298b9ba2593e675d7fd00699424c79bc38e6cafb67072b39bb5462e336e1408dbaa7868ab1a70a086952c54220a874cfcf858949610b3d8db
6
+ metadata.gz: 9d23c75c2a71d0e4d1e574f86a2e8adc70e3b018674852b18452475eed477387c6b56f07a3e9aed59b64475eb9e21e3667ce863be852320adc71526de1315c04
7
+ data.tar.gz: ad348254f5901b73ddd9a5a5ae79aa49305e55ee65cf019ab293f0338245fe1c65ed3bea8acdde0e5b6ce26a328aa64da4dd7c11f69458d90d6b128f93579f9c
data/Gemfile.lock CHANGED
@@ -1,31 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cow_auth (0.5.3)
4
+ cow_auth (0.6.0)
5
5
  activesupport (~> 5.1)
6
6
  scrypt (~> 3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.1.4)
11
+ activesupport (5.2.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (~> 0.7)
13
+ i18n (>= 0.7, < 2)
14
14
  minitest (~> 5.1)
15
15
  tzinfo (~> 1.1)
16
16
  concurrent-ruby (1.0.5)
17
- ffi (1.9.18)
17
+ ffi (1.9.25)
18
18
  ffi-compiler (1.0.1)
19
19
  ffi (>= 1.0.0)
20
20
  rake
21
- i18n (0.9.1)
21
+ i18n (1.1.0)
22
22
  concurrent-ruby (~> 1.0)
23
- minitest (5.11.1)
24
- rake (12.3.0)
23
+ minitest (5.11.3)
24
+ rake (12.3.1)
25
25
  scrypt (3.0.5)
26
26
  ffi-compiler (>= 1.0, < 2.0)
27
27
  thread_safe (0.3.6)
28
- tzinfo (1.2.4)
28
+ tzinfo (1.2.5)
29
29
  thread_safe (~> 0.1)
30
30
 
31
31
  PLATFORMS
@@ -38,4 +38,4 @@ DEPENDENCIES
38
38
  rake (~> 12.3)
39
39
 
40
40
  BUNDLED WITH
41
- 1.16.1
41
+ 1.16.2
data/README.md CHANGED
@@ -26,7 +26,7 @@ Configure your user model to add the authentication mechanism.
26
26
 
27
27
  #### Generator (Example)
28
28
 
29
- $ bundle exec rails generate model user uuid:string:uniq email:string:uniq sid:string:uniq encrypted_password:string locale:string first_name:string last_name:string role:integer sign_in_count:integer is_approved:boolean is_deleted:boolean
29
+ $ bundle exec rails generate model user uuid:string:uniq email:string:uniq sid:string:uniq encrypted_password:string locale:string first_name:string last_name:string sign_in_count:integer is_enabled:boolean is_deleted:boolean
30
30
 
31
31
  #### Migration (Example)
32
32
 
@@ -41,9 +41,8 @@ Configure your user model to add the authentication mechanism.
41
41
  t.string :locale, null: false
42
42
  t.string :first_name
43
43
  t.string :last_name
44
- t.integer :role, default: 0, null: false
45
44
  t.integer :sign_in_count, default: 0, null: false
46
- t.boolean :is_approved, default: false, null: false
45
+ t.boolean :is_enabled, default: false, null: false
47
46
  t.boolean :is_deleted, default: false, null: false
48
47
  t.timestamps
49
48
  t.index [:uuid], unique: true
@@ -1,7 +1,4 @@
1
1
  module CowAuth
2
2
  class NotAuthenticatedError < StandardError
3
3
  end
4
-
5
- class RedisHandleMissingError < StandardError
6
- end
7
4
  end
data/lib/cow_auth/user.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'scrypt'
2
- require 'cow_auth/exceptions'
3
2
 
4
3
  module CowAuth
5
4
  module User
@@ -26,34 +25,31 @@ module CowAuth
26
25
  end
27
26
 
28
27
  def authenticate_with_token(auth_token)
29
- api_key = self.fetch_api_key_from_redis(sid)
30
- if api_key.present? &&
31
- api_key.key?(:auth_token) &&
32
- api_key.key?(:expires_at) &&
33
- api_key[:auth_token] == auth_token &&
34
- api_key[:expires_at] > Time.zone.now
28
+ if self.auth_token.present? &&
29
+ self.expires_at.present? &&
30
+ self.auth_token == auth_token &&
31
+ self.expires_at > Time.zone.now
35
32
  return true
36
33
  end
37
34
  return false
38
35
  end
39
36
 
40
37
  def api_sign_in
41
- self.redis_handle.set(self.redis_key, {
38
+ self.update(
42
39
  auth_token: self.token_valid? ? self.auth_token : self.generate_auth_token,
43
40
  expires_at: self.generate_token_expires_at
44
- }.to_json)
41
+ )
45
42
  return true
46
43
  end
47
44
 
48
45
  def api_sign_out
49
- self.redis_handle.del(self.redis_key)
46
+ self.update(
47
+ auth_token: nil,
48
+ expires_at: nil
49
+ )
50
50
  return true
51
51
  end
52
52
 
53
- def auth_token
54
- return self.fetch_api_key_from_redis(self.sid).try(:[], :auth_token)
55
- end
56
-
57
53
  def password=(new_password)
58
54
  return false if new_password.blank?
59
55
  salt = SCrypt::Engine.generate_salt
@@ -63,11 +59,6 @@ module CowAuth
63
59
 
64
60
  protected
65
61
 
66
- def fetch_api_key_from_redis(sid)
67
- api_key = self.redis_handle.get(self.redis_key)
68
- return api_key.present? ? JSON.parse(api_key).try(:symbolize_keys) : nil
69
- end
70
-
71
62
  def generate_auth_token
72
63
  return SecureRandom.hex(64)
73
64
  end
@@ -76,21 +67,10 @@ module CowAuth
76
67
  return 1.month.from_now
77
68
  end
78
69
 
79
- def redis_handle
80
- raise CowAuth::RedisHandleMissingError.new('"$redis" handle not found.') unless $redis.present?
81
- return $redis
82
- end
83
-
84
- def redis_key
85
- return "user_#{self.sid.downcase}"
86
- end
87
-
88
70
  def token_valid?
89
- api_key = self.fetch_api_key_from_redis(self.sid)
90
- return api_key.present? &&
91
- api_key.key?(:auth_token) &&
92
- api_key.key?(:expires_at) &&
93
- api_key[:expires_at] > Time.zone.now
71
+ return self.auth_token.present? &&
72
+ self.expires_at.present? &&
73
+ self.expires_at > Time.zone.now
94
74
  end
95
75
 
96
76
  private
@@ -1,3 +1,3 @@
1
1
  module CowAuth
2
- VERSION = '0.5.3'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cow_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickey Cowden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.7.4
128
+ rubygems_version: 2.7.7
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Authentication gem