onelogin 1.2.3 → 1.3.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: 35fa6e59d712be2d32a0f0226cb26748c38c5aef
4
- data.tar.gz: 4bf1cd249892f17c680acc337ea57168582d9e90
3
+ metadata.gz: 7fca4bd8901e5234c12acd2fcbf85179634aeb25
4
+ data.tar.gz: 8b7e7cb38fac5a432812cd12705c55e4539f4fac
5
5
  SHA512:
6
- metadata.gz: edf073e14e440e6939e24088ca13876fa2724a9a7a4c277ed7c5d731ab913285a238beac455010fe7afeb8b7570b748d677e1db8ac74cb77d23ba3a213933025
7
- data.tar.gz: d63150971c087549b2cd679c527475fcbb9e47c7b5b845da299d79afef349e44c4f5caaee7f01a2de0973488fd41ff89f8249c9c56fcc1759ce74e1bdf80e65c
6
+ metadata.gz: 671935da852605381ade21ea1ee8dffb13f788a6ee50af30842a7e4edc5edba97b30a112280f69a9ec817c73b20f6e65eec189e95cc1b3c23c47a9d86a25bc3c
7
+ data.tar.gz: bc7473a57abbbcb9fd20637c589d32f57e27f29089dd1af4e9d641193c019c14267c331ea6aad91c8a1d0368029a9eebfd0c84928d5d177bc5ae39f400a2b1c7
data/README.md CHANGED
@@ -41,6 +41,7 @@ If you don't have an account you can [sign up for a free developer account here]
41
41
  |client_secret|Required: A valid OneLogin API client_secret|
42
42
  |region| Optional: `us` or `eu`. Defaults to `us` |
43
43
  |max_results| Optional: Defaults to 1000 |
44
+ |timeout| Optional: Defaults to 60 (requires httparty > 0.16.2) |
44
45
 
