auth-lh 0.30.0 → 1.0
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/CHANGELOG.md +4 -0
- data/lib/auth/lh.rb +1 -0
- data/lib/auth/lh/version.rb +1 -1
- data/lib/auth_lh/api.rb +16 -20
- data/lib/auth_lh/auth_management.rb +48 -0
- data/lib/auth_lh/user_management.rb +23 -28
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4241bf40e9b6644cbb77638cf083fe9161a675
|
4
|
+
data.tar.gz: de2e76baef61b694fca69931cc30866d13909b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b3ca6c33c947982634c3b64a81c02c57d0055449c51eb55fa96facba9ee3041049e1fdd62f6a3d35a1c07b6f713d08a884a8fbdbe135726714816e371f1d50
|
7
|
+
data.tar.gz: aa3115b2f40894959d9bc1ceb695bb000a0db91ed82995a0bc784b4126f68eee73a391ed85a737d3a6ed2a71bafe9e1ba3b5f7939304c846cff6fcdfb9a33c5e
|
data/CHANGELOG.md
CHANGED
data/lib/auth/lh.rb
CHANGED
data/lib/auth/lh/version.rb
CHANGED
data/lib/auth_lh/api.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
module AuthLh
|
2
2
|
class Api
|
3
|
-
def
|
3
|
+
def initialize(args={})
|
4
4
|
@endpoint = (args[:endpoint] || 'https://usuarios.lhconfort.com.ar')
|
5
5
|
@application_code = args[:application_code]
|
6
6
|
@access_token = args[:access_token]
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def get_user(login)
|
10
10
|
User.new(get_request("/api/users/#{CGI::escape(login)}"))
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def update_user(login, attrs={})
|
14
14
|
User.new(put_request("/api/users/#{CGI::escape(login)}", attrs))
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def get_users(filters={})
|
18
18
|
results = get_request('/api/users', filters)
|
19
19
|
results.map { |r| User.new(r) }
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def get_users_extended(filters={})
|
23
23
|
results = get_request('/api/users/extended', filters)
|
24
24
|
results.map { |r| UserExtended.new(r) }
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def get_external_apps
|
28
28
|
results = get_request('/api/external_apps')
|
29
29
|
results.map { |r| ExternalAppExtended.new(r) }
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def get_roles
|
33
33
|
results = get_request('/api/roles')
|
34
34
|
results.map { |r| Role.new(r) }
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def get_role(role_id)
|
38
38
|
Role.new(get_request("/api/roles/#{role_id}"))
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def get_current_user(session_token, remote_ip, return_url=nil)
|
42
42
|
result = get_request '/api/current_user', {
|
43
43
|
app_code: @application_code,
|
44
44
|
session_token: session_token,
|
@@ -49,13 +49,13 @@ module AuthLh
|
|
49
49
|
SessionResponse.new(result)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
52
|
+
def get_current_shop(ip_address=nil)
|
53
53
|
attrs = { ip: ip_address }
|
54
54
|
response = get_request('/api/current_shop', attrs)
|
55
55
|
response.nil? ? nil : Shop.new(response)
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def login_url(return_url=nil)
|
59
59
|
if return_url.present?
|
60
60
|
"#{@endpoint}/login?return_url=#{CGI::escape(return_url)}"
|
61
61
|
else
|
@@ -63,7 +63,7 @@ module AuthLh
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def logout_url(return_url=nil)
|
67
67
|
if return_url.present?
|
68
68
|
"#{@endpoint}/logout?return_url=#{CGI::escape(return_url)}"
|
69
69
|
else
|
@@ -71,7 +71,7 @@ module AuthLh
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
74
|
+
def change_password_url(return_url=nil)
|
75
75
|
if return_url.present?
|
76
76
|
"#{@endpoint}/current_user/password/edit?return_url=#{CGI::escape(return_url)}"
|
77
77
|
else
|
@@ -79,13 +79,9 @@ module AuthLh
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
def self.my_apps_url
|
83
|
-
"#{@endpoint}"
|
84
|
-
end
|
85
|
-
|
86
82
|
protected
|
87
83
|
|
88
|
-
def
|
84
|
+
def get_request(action, params={})
|
89
85
|
response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
|
90
86
|
|
91
87
|
if response.body == 'null'
|
@@ -95,7 +91,7 @@ module AuthLh
|
|
95
91
|
end
|
96
92
|
end
|
97
93
|
|
98
|
-
def
|
94
|
+
def put_request(action, params={})
|
99
95
|
response = RestClient.put("#{@endpoint}#{action}", params, auth_headers)
|
100
96
|
|
101
97
|
if response.body == 'null'
|
@@ -105,7 +101,7 @@ module AuthLh
|
|
105
101
|
end
|
106
102
|
end
|
107
103
|
|
108
|
-
def
|
104
|
+
def auth_headers
|
109
105
|
{ authorization: "Token token=\"#{@access_token}\"" }
|
110
106
|
end
|
111
107
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AuthLh
|
2
|
+
module AuthManagement
|
3
|
+
def set_current_user
|
4
|
+
session_response = @auth_api.get_current_user(cookies[:session_token], request.remote_ip, request.original_url)
|
5
|
+
|
6
|
+
if session_response.user
|
7
|
+
@current_user = ::User.find_or_create_by(login: session_response.user.login)
|
8
|
+
@current_user.auth_user = session_response.user
|
9
|
+
end
|
10
|
+
|
11
|
+
if session_response.destination_url.present?
|
12
|
+
redirect_to session_response.destination_url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
@current_user
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_current_shop
|
21
|
+
@current_shop = @auth_api.get_current_shop(request.remote_ip)
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_shop
|
25
|
+
@current_shop
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_access_grants
|
29
|
+
if current_user
|
30
|
+
if !current_user.can_access?(params[:controller], params[:action])
|
31
|
+
if request.xhr?
|
32
|
+
render status: :forbidden
|
33
|
+
else
|
34
|
+
render file: 'public/403.html', layout: false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def logout_url
|
41
|
+
@auth_api.logout_url(request.protocol + request.host_with_port)
|
42
|
+
end
|
43
|
+
|
44
|
+
def change_password_url
|
45
|
+
@auth_api.change_password_url(request.original_url)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -22,7 +22,7 @@ module AuthLh
|
|
22
22
|
|
23
23
|
module ClassMethods
|
24
24
|
def all_external
|
25
|
-
@cached_users ||=
|
25
|
+
@cached_users ||= auth_api.get_users({ pagination: 'false' })
|
26
26
|
end
|
27
27
|
|
28
28
|
def all_external_with_role(role_id)
|
@@ -31,7 +31,13 @@ module AuthLh
|
|
31
31
|
|
32
32
|
def all_external_with_some_role(role_ids)
|
33
33
|
all_external.find_all { |x|
|
34
|
-
role_ids.any? { |role_id| x.
|
34
|
+
role_ids.any? { |role_id| x.has_some_role?(role_id) }
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_external_with_all_roles(role_ids)
|
39
|
+
all_external.find_all { |x|
|
40
|
+
role_ids.any? { |role_id| x.has_all_roles?(role_id) }
|
35
41
|
}
|
36
42
|
end
|
37
43
|
|
@@ -39,43 +45,32 @@ module AuthLh
|
|
39
45
|
all_external.find { |x| x.login == login.to_s }
|
40
46
|
end
|
41
47
|
|
42
|
-
def
|
43
|
-
|
48
|
+
def find_external_with_role(role_id)
|
49
|
+
all_external_with_role(role_id).first
|
44
50
|
end
|
45
51
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
logged_user = response.user
|
50
|
-
@destination_url = response.destination_url
|
52
|
+
def find_external_with_some_role(role_ids)
|
53
|
+
all_external_with_some_role(role_ids).first
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
user.auth_user = logged_user
|
55
|
-
user
|
56
|
-
else
|
57
|
-
nil
|
58
|
-
end
|
56
|
+
def find_external_with_all_roles(role_ids)
|
57
|
+
all_external_with_all_roles(role_ids).first
|
59
58
|
end
|
60
59
|
|
61
|
-
def
|
62
|
-
|
63
|
-
@destination_url
|
64
|
-
else
|
65
|
-
AuthLh::Api.login_url(return_url)
|
66
|
-
end
|
60
|
+
def with_role(role_id)
|
61
|
+
all.to_a.find_all { |x| x.has_role?(role_id) }
|
67
62
|
end
|
68
63
|
|
69
|
-
def
|
70
|
-
|
64
|
+
def with_some_role(role_ids)
|
65
|
+
all.to_a.find_all { |x| x.has_some_role?(role_ids) }
|
71
66
|
end
|
72
67
|
|
73
|
-
def
|
74
|
-
|
68
|
+
def with_all_roles(role_ids)
|
69
|
+
all.to_a.find_all { |x| x.has_all_roles?(role_ids) }
|
75
70
|
end
|
76
71
|
|
77
|
-
def
|
78
|
-
|
72
|
+
def clear_cache!
|
73
|
+
@cached_users = nil
|
79
74
|
end
|
80
75
|
end
|
81
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth-lh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Hick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/auth/lh.rb
|
66
66
|
- lib/auth/lh/version.rb
|
67
67
|
- lib/auth_lh/api.rb
|
68
|
+
- lib/auth_lh/auth_management.rb
|
68
69
|
- lib/auth_lh/external_app.rb
|
69
70
|
- lib/auth_lh/role.rb
|
70
71
|
- lib/auth_lh/role_management.rb
|