grape_devise_auth 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/grape_devise_auth.rb +2 -4
- data/lib/grape_devise_auth/auth_headers.rb +1 -1
- data/lib/grape_devise_auth/auth_helpers.rb +11 -31
- data/lib/grape_devise_auth/configuration.rb +2 -9
- data/lib/grape_devise_auth/middleware.rb +4 -46
- data/lib/grape_devise_auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b9b3d196787d6ee25e67f15ee0c23bdade1b43b
|
4
|
+
data.tar.gz: 2784c17dcc774bc5ecd8adaaef7ef9f36714ee4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebac066932bfbadb5c22e39cd472e0263de23b600e15cb36f733cde4d18f00805f6906b0c01127b699ee0b25420bbff2b7581b9f5b57b0bef3ea33401e1fe6f4
|
7
|
+
data.tar.gz: 46b7f0c060874447f2d5425f30632ee0778065a3173df7ca9e256b64034af36e04d014023f664548e5663eb4e50605c0175efe0410fcdce4918d092ba65050d3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
##Current - 0.0.
|
1
|
+
##Current - 0.0.4
|
2
2
|
|
3
|
+
#### Remove unnecessary code
|
4
|
+
#### Code refactor
|
5
|
+
#### Fix bug with multiple models names compatibility
|
6
|
+
#### Fix registration bug from version 0.0.3
|
7
|
+
|
8
|
+
|
9
|
+
### 0.0.3
|
3
10
|
#### Passing ActiveRecord error message to RegistrationFailed exception
|
4
11
|
|
5
12
|
|
data/lib/grape_devise_auth.rb
CHANGED
@@ -17,9 +17,7 @@ module GrapeDeviseAuth
|
|
17
17
|
:token_lifespan,
|
18
18
|
:max_number_of_devices,
|
19
19
|
:headers_names,
|
20
|
-
:remove_tokens_after_password_reset
|
21
|
-
:authenticate_all,
|
22
|
-
:skip_middleware_unauthorized_error_raising
|
20
|
+
:remove_tokens_after_password_reset
|
23
21
|
|
24
22
|
def configuration
|
25
23
|
@configuration ||= Configuration.new
|
@@ -42,4 +40,4 @@ module GrapeDeviseAuth
|
|
42
40
|
)
|
43
41
|
end
|
44
42
|
end
|
45
|
-
end
|
43
|
+
end
|
@@ -7,17 +7,18 @@ module GrapeDeviseAuth
|
|
7
7
|
end
|
8
8
|
|
9
9
|
define_method("authenticate_#{mapping}") do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
token_authorizer = TokenAuthorizer.new(authorizer_data,
|
10
|
+
@authorizer_data = AuthorizerData.from_env(env)
|
11
|
+
devise_interface = DeviseInterface.new(@authorizer_data)
|
12
|
+
token_authorizer = TokenAuthorizer.new(@authorizer_data,
|
14
13
|
devise_interface)
|
15
14
|
|
16
15
|
resource = token_authorizer.authenticate_from_token(mapping)
|
17
16
|
if resource
|
18
17
|
devise_interface.set_user_in_warden(mapping, resource)
|
19
|
-
|
20
|
-
|
18
|
+
env[Configuration::CURRENT_AUTH_HEADERS] = AuthHeaders.new(warden,
|
19
|
+
mapping,
|
20
|
+
env[Configuration::REQUEST_START],
|
21
|
+
@authorizer_data).headers
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -33,7 +34,7 @@ module GrapeDeviseAuth
|
|
33
34
|
resource = resource_class(mapping).find_by_uid(uid)
|
34
35
|
|
35
36
|
if resource && valid_params?(field, uid) && resource.valid_password?(params[:password]) && (!resource.respond_to?(:active_for_authentication?) || resource.active_for_authentication?)
|
36
|
-
|
37
|
+
env[Configuration::CURRENT_AUTH_HEADERS] = resource.create_new_auth_token
|
37
38
|
warden.set_user(resource, scope: mapping, store: false)
|
38
39
|
end
|
39
40
|
end
|
@@ -74,16 +75,13 @@ module GrapeDeviseAuth
|
|
74
75
|
resource.email = declared(params)['email'].try :downcase
|
75
76
|
end
|
76
77
|
|
77
|
-
if resource.save
|
78
|
-
|
79
|
-
else
|
80
|
-
resource
|
81
|
-
end
|
78
|
+
env[Configuration::CURRENT_AUTH_HEADERS] = resource.create_new_auth_token if resource.save
|
79
|
+
resource
|
82
80
|
end
|
83
81
|
|
84
82
|
define_method("register_#{mapping}!") do
|
85
83
|
register = send("register_#{mapping}")
|
86
|
-
raise RegistrationFailed.new(register.errors) if register.errors
|
84
|
+
raise RegistrationFailed.new(register.errors) if register.errors.any?
|
87
85
|
register
|
88
86
|
end
|
89
87
|
end
|
@@ -121,23 +119,5 @@ module GrapeDeviseAuth
|
|
121
119
|
def find_uid(field)
|
122
120
|
request.headers[field.to_s.capitalize] || params[field] || request.headers['Uid'] || params['uid']
|
123
121
|
end
|
124
|
-
|
125
|
-
def load_auth_headers_data(mapping)
|
126
|
-
env[Configuration::UID_KEY] = find_uid(authentication_field(mapping))
|
127
|
-
env[Configuration::CLIENT_KEY] = request.headers['Client'] || params['client']
|
128
|
-
env[Configuration::ACCESS_TOKEN_KEY] = request.headers['Access-Token'] || params['access-token']
|
129
|
-
end
|
130
|
-
|
131
|
-
def update_expiry_for_client_token(client_id)
|
132
|
-
if @user
|
133
|
-
@client_id = client_id
|
134
|
-
@user.tokens[@client_id]['expiry'] = (Time.now + GrapeDeviseAuth.token_lifespan).to_i
|
135
|
-
@user.save
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def update_env_with_auth_data(auth_data)
|
140
|
-
env[Configuration::CURRENT_AUTH_HEADERS] = auth_data
|
141
|
-
end
|
142
122
|
end
|
143
123
|
end
|
@@ -2,24 +2,22 @@ module GrapeDeviseAuth
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :batch_request_buffer_throttle,
|
4
4
|
:change_headers_on_each_request,
|
5
|
-
:authenticate_all,
|
6
5
|
:default_provider,
|
7
6
|
:token_lifespan,
|
8
7
|
:max_number_of_devices,
|
9
8
|
:headers_names,
|
10
|
-
:remove_tokens_after_password_reset
|
11
|
-
:skip_middleware_unauthorized_error_raising
|
9
|
+
:remove_tokens_after_password_reset
|
12
10
|
|
13
11
|
ACCESS_TOKEN_KEY = 'HTTP_ACCESS_TOKEN'
|
14
12
|
EXPIRY_KEY = 'HTTP_EXPIRY'
|
15
13
|
UID_KEY = 'HTTP_UID'
|
16
14
|
CLIENT_KEY = 'HTTP_CLIENT'
|
15
|
+
REQUEST_START = 'REQUEST_START'
|
17
16
|
CURRENT_AUTH_HEADERS = 'CURRENT_AUTH_HEADERS'
|
18
17
|
|
19
18
|
def initialize
|
20
19
|
@batch_request_buffer_throttle = 2.weeks
|
21
20
|
@change_headers_on_each_request = true
|
22
|
-
@authenticate_all = false
|
23
21
|
@default_provider = 'email'
|
24
22
|
@token_lifespan = 2.weeks
|
25
23
|
@max_number_of_devices = 10
|
@@ -29,11 +27,6 @@ module GrapeDeviseAuth
|
|
29
27
|
:'uid' => 'uid',
|
30
28
|
:'token-type' => 'token-type' }
|
31
29
|
@remove_tokens_after_password_reset = false
|
32
|
-
@skip_middleware_unauthorized_error_raising = true
|
33
|
-
end
|
34
|
-
|
35
|
-
def auth_all?
|
36
|
-
@authenticate_all
|
37
30
|
end
|
38
31
|
end
|
39
32
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module GrapeDeviseAuth
|
2
2
|
class Middleware
|
3
|
-
extend Forwardable
|
4
3
|
|
5
4
|
def initialize(app, resource_name)
|
6
5
|
@app = app
|
@@ -9,58 +8,17 @@ module GrapeDeviseAuth
|
|
9
8
|
|
10
9
|
def call(env)
|
11
10
|
setup(env)
|
12
|
-
|
13
|
-
auth_all
|
14
|
-
responses_with_auth_headers(*@app.call(env))
|
15
|
-
rescue Unauthorized => _e
|
16
|
-
return unauthorized unless GrapeDeviseAuth.skip_middleware_unauthorized_error_raising
|
17
|
-
raise Unauthorized
|
18
|
-
end
|
11
|
+
responses_with_headers(*@app.call(env))
|
19
12
|
end
|
20
13
|
|
21
14
|
private
|
22
15
|
|
23
|
-
attr_reader :authorizer_data, :token_authorizer, :resource, :request_start
|
24
|
-
def_delegators :@authorizer_data, :warden, :token, :client_id
|
25
|
-
|
26
|
-
def auth_all
|
27
|
-
return if skip_auth_all?
|
28
|
-
user = token_authorizer.authenticate_from_token(@resource_name)
|
29
|
-
fail Unauthorized unless user
|
30
|
-
sign_in_user(user)
|
31
|
-
end
|
32
|
-
|
33
|
-
def skip_auth_all?
|
34
|
-
!GrapeDeviseAuth.configuration.auth_all?
|
35
|
-
end
|
36
|
-
|
37
16
|
def setup(env)
|
38
|
-
|
39
|
-
@authorizer_data = AuthorizerData.from_env(env)
|
40
|
-
@devise_interface = DeviseInterface.new(@authorizer_data)
|
41
|
-
@token_authorizer = TokenAuthorizer.new(@authorizer_data,
|
42
|
-
@devise_interface)
|
43
|
-
end
|
44
|
-
|
45
|
-
def sign_in_user(user)
|
46
|
-
@devise_interface.set_user_in_warden(@resource_name, user)
|
47
|
-
end
|
48
|
-
|
49
|
-
def responses_with_auth_headers(status, headers, response)
|
50
|
-
auth_headers = AuthHeaders.new(warden, @resource_name, request_start, authorizer_data)
|
51
|
-
[
|
52
|
-
status,
|
53
|
-
headers.merge(auth_headers.headers),
|
54
|
-
response
|
55
|
-
]
|
17
|
+
env[Configuration::REQUEST_START] = Time.now
|
56
18
|
end
|
57
19
|
|
58
|
-
def
|
59
|
-
[
|
60
|
-
{ 'Content-Type' => 'application/json'
|
61
|
-
},
|
62
|
-
[]
|
63
|
-
]
|
20
|
+
def responses_with_headers(status, headers, response)
|
21
|
+
[ status, headers, response ]
|
64
22
|
end
|
65
23
|
end
|
66
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_devise_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolskyi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|