45
46
  ```ruby
46
47
  require 'onelogin'
@@ -12,7 +12,8 @@ require 'onelogin'
12
12
  client = OneLogin::Api::Client.new(
13
13
  client_id: 'ONELOGIN_CLIENT_ID',
14
14
  client_secret:'ONELOGIN_CLIENT_SECRET',
15
- region: 'us'
15
+ region: 'us',
16
+ max_results: 50000
16
17
  )
17
18
 
18
19
  attribute_names = ['id', 'external_id', 'email', 'username', 'firstname', 'lastname', 'distinguished_name',
@@ -34,7 +34,8 @@ end.parse!
34
34
  client = OneLogin::Api::Client.new(
35
35
  client_id: 'ONELOGIN_CLIENT_ID_GOES_HERE',
36
36
  client_secret: 'ONELOGIN_CLIENT_SECRET_GOES_HERE',
37
- region: 'us'
37
+ region: 'us',
38
+ max_results: 50000
38
39
  )
39
40
 
40
41
  counter = 0
@@ -0,0 +1,10 @@
1
+ module OneLogin
2
+ module Api
3
+ class ApiException < Exception
4
+ def initialize(message, code)
5
+ super(message)
6
+ @code = code
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,7 @@
1
1
  require 'onelogin/version'
2
- require 'onelogin/api/util'
2
+ require 'onelogin/api/apiexception'
3
3
  require 'onelogin/api/cursor'
4
+ require 'onelogin/api/util'
4
5
  require 'json'
5
6
  require 'httparty'
6
7
  require 'nokogiri'
@@ -38,6 +39,10 @@ module OneLogin
38
39
  @region = options[:region] || 'us'
39
40
  @max_results = options[:max_results] || 1000
40
41
 
42
+ if options[:timeout] and defined? self.class.default_timeout
43
+ self.class.default_timeout options[:timeout]
44
+ end
45
+
41
46
  if options[:proxy_host]
42
47
  self.class.http_proxy options[:proxy_host], options[:proxy_port], options[:proxy_user], options[:proxy_pass]
43
48
  end
@@ -59,40 +64,6 @@ module OneLogin
59
64
  @error_attribute = nil
60
65
  end
61
66
 
62
- def extract_error_message_from_response(response)
63
- message = ''
64
- content = JSON.parse(response.body)
65
- if content && content.has_key?('status')
66
- status = content['status']
67
- if status.has_key?('message')
68
- if status['message'].instance_of?(Hash)
69
- if status['message'].has_key?('description')
70
- message = status['message']['description']
71
- end
72
- else
73
- message = status['message']
74
- end
75
- elsif status.has_key?('type')
76
- message = status['type']
77
- end
78
- end
79
- message
80
- end
81
-
82
- def extract_error_attribute_from_response(response)
83
- attribute = nil
84
- content = JSON.parse(response.body)
85
- if content && content.has_key?('status')
86
- status = content['status']
87
- if status.has_key?('message') && status['message'].instance_of?(Hash)
88
- if status['message'].has_key?('attribute')
89
- attribute = status['message']['attribute']
90
- end
91
- end
92
- end
93
- attribute
94
- end
95
-
96
67
  def expired?
97
68
  Time.now.utc > @expiration
98
69
  end
@@ -202,11 +173,16 @@ module OneLogin
202
173
 
203
174
  if response.code == 200
204
175
  json_data = JSON.parse(response.body)
205
- token = OneLogin::Api::Models::OneLoginToken.new(json_data)
206
- @access_token = token.access_token
207
- @refresh_token = token.refresh_token
208
- @expiration = token.created_at + token.expires_in
209
- return token
176
+ if json_data.has_key?('status')
177
+ @error = json_data['status']['code'].to_s
178
+ @error_description = extract_error_message_from_response(response)
179
+ else
180
+ token = OneLogin::Api::Models::OneLoginToken.new(json_data)
181
+ @access_token = token.access_token
182
+ @refresh_token = token.refresh_token
183
+ @expiration = token.created_at + token.expires_in
184
+ return token
185
+ end
210
186
  else
211
187
  @error = response.code.to_s
212
188
  @error_description = extract_error_message_from_response(response)
@@ -244,11 +220,16 @@ module OneLogin
244
220
 
245
221
  if response.code == 200
246
222
  json_data = JSON.parse(response.body)
247
- token = OneLogin::Api::Models::OneLoginToken.new(json_data)
248
- @access_token = token.access_token
249
- @refresh_token = token.refresh_token
250
- @expiration = token.created_at + token.expires_in
251
- return token
223
+ if json_data.has_key?('status')
224
+ @error = json_data['status']['code'].to_s
225
+ @error_description = extract_error_message_from_response(response)
226
+ else
227
+ token = OneLogin::Api::Models::OneLoginToken.new(json_data)
228
+ @access_token = token.access_token
229
+ @refresh_token = token.refresh_token
230
+ @expiration = token.created_at + token.expires_in
231
+ return token
232
+ end
252
233
  else
253
234
  @error = response.code.to_s
254
235
  @error_description = extract_error_message_from_response(response)
@@ -1140,13 +1121,13 @@ module OneLogin
1140
1121
  prepare_token
1141
1122
 
1142
1123
  begin
1143
- options = {
1144
- model: OneLogin::Api::Models::EventType,
1145
- headers: authorized_headers,
1146
- max_results: @max_results
1147
- }
1124
+ options = {
1125
+ model: OneLogin::Api::Models::EventType,
1126
+ headers: authorized_headers,
1127
+ max_results: @max_results
1128
+ }
1148
1129
 
1149
- return Cursor.new(self.class, url_for(GET_EVENT_TYPES_URL), options)
1130
+ return Cursor.new(self.class, url_for(GET_EVENT_TYPES_URL), options)
1150
1131
 
1151
1132
  rescue Exception => e
1152
1133
  @error = '500'
@@ -1168,14 +1149,14 @@ module OneLogin
1168
1149
  prepare_token
1169
1150
 
1170
1151
  begin
1171
- options = {
1172
- model: OneLogin::Api::Models::Event,
1173
- headers: authorized_headers,
1174
- max_results: @max_results,
1175
- params: params
1176
- }
1152
+ options = {
1153
+ model: OneLogin::Api::Models::Event,
1154
+ headers: authorized_headers,
1155
+ max_results: @max_results,
1156
+ params: params
1157
+ }
1177
1158
 
1178
- return Cursor.new(self.class, url_for(GET_EVENTS_URL), options)
1159
+ return Cursor.new(self.class, url_for(GET_EVENTS_URL), options)
1179
1160
 
1180
1161
  rescue Exception => e
1181
1162
  @error = '500'
@@ -1,3 +1,6 @@
1
+ require 'onelogin/api/apiexception'
2
+ require 'onelogin/api/util'
3
+
1
4
  # Cursor
2
5
  #
3
6
  # Used for paginating requests to the OneLogin API
@@ -5,6 +8,7 @@
5
8
  # Returns an enumerable object
6
9
  class Cursor
7
10
  include Enumerable
11
+ include OneLogin::Api::Util
8
12
 
9
13
  # Create a new instance of the Cursor.
10
14
  #
@@ -58,16 +62,22 @@ class Cursor
58
62
 
59
63
  json = response.parsed_response
60
64
 
61
- results = json['data'].flatten
62
-
63
- @collection += if results_remaining < results.size
64
- results.slice(0, results_remaining)
65
+ if json.nil?
66
+ raise OneLogin::Api::ApiException.new("Response could not be parsed", 500)
67
+ elsif !json.key?("data") && json["status"]["error"] == true
68
+ raise OneLogin::Api::ApiException.new(extract_error_message_from_response(response), json["status"]["code"])
65
69
  else
66
- results
67
- end
70
+ results = json['data'].flatten
68
71
 
69
- @after_cursor = after_cursor(json)
70
- @last_cursor_empty = @after_cursor.nil?
72
+ @collection += if results_remaining < results.size
73
+ results.slice(0, results_remaining)
74
+ else
75
+ results
76
+ end
77
+
78
+ @after_cursor = after_cursor(json)
79
+ @last_cursor_empty = @after_cursor.nil?
80
+ end
71
81
  end
72
82
 
73
83
  def after_cursor(json)
@@ -7,7 +7,7 @@ module OneLogin
7
7
  attr_accessor :id, :external_id, :email, :username, :firstname, :lastname, :distinguished_name,
8
8
  :phone, :company, :department, :status, :state, :member_of, :samaccountname, :userprincipalname,
9
9
  :group_id, :role_ids, :custom_attributes, :openid_name, :locale_code, :comment, :directory_id,
10
- :title, :manager_ad_id, :trusted_idp_id, :activated_at, :created_at, :updated_at,
10
+ :title, :manager_ad_id, :trusted_idp_id, :manager_user_id, :activated_at, :created_at, :updated_at,
11
11
  :password_changed_at, :invitation_sent_at, :invalid_login_attempts, :last_login, :locked_until
12
12
 
13
13
  def initialize(data)
@@ -36,6 +36,7 @@ module OneLogin
36
36
  @directory_id = data['directory_id']
37
37
  @manager_ad_id = data['manager_ad_id']
38
38
  @trusted_idp_id = data['trusted_idp_id']
39
+ @manager_user_id = data['manager_user_id']
39
40
  @activated_at = data['activated_at']? Time.iso8601(data['activated_at']) : nil
40
41
  @created_at = data['created_at']? Time.iso8601(data['created_at']) : nil
41
42
  @updated_at = data['updated_at']? Time.iso8601(data['updated_at']) : nil
@@ -77,6 +78,7 @@ module OneLogin
77
78
  user_data.directory_id = @directory_id
78
79
  user_data.manager_ad_id = @manager_ad_id
79
80
  user_data.trusted_idp_id = @trusted_idp_id
81
+ user_data.manager_user_id = @manager_user_id
80
82
  return user_data
81
83
  end
82
84
 
@@ -123,7 +125,8 @@ module OneLogin
123
125
  "openid_name"=> self.openid_name,
124
126
  "directory_id"=> self.directory_id,
125
127
  "manager_ad_id"=> self.manager_ad_id,
126
- "trusted_idp_id"=> self.trusted_idp_id
128
+ "trusted_idp_id"=> self.trusted_idp_id,
129
+ "manager_user_id"=> self.manager_user_id
127
130
  }
128
131
  end
129
132
  end
@@ -6,7 +6,7 @@ module OneLogin
6
6
 
7
7
  attr_accessor :id, :external_id, :email, :username, :firstname, :lastname, :distinguished_name,
8
8
  :phone, :company, :department, :status, :state, :member_of, :samaccountname, :userprincipalname,
9
- :title, :openid_name, :locale_code, :directory_id, :manager_ad_id, :trusted_idp_id
9
+ :title, :openid_name, :locale_code, :directory_id, :manager_ad_id, :trusted_idp_id, :manager_user_id
10
10
  end
11
11
  end
12
12
  end
@@ -1,11 +1,13 @@
1
1
  require 'onelogin/api/util/constants'
2
2
  require 'onelogin/api/util/url_builder'
3
+ require 'onelogin/api/util/parser'
3
4
 
4
5
  module OneLogin
5
6
  module Api
6
7
  module Util
7
8
  include OneLogin::Api::Util::Constants
8
9
  include OneLogin::Api::Util::UrlBuilder
10
+ include OneLogin::Api::Util::Parser
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,42 @@
1
+ module OneLogin
2
+ module Api
3
+ module Util
4
+ module Parser
5
+ def extract_error_message_from_response(response)
6
+ message = ''
7
+ content = JSON.parse(response.body)
8
+ if content && content.has_key?('status')
9
+ status = content['status']
10
+ if status.has_key?('message')
11
+ if status['message'].instance_of?(Hash)
12
+ if status['message'].has_key?('description')
13
+ message = status['message']['description']
14
+ end
15
+ else
16
+ message = status['message']
17
+ end
18
+ elsif status.has_key?('type')
19
+ message = status['type']
20
+ end
21
+ end
22
+ message
23
+ end
24
+
25
+ def extract_error_attribute_from_response(response)
26
+ attribute = nil
27
+ content = JSON.parse(response.body)
28
+ if content && content.has_key?('status')
29
+ status = content['status']
30
+ if status.has_key?('message') && status['message'].instance_of?(Hash)
31
+ if status['message'].has_key?('attribute')
32
+ attribute = status['message']['attribute']
33
+ end
34
+ end
35
+ end
36
+ attribute
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module OneLogin
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onelogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneLogin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -213,6 +213,7 @@ files:
213
213
  - examples/rails-custom-login-page/vendor/.keep
214
214
  - lib/onelogin.rb
215
215
  - lib/onelogin/api.rb
216
+ - lib/onelogin/api/apiexception.rb
216
217
  - lib/onelogin/api/client.rb
217
218
  - lib/onelogin/api/cursor.rb
218
219
  - lib/onelogin/api/models.rb
@@ -237,6 +238,7 @@ files:
237
238
  - lib/onelogin/api/models/user_metadata.rb
238
239
  - lib/onelogin/api/util.rb
239
240
  - lib/onelogin/api/util/constants.rb
241
+ - lib/onelogin/api/util/parser.rb
240
242
  - lib/onelogin/api/util/url_builder.rb
241
243
  - lib/onelogin/version.rb
242
244
  - onelogin.gemspec
@@ -261,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
263
  version: '0'
262
264
  requirements: []
263
265
  rubyforge_project: http://www.rubygems.org/gems/onelogin-ruby-sdk
264
- rubygems_version: 2.2.2
266
+ rubygems_version: 2.4.8
265
267
  signing_key:
266
268
  specification_version: 4
267
269
  summary: OneLogin's Ruby SDK.