auth-lh 0.3.2 → 0.4.0

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
  SHA1:
3
- metadata.gz: f9ccb8aa0e85dd54611331dedd7b7e51631add40
4
- data.tar.gz: bfd6376a74440673409e69ad4e7e0b9c78d8ef8f
3
+ metadata.gz: 20c4858e61f37e391405761067381bba5eae7def
4
+ data.tar.gz: 15a5c9964e58316cd4a9721583163506e92661a4
5
5
  SHA512:
6
- metadata.gz: f69a13bc0709097f39c175fb940969a020f1415479d604a98affdaab4eb75d51211be882bd58bf315085f52deb5eb3396515e8d6b6355f75b096bc1e6081f3e2
7
- data.tar.gz: 2847a52f616eae25bacecf4185a2323ee1e0fb7b7edc59cd96c50155db1faea7aae34d5b904a37eb92751fb09fa88eb87c022386ef17ae9329a1309e7cb75f18
6
+ metadata.gz: ae4ebd327dee06bbc6fac8afd7cf22ab97d18a26ffe24b22dfa1b78248f8832a3033e673117ce787b70ab463caef0922a64363e2f39edb1c74f575d454a5265f
7
+ data.tar.gz: 903842eb9ac63dc87c15a82d1887ffb46943a58d7e9644aba403a8b70e5d4eb8e6e9a61f2d296f384d69f88e010eda8391bd18214da5a494f04cfe61e604f33f
data/CHANGELOG.md CHANGED
@@ -85,3 +85,7 @@
85
85
  ## v0.3.2
86
86
 
87
87
  * Added new fields to entities
88
+
89
+ ## v0.4.0
90
+
91
+ * Improved auth interface
@@ -1,5 +1,5 @@
1
1
  module Auth
2
2
  module Lh
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/auth/lh.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'auth_lh'
2
2
  require 'auth_lh/authentication'
3
3
  require 'auth_lh/external_app'
4
- require 'auth_lh/login_attempt'
5
4
  require 'auth_lh/role'
6
5
  require 'auth_lh/session_response'
7
6
  require 'auth_lh/user'
@@ -25,16 +25,11 @@ module AuthLh
25
25
  all_external.find { |x| x.login == login.to_s }
26
26
  end
27
27
 
28
- def find_current_user(session_token, remote_ip)
29
- response = AuthLh.get_current_user(session_token, remote_ip)
28
+ def find_current_user(session_token, remote_ip, return_url=nil)
29
+ response = AuthLh.get_current_user(session_token, remote_ip, return_url)
30
30
 
31
- if response.nil?
32
- logged_user = nil
33
- login_error = nil
34
- else
35
- logged_user = response.user
36
- login_error = response.reason
37
- end
31
+ logged_user = response.user
32
+ @login_url = response.login_url
38
33
 
39
34
  if logged_user
40
35
  user = find_or_create_by(login: logged_user.login)
@@ -45,20 +40,20 @@ module AuthLh
45
40
  end
46
41
  end
47
42
 
48
- def login_url
49
- if @login_error
50
- "#{AuthLh.login_url}&reason=#{@login_error}"
51
- else
52
- AuthLh.login_url
53
- end
43
+ def login_url(return_url=nil)
44
+ AuthLh.login_url(return_url)
45
+ end
46
+
47
+ def logout_url(return_url=nil)
48
+ AuthLh.logout_url(return_url)
54
49
  end
55
50
 
56
- def logout_url
57
- AuthLh.logout_url
51
+ def change_password_url(return_url=nil)
52
+ AuthLh.change_password_url(return_url)
58
53
  end
59
54
 
60
- def change_password_url
61
- AuthLh.change_password_url
55
+ def my_apps_url
56
+ AuthLh.my_apps_url
62
57
  end
63
58
  end
64
59
  end
@@ -1,6 +1,6 @@
1
1
  module AuthLh
2
2
  class SessionResponse
3
- attr_accessor :user, :success, :reason
3
+ attr_accessor :user, :login_url
4
4
 
5
5
  def initialize(attributes={})
6
6
  attributes.each do |k,v|
data/lib/auth_lh.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module AuthLh
2
2
  def self.configure(args={})
3
- @endpoint = (args[:endpoint] || 'https://auth.lhconfort.com.ar')
4
- @return_url = args[:return_url]
3
+ @endpoint = (args[:endpoint] || 'https://usuarios.lhconfort.com.ar')
5
4
  @application_code = args[:application_code]
