red_token_auth 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37698c3c846ac9b834f5e54f61f0740d47aba30f
4
- data.tar.gz: 648bfbe72f80db915cba1b00ccf01e197a5bb2a0
3
+ metadata.gz: 9ca882c5a5384b2e8610afd2f87e645db9012cd0
4
+ data.tar.gz: 7b0bd783c3dac1bb81472204cfe9b171c8243d88
5
5
  SHA512:
6
- metadata.gz: 9abfc95f64dfd0c248ae7515809981613e73b71565953a628c65d57795982b68babd05ad87b0bae43fdb419e576c49fbbd0a9966ecfddef6dd4941a3dfc4b8fc
7
- data.tar.gz: b2b27205515f131d53154def7d88871c95e6ac1d897c399ede2329a04e909a8df4cc492524d09c67d44371455424b8e5017712c9a3a3e0da98a8330e93b7eff9
6
+ metadata.gz: 66b21b4b9f5eb419ba9e0ca09bae649298599b7bd135e58f7f5d37347cd373d0bb43d63cd9466ea384c6b908b64a922e421cd818d29dfd6160614618fadb6789
7
+ data.tar.gz: fd38b9fe4b29b7cd228144fd6b96a94217cecb8c98ea46a1c3ab681b2d3de1682f32102cd96f0e74e9f6093bcb48a43793d191749c23474de1e3d794052eefa0
data/README.md CHANGED
@@ -74,7 +74,7 @@ By using the `authenticate!(:user)` in your controller, you'll have access to `c
74
74
  ### Included methods
75
75
  * `User#sign_in`
76
76
 
77
- It'll return `true` if `"password"` matches the user password and an `authentication_token` will be generated for the user. If it doesn't match, errors will be added to `User#errors` and `false` will be returned.
77
+ It'll return `User#create_new_authentication_token` if `"password"` matches the user password and an `authentication_token` will be generated for the user. If it doesn't match, errors will be added to `User#errors` and `false` will be returned.
78
78
 
79
79
  ```ruby
80
80
  user.sign_in("password")
@@ -110,6 +110,17 @@ By using the `authenticate!(:user)` in your controller, you'll have access to `c
110
110
  user.reset_password(reset_password_token: "token", password: "new_password", password_confirmation: "new_password")
111
111
  ```
112
112
 
113
+ * `User#create_new_authentication_token`
114
+
115
+ This method will create new authentication token for the user and will return a hash that can be appended to the headers.
116
+ ```ruby
117
+ user.create_new_authentication_token
118
+ #=> {"access-token" => "==wei2989896756-_", "uid" => "email@email.com", "token-type" => "Bearer"}
119
+
120
+ # In controller scope:
121
+ request.headers.merge!(user.create_new_authentication_token)
122
+ ```
123
+
113
124
  ### Configuring
114
125
  ```ruby
115
126
  RedTokenAuth.configure do |config|
@@ -121,3 +132,4 @@ end
121
132
 
122
133
  ## License
123
134
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
135
+
@@ -4,7 +4,22 @@ module RedTokenAuth
4
4
 
5
5
  included do
6
6
  def authenticate_token(token)
7
- token == authentication_token
7
+ BCrypt::Password.new(authentication_token) == token
8
+ end
9
+
10
+ def create_new_authentication_token
11
+ token = SecureRandom.urlsafe_base64(nil, true)
12
+ token_hash = BCrypt::Password.create(token)
13
+
14
+ self.authentication_token = token_hash
15
+
16
+ save!
17
+
18
+ {
19
+ "access-token" => token,
20
+ "uid" => email,
21
+ "token-type" => "Bearer"
22
+ }
8
23
  end
9
24
  end
10
25
  end
@@ -7,9 +7,10 @@ module RedTokenAuth
7
7
  included do
8
8
  def sign_in(password)
9
9
  if authenticate(password)
10
- update(authentication_token: random_token)
10
+ create_new_authentication_token
11
11
  else
12
12
  errors.add(:password, :wrong_password)
13
+ false
13
14
  end
14
15
  end
15
16
 
@@ -1,3 +1,3 @@
1
1
  module RedTokenAuth
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_token_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Ergos