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 +4 -4
- data/README.md +13 -1
- data/lib/red_token_auth/authentication.rb +16 -1
- data/lib/red_token_auth/sign_in_out.rb +2 -1
- data/lib/red_token_auth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca882c5a5384b2e8610afd2f87e645db9012cd0
|
4
|
+
data.tar.gz: 7b0bd783c3dac1bb81472204cfe9b171c8243d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 `
|
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
|
-
|
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
|