model_token_auth 1.1.1 → 1.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db811590f96edd70be9dd6a69de23417df28b1f0bd462329730425224538866
|
4
|
+
data.tar.gz: 89dd8598f5366e651ff3a05faa776021e6fcb9500ee6f6a21ce7e6635a11f4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa3c52bd3765557b37aa4e4317792e6e9c6c6cce5f5b6520f38f272379dc8ff3cd3dde2c3b5e369d0c54e9e186a0eaf264a21f1ba6eac75348f0a5605c18757
|
7
|
+
data.tar.gz: ce058c13cf9204bcf68d5f2d9136265464db6c56c1c3a0fcae4daba832ed1f549b1b5c337fbbcb4ff210d3bb079bb6493dc6efa23df89d789f147fc7dcb2ab7b
|
data/README.md
CHANGED
@@ -36,14 +36,15 @@ Once the migration finishes, the models will be ready to be authenticated.
|
|
36
36
|
|
37
37
|
This plugin handles Token authentication for models. In models in which
|
38
38
|
`#acts_as_model_authenticable` method is called, the instances will be able generating
|
39
|
-
a token by calling the methods `#save`, `#create` and `#create!`of ActiveRecord
|
40
|
-
token is generated in an associated model called AccessToken
|
39
|
+
a token by calling the methods `#save`, `#create` and `#create!`of `ActiveRecord::Base`.
|
40
|
+
The token is generated in an associated model called `AccessToken`.
|
41
41
|
|
42
42
|
The plugin also handles authentication in the controllers by inserting a generic
|
43
|
-
`#authenticate!` method
|
44
|
-
will verify the existence of the token and
|
43
|
+
`#authenticate!` method when calling the callback `acts_as_controller_authenticable` in
|
44
|
+
ApplicationController. This method will verify the existence of the token and
|
45
|
+
creates the `current_*` method.
|
45
46
|
|
46
|
-
To authenticate some token
|
47
|
+
To authenticate some token the request will need the standard header `Authorization`
|
47
48
|
with a token as a value.
|
48
49
|
|
49
50
|
### Models
|
@@ -51,8 +52,6 @@ with a token as a value.
|
|
51
52
|
Make models authenticatables.
|
52
53
|
|
53
54
|
```ruby
|
54
|
-
# example
|
55
|
-
|
56
55
|
class Center < ActiveRecord::Base
|
57
56
|
acts_as_model_authenticable
|
58
57
|
end
|
@@ -78,11 +77,9 @@ center.access_token
|
|
78
77
|
|
79
78
|
### Controllers
|
80
79
|
|
81
|
-
Allow controllers to handle token authentication
|
80
|
+
Allow controllers to handle token authentication.
|
82
81
|
|
83
82
|
```ruby
|
84
|
-
# example ActionController::Base
|
85
|
-
|
86
83
|
class ApplicationController < ActionController::Base
|
87
84
|
acts_as_controller_authenticable
|
88
85
|
end
|
@@ -122,14 +119,14 @@ end
|
|
122
119
|
|
123
120
|
To facilitate the testing of the controllers:
|
124
121
|
|
125
|
-
1.- Add a new folder with the name of
|
122
|
+
1.- Add a new folder with the name of `support` in the root of `spec`.
|
126
123
|
|
127
|
-
2.- Create a ruby file with the name of model_token_auth_helper (
|
124
|
+
2.- Create a ruby file with the name of model_token_auth_helper (`model_token_auth_helper.rb`).
|
128
125
|
|
129
126
|
3.- Copy the following code:
|
130
127
|
|
131
128
|
```ruby
|
132
|
-
#
|
129
|
+
# model_token_auth_helper.rb
|
133
130
|
|
134
131
|
module ModelTokenAuthHelper
|
135
132
|
|
@@ -145,18 +142,17 @@ module ModelTokenAuthHelper
|
|
145
142
|
# value of the token that is passed to it,
|
146
143
|
# giving it the necessary format.
|
147
144
|
#
|
148
|
-
def add_authorization_header(
|
149
|
-
request.env['HTTP_AUTHORIZATION'] =
|
150
|
-
ActionController::HttpAuthentication::Token.encode_credentials(token)
|
145
|
+
def add_authorization_header(access_token)
|
146
|
+
subject.request.env['HTTP_AUTHORIZATION'] =
|
147
|
+
ActionController::HttpAuthentication::Token.encode_credentials(access_token.token)
|
151
148
|
end
|
152
149
|
end
|
153
150
|
```
|
154
151
|
|
155
|
-
4.- Require ModelTokenAuthHelper at top of the file
|
156
|
-
the RSpec configuration:
|
152
|
+
4.- Require `ModelTokenAuthHelper` at the top of the file `spec_helper.rb` and add the module to the RSpec configuration:
|
157
153
|
|
158
154
|
```ruby
|
159
|
-
#
|
155
|
+
# spec_helper.rb
|
160
156
|
|
161
157
|
require_relative 'support/model_token_auth_helper'
|
162
158
|
|
@@ -170,7 +166,7 @@ end
|
|
170
166
|
|
171
167
|
### ModelTokenAuthHelper Usage
|
172
168
|
|
173
|
-
Here is described how to use the methods of the ModelTokenAuthHelper module that we created
|
169
|
+
Here is described how to use the methods of the ModelTokenAuthHelper module that we created.
|
174
170
|
|
175
171
|
```ruby
|
176
172
|
require 'rails_helper'
|
@@ -222,11 +218,11 @@ Bug report or pull request are welcome.
|
|
222
218
|
|
223
219
|
Make a pull request:
|
224
220
|
|
225
|
-
-
|
226
|
-
- Create your feature branch
|
227
|
-
- Commit your changes
|
228
|
-
- Push
|
229
|
-
- Create new Pull
|
221
|
+
- Clone the repo
|
222
|
+
- Create your feature branch
|
223
|
+
- Commit your changes
|
224
|
+
- Push the branch
|
225
|
+
- Create new Pull-Request
|
230
226
|
|
231
227
|
Please write tests if necessary.
|
232
228
|
|
data/lib/model_token_auth.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "model_token_auth/railtie"
|
2
2
|
require 'model_token_auth/access_tokens_config'
|
3
3
|
require 'model_token_auth/acts_as_model_authenticable'
|
4
|
-
require 'model_token_auth/
|
4
|
+
require 'model_token_auth/acts_as_controller_authenticable'
|
5
5
|
|
6
6
|
# => Class associated with the models
|
7
7
|
# that will be authenticated.
|
@@ -15,9 +15,7 @@ class AccessToken < ActiveRecord::Base
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# => *
|
18
|
-
|
18
|
+
include ModelTokenAuth::ActsAsControllerAuthenticable
|
19
19
|
|
20
20
|
# => *
|
21
|
-
|
22
|
-
resource.include ModelTokenAuth::ActsAsControllersAuthenticable
|
23
|
-
end
|
21
|
+
ActiveRecord::Base.include ModelTokenAuth::ActsAsModelAuthenticable
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_token_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Armando Alejandre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -138,7 +138,7 @@ files:
|
|
138
138
|
- lib/generators/access_token/templates/migration.rb
|
139
139
|
- lib/model_token_auth.rb
|
140
140
|
- lib/model_token_auth/access_tokens_config.rb
|
141
|
-
- lib/model_token_auth/
|
141
|
+
- lib/model_token_auth/acts_as_controller_authenticable.rb
|
142
142
|
- lib/model_token_auth/acts_as_model_authenticable.rb
|
143
143
|
- lib/model_token_auth/controllers_auth.rb
|
144
144
|
- lib/model_token_auth/railtie.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'model_token_auth/controllers_auth'
|
2
|
-
|
3
|
-
module ModelTokenAuth
|
4
|
-
module ActsAsControllersAuthenticable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
class_methods do
|
8
|
-
def acts_as_controller_authenticable
|
9
|
-
superclass.include ModelTokenAuth::ControllersAuth
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|