auth-lh 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/auth/lh.rb +1 -1
- data/lib/auth/lh/version.rb +1 -1
- data/lib/auth_lh.rb +61 -0
- metadata +2 -2
- data/lib/auth_lh/api.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea7a9dc6ed58444c7872e2aee7893aefb47a8c4d
|
4
|
+
data.tar.gz: 0b933e0716c002029937f28811c02851d50be865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e039f9a052cc0c055cc47eb6cd633aaf79ca2694d131f606c66d10936eab6ca4c2c88a4fa88244c8412c04e7584477430d6980e55d74327d91d07067f083f2cd
|
7
|
+
data.tar.gz: 640e349c9477bc2561bd964caabcef37927ac6d70d400693991b8380978d978a3476e6fdfbb61f5d11353fcf5a15aa2b851fb62bdd65951852e1cd6dbb4d4f34
|
data/CHANGELOG.md
CHANGED
data/lib/auth/lh.rb
CHANGED
data/lib/auth/lh/version.rb
CHANGED
data/lib/auth_lh.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module AuthLh
|
2
|
+
def self.configure(args={})
|
3
|
+
@endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
|
4
|
+
@return_url = args[:return_url]
|
5
|
+
@application_code = args[:application_code]
|
6
|
+
@access_token = args[:access_token]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.logged_user(session_token, remote_ip)
|
10
|
+
result = get_request '/logged_user', {
|
11
|
+
app_code: @application_code,
|
12
|
+
session_token: session_token,
|
13
|
+
remote_ip: remote_ip
|
14
|
+
}
|
15
|
+
|
16
|
+
SessionResponse.new(result)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.login_url
|
20
|
+
login_attempt = create_login_attempt
|
21
|
+
"#{@endpoint}/login?attempt=#{login_attempt.token}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.logout_url
|
25
|
+
"#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_user(code_or_login)
|
29
|
+
User.new(get_request("/api/users/#{code_or_login}"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_users(filters={})
|
33
|
+
results = get_request("/api/users", filters)
|
34
|
+
results.map { |r| User.new(r) }
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def self.create_login_attempt
|
40
|
+
params = { app_code: @application_code }
|
41
|
+
|
42
|
+
if @return_url
|
43
|
+
params[:return_url] = @return_url
|
44
|
+
end
|
45
|
+
|
46
|
+
LoginAttempt.new(post_request('/login_attempts', params))
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_request(action, params={})
|
50
|
+
response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
|
51
|
+
JSON.parse(response.body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.post_request(action, params={})
|
55
|
+
JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.auth_headers
|
59
|
+
{ authorization: "Token token=\"#{@access_token}\"" }
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth-lh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Hick
|
@@ -64,10 +64,10 @@ files:
|
|
64
64
|
- CHANGELOG.md
|
65
65
|
- lib/auth/lh/version.rb
|
66
66
|
- lib/auth/lh.rb
|
67
|
-
- lib/auth_lh/api.rb
|
68
67
|
- lib/auth_lh/login_attempt.rb
|
69
68
|
- lib/auth_lh/session_response.rb
|
70
69
|
- lib/auth_lh/user.rb
|
70
|
+
- lib/auth_lh.rb
|
71
71
|
homepage: https://github.com/unformattmh/auth-lh
|
72
72
|
licenses:
|
73
73
|
- MIT
|
data/lib/auth_lh/api.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module AuthLh
|
2
|
-
class Api
|
3
|
-
def self.configure(args={})
|
4
|
-
@endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
|
5
|
-
@return_url = args[:return_url]
|
6
|
-
@application_code = args[:application_code]
|
7
|
-
@access_token = args[:access_token]
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.logged_user(session_token, remote_ip)
|
11
|
-
result = get_request '/logged_user', {
|
12
|
-
app_code: @application_code,
|
13
|
-
session_token: session_token,
|
14
|
-
remote_ip: remote_ip
|
15
|
-
}
|
16
|
-
|
17
|
-
SessionResponse.new(result)
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.login_url
|
21
|
-
login_attempt = create_login_attempt
|
22
|
-
"#{@endpoint}/login?attempt=#{login_attempt.token}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.logout_url
|
26
|
-
"#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.get_user(code_or_login)
|
30
|
-
User.new(get_request("/api/users/#{code_or_login}"))
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.get_users(filters={})
|
34
|
-
results = get_request("/api/users", filters)
|
35
|
-
results.map { |r| User.new(r) }
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def self.create_login_attempt
|
41
|
-
params = { app_code: @application_code }
|
42
|
-
|
43
|
-
if @return_url
|
44
|
-
params[:return_url] = @return_url
|
45
|
-
end
|
46
|
-
|
47
|
-
LoginAttempt.new(post_request('/login_attempts', params))
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.get_request(action, params={})
|
51
|
-
response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
|
52
|
-
JSON.parse(response.body)
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.post_request(action, params={})
|
56
|
-
JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.auth_headers
|
60
|
-
{ authorization: "Token token=\"#{@access_token}\"" }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|