6
5
  @access_token = args[:access_token]
7
6
  end
@@ -20,16 +19,6 @@ module AuthLh
20
19
  results.map { |r| UserExtended.new(r) }
21
20
  end
22
21
 
23
- def self.get_current_user(session_token, remote_ip)
24
- result = get_request '/api/current_user', {
25
- app_code: @application_code,
26
- session_token: session_token,
27
- remote_ip: remote_ip
28
- }
29
-
30
- SessionResponse.new(result)
31
- end
32
-
33
22
  def self.get_external_apps
34
23
  results = get_request('/api/external_apps')
35
24
  results.map { |r| ExternalApp.new(r) }
@@ -44,41 +33,57 @@ module AuthLh
44
33
  Role.new(get_request("/api/roles/#{code}"))
45
34
  end
46
35
 
47
- def self.login_url
48
- login_attempt = create_login_attempt
49
- "#{@endpoint}/login?attempt=#{login_attempt.token}"
36
+ def self.get_current_user(session_token, remote_ip, return_url=nil)
37
+ result = get_request '/api/current_user', {
38
+ app_code: @application_code,
39
+ session_token: session_token,
40
+ remote_ip: remote_ip,
41
+ return_url: return_url
42
+ }
43
+
44
+ SessionResponse.new(result)
50
45
  end
51
46
 
52
- def self.logout_url
53
- "#{@endpoint}/logout?return_url=#{CGI::escape(@return_url)}"
47
+ def self.get_current_shop(ip_address=nil)
48
+ attrs = { ip: ip_address }
49
+ get_request('/api/whatsmyshop', attrs)['shop_codes']
54
50
  end
55
51
 
56
- def self.change_password_url
57
- "#{@endpoint}/change_password?return_url=#{CGI::escape(@return_url)}"
52
+ def self.login_url(return_url=nil)
53
+ if return_url.present?
54
+ "#{@endpoint}/login?return_url=#{CGI::escape(return_url)}"
55
+ else
56
+ "#{@endpoint}/login"
57
+ end
58
58
  end
59
59
 
60
- def self.whatsmyshop(ip_address=nil)
61
- attrs = { ip: ip_address }
62
- get_request('/api/whatsmyshop', attrs)['shop_codes']
60
+ def self.logout_url(return_url=nil)
61
+ if return_url.present?
62
+ "#{@endpoint}/logout?return_url=#{CGI::escape(return_url)}"
63
+ else
64
+ "#{@endpoint}/logout"
65
+ end
63
66
  end
64
67
 
65
- protected
68
+ def self.change_password_url(return_url=nil)
69
+ if return_url.present?
70
+ "#{@endpoint}/change_password?return_url=#{CGI::escape(return_url)}"
71
+ else
72
+ "#{@endpoint}/change_password"
73
+ end
74
+ end
66
75
 
67
- def self.create_login_attempt
68
- LoginAttempt.new(post_request('/api/login_attempts', {
69
- return_url: @return_url
70
- }))
76
+ def self.my_apps_url
77
+ "#{@endpoint}"
71
78
  end
72
79
 
80
+ protected
81
+
73
82
  def self.get_request(action, params={})
74
83
  response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
75
84
  JSON.parse(response.body)
76
85
  end
77
86
 
78
- def self.post_request(action, params={})
79
- JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
80
- end
81
-
82
87
  def self.auth_headers
83
88
  { authorization: "Token token=\"#{@access_token}\"" }
84
89
  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: 0.3.2
4
+ version: 0.4.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: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,6 @@ files:
66
66
  - lib/auth/lh.rb
67
67
  - lib/auth_lh/authentication.rb
68
68
  - lib/auth_lh/external_app.rb
69
- - lib/auth_lh/login_attempt.rb
70
69
  - lib/auth_lh/role.rb
71
70
  - lib/auth_lh/session_response.rb
72
71
  - lib/auth_lh/user.rb
@@ -1,11 +0,0 @@
1
- module AuthLh
2
- class LoginAttempt
3
- attr_accessor :token
4
-
5
- def initialize(attributes={})
6
- attributes.each do |k,v|
7
- self.send("#{k}=", v)
8
- end
9
- end
10
- end
11
- end