onelogin 1.3.1 → 1.6.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/.github/workflows/git-secrets-public.yml +55 -0
- data/README.md +64 -0
- data/examples/Gemfile.lock +10 -6
- data/examples/another-get-all-login-events-of-last-day-to-csv.rb +141 -0
- data/examples/events-to-csv.rb +3 -3
- data/examples/get-all-login-events-of-last-day-to-csv.rb +88 -0
- data/examples/rails-custom-login-page/Gemfile +2 -2
- data/examples/rails-custom-login-page/Gemfile.lock +20 -16
- data/examples/rails-custom-login-page/README.md +35 -2
- data/examples/rails-custom-login-page/app/assets/stylesheets/application.css +1 -61
- data/examples/rails-custom-login-page/app/controllers/home_controller.rb +1 -0
- data/examples/rails-custom-login-page/app/controllers/sessions_controller.rb +4 -4
- data/examples/rails-custom-login-page/app/controllers/users_controller.rb +48 -14
- data/examples/rails-custom-login-page/app/helpers/sessions_helper.rb +1 -1
- data/examples/rails-custom-login-page/app/helpers/users_helper.rb +1 -0
- data/examples/rails-custom-login-page/app/views/dashboard/index.html.erb +2 -9
- data/examples/rails-custom-login-page/app/views/home/index.html.erb +84 -18
- data/examples/rails-custom-login-page/app/views/layouts/application.html.erb +13 -1
- data/examples/rails-custom-login-page/app/views/users/edit.html.erb +30 -24
- data/examples/rails-custom-login-page/app/views/users/index.html.erb +30 -27
- data/examples/rails-custom-login-page/app/views/users/new.html.erb +58 -3
- data/examples/rails-custom-login-page/app/views/users/onboard.html.erb +54 -0
- data/examples/rails-custom-login-page/app/views/users/show.html.erb +16 -13
- data/examples/rails-custom-login-page/config/initializers/onelogin.rb +3 -1
- data/examples/rails-custom-login-page/config/routes.rb +4 -0
- data/examples/rails-custom-login-page/config/secrets.yml.sample +2 -0
- data/lib/onelogin/api/client.rb +682 -10
- data/lib/onelogin/api/cursor.rb +4 -3
- data/lib/onelogin/api/models/connector_basic.rb +20 -0
- data/lib/onelogin/api/models/event.rb +6 -1
- data/lib/onelogin/api/models/event_type.rb +2 -2
- data/lib/onelogin/api/models/mfa_token.rb +18 -0
- data/lib/onelogin/api/models/onelogin_app.rb +62 -0
- data/lib/onelogin/api/models/onelogin_app_basic.rb +51 -0
- data/lib/onelogin/api/models/onelogin_app_v1.rb +22 -0
- data/lib/onelogin/api/models/user.rb +1 -1
- data/lib/onelogin/api/models.rb +5 -0
- data/lib/onelogin/api/util/constants.rb +18 -0
- data/lib/onelogin/version.rb +1 -1
- data/onelogin.gemspec +2 -2
- metadata +16 -7
data/lib/onelogin/api/client.rb
CHANGED
@@ -47,6 +47,8 @@ module OneLogin
|
|
47
47
|
self.class.http_proxy options[:proxy_host], options[:proxy_port], options[:proxy_user], options[:proxy_pass]
|
48
48
|
end
|
49
49
|
|
50
|
+
self.class.default_options.update(verify: false)
|
51
|
+
|
50
52
|
validate_config
|
51
53
|
|
52
54
|
@user_agent = DEFAULT_USER_AGENT
|
@@ -342,7 +344,7 @@ module OneLogin
|
|
342
344
|
params: params
|
343
345
|
}
|
344
346
|
|
345
|
-
return Cursor.new(self
|
347
|
+
return Cursor.new(self, url_for(GET_USERS_URL), options)
|
346
348
|
|
347
349
|
rescue Exception => e
|
348
350
|
@error = '500'
|
@@ -364,6 +366,12 @@ module OneLogin
|
|
364
366
|
prepare_token
|
365
367
|
|
366
368
|
begin
|
369
|
+
if user_id.nil? || user_id.to_s.empty?
|
370
|
+
@error = '400'
|
371
|
+
@error_description = "user_id is required"
|
372
|
+
@error_attribute = "user_id"
|
373
|
+
return
|
374
|
+
end
|
367
375
|
|
368
376
|
url = url_for(GET_USER_URL, user_id)
|
369
377
|
|
@@ -401,13 +409,20 @@ module OneLogin
|
|
401
409
|
prepare_token
|
402
410
|
|
403
411
|
begin
|
412
|
+
if user_id.nil? || user_id.to_s.empty?
|
413
|
+
@error = '400'
|
414
|
+
@error_description = "user_id is required"
|
415
|
+
@error_attribute = "user_id"
|
416
|
+
return
|
417
|
+
end
|
418
|
+
|
404
419
|
options = {
|
405
420
|
model: OneLogin::Api::Models::App,
|
406
421
|
headers: authorized_headers,
|
407
422
|
max_results: @max_results
|
408
423
|
}
|
409
424
|
|
410
|
-
return Cursor.new(self
|
425
|
+
return Cursor.new(self, url_for(GET_APPS_FOR_USER_URL, user_id), options)
|
411
426
|
|
412
427
|
rescue Exception => e
|
413
428
|
@error = '500'
|
@@ -429,6 +444,13 @@ module OneLogin
|
|
429
444
|
prepare_token
|
430
445
|
|
431
446
|
begin
|
447
|
+
if user_id.nil? || user_id.to_s.empty?
|
448
|
+
@error = '400'
|
449
|
+
@error_description = "user_id is required"
|
450
|
+
@error_attribute = "user_id"
|
451
|
+
return
|
452
|
+
end
|
453
|
+
|
432
454
|
url = url_for(GET_ROLES_FOR_USER_URL, user_id)
|
433
455
|
|
434
456
|
response = self.class.get(
|
@@ -552,6 +574,13 @@ module OneLogin
|
|
552
574
|
prepare_token
|
553
575
|
|
554
576
|
begin
|
577
|
+
if user_id.nil? || user_id.to_s.empty?
|
578
|
+
@error = '400'
|
579
|
+
@error_description = "user_id is required"
|
580
|
+
@error_attribute = "user_id"
|
581
|
+
return
|
582
|
+
end
|
583
|
+
|
555
584
|
url = url_for(UPDATE_USER_URL, user_id)
|
556
585
|
|
557
586
|
response = self.class.put(
|
@@ -591,6 +620,13 @@ module OneLogin
|
|
591
620
|
prepare_token
|
592
621
|
|
593
622
|
begin
|
623
|
+
if user_id.nil? || user_id.to_s.empty?
|
624
|
+
@error = '400'
|
625
|
+
@error_description = "user_id is required"
|
626
|
+
@error_attribute = "user_id"
|
627
|
+
return
|
628
|
+
end
|
629
|
+
|
594
630
|
url = url_for(ADD_ROLE_TO_USER_URL, user_id)
|
595
631
|
|
596
632
|
data = {
|
@@ -631,6 +667,13 @@ module OneLogin
|
|
631
667
|
prepare_token
|
632
668
|
|
633
669
|
begin
|
670
|
+
if user_id.nil? || user_id.to_s.empty?
|
671
|
+
@error = '400'
|
672
|
+
@error_description = "user_id is required"
|
673
|
+
@error_attribute = "user_id"
|
674
|
+
return
|
675
|
+
end
|
676
|
+
|
634
677
|
url = url_for(DELETE_ROLE_TO_USER_URL, user_id)
|
635
678
|
|
636
679
|
data = {
|
@@ -673,6 +716,13 @@ module OneLogin
|
|
673
716
|
prepare_token
|
674
717
|
|
675
718
|
begin
|
719
|
+
if user_id.nil? || user_id.to_s.empty?
|
720
|
+
@error = '400'
|
721
|
+
@error_description = "user_id is required"
|
722
|
+
@error_attribute = "user_id"
|
723
|
+
return
|
724
|
+
end
|
725
|
+
|
676
726
|
url = url_for(SET_PW_CLEARTEXT, user_id)
|
677
727
|
|
678
728
|
data = {
|
@@ -718,6 +768,13 @@ module OneLogin
|
|
718
768
|
prepare_token
|
719
769
|
|
720
770
|
begin
|
771
|
+
if user_id.nil? || user_id.to_s.empty?
|
772
|
+
@error = '400'
|
773
|
+
@error_description = "user_id is required"
|
774
|
+
@error_attribute = "user_id"
|
775
|
+
return
|
776
|
+
end
|
777
|
+
|
721
778
|
url = url_for(SET_PW_SALT, user_id)
|
722
779
|
|
723
780
|
data = {
|
@@ -764,6 +821,13 @@ module OneLogin
|
|
764
821
|
prepare_token
|
765
822
|
|
766
823
|
begin
|
824
|
+
if user_id.nil? || user_id.to_s.empty?
|
825
|
+
@error = '400'
|
826
|
+
@error_description = "user_id is required"
|
827
|
+
@error_attribute = "user_id"
|
828
|
+
return
|
829
|
+
end
|
830
|
+
|
767
831
|
url = url_for(SET_USER_STATE_URL, user_id)
|
768
832
|
|
769
833
|
data = {
|
@@ -804,6 +868,13 @@ module OneLogin
|
|
804
868
|
prepare_token
|
805
869
|
|
806
870
|
begin
|
871
|
+
if user_id.nil? || user_id.to_s.empty?
|
872
|
+
@error = '400'
|
873
|
+
@error_description = "user_id is required"
|
874
|
+
@error_attribute = "user_id"
|
875
|
+
return
|
876
|
+
end
|
877
|
+
|
807
878
|
url = url_for(SET_CUSTOM_ATTRIBUTE_TO_USER_URL, user_id)
|
808
879
|
|
809
880
|
data = {
|
@@ -843,6 +914,13 @@ module OneLogin
|
|
843
914
|
prepare_token
|
844
915
|
|
845
916
|
begin
|
917
|
+
if user_id.nil? || user_id.to_s.empty?
|
918
|
+
@error = '400'
|
919
|
+
@error_description = "user_id is required"
|
920
|
+
@error_attribute = "user_id"
|
921
|
+
return
|
922
|
+
end
|
923
|
+
|
846
924
|
url = url_for(LOG_USER_OUT_URL, user_id)
|
847
925
|
|
848
926
|
response = self.class.put(
|
@@ -880,6 +958,13 @@ module OneLogin
|
|
880
958
|
prepare_token
|
881
959
|
|
882
960
|
begin
|
961
|
+
if user_id.nil? || user_id.to_s.empty?
|
962
|
+
@error = '400'
|
963
|
+
@error_description = "user_id is required"
|
964
|
+
@error_attribute = "user_id"
|
965
|
+
return
|
966
|
+
end
|
967
|
+
|
883
968
|
url = url_for(LOCK_USER_URL, user_id)
|
884
969
|
|
885
970
|
data = {
|
@@ -919,6 +1004,13 @@ module OneLogin
|
|
919
1004
|
prepare_token
|
920
1005
|
|
921
1006
|
begin
|
1007
|
+
if user_id.nil? || user_id.to_s.empty?
|
1008
|
+
@error = '400'
|
1009
|
+
@error_description = "user_id is required"
|
1010
|
+
@error_attribute = "user_id"
|
1011
|
+
return
|
1012
|
+
end
|
1013
|
+
|
922
1014
|
url = url_for(DELETE_USER_URL, user_id)
|
923
1015
|
|
924
1016
|
response = self.class.delete(
|
@@ -941,6 +1033,59 @@ module OneLogin
|
|
941
1033
|
false
|
942
1034
|
end
|
943
1035
|
|
1036
|
+
# Use to generate a temporary MFA token that can be used in place of other MFA tokens for a set time period.
|
1037
|
+
# For example, use this token for account recovery.
|
1038
|
+
#
|
1039
|
+
# @param user_id [Integer] Id of the user
|
1040
|
+
# @param expires_in [Integer] Set the duration of the token in seconds.
|
1041
|
+
# (default: 259200 seconds = 72h) 72 hours is the max value.
|
1042
|
+
# @param reusable [Boolean] Defines if the token reusable. (default: false) If set to true, token can be used for multiple apps, until it expires.
|
1043
|
+
#
|
1044
|
+
# @return [MFAToken] if the action succeed
|
1045
|
+
#
|
1046
|
+
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/generate-mfa-token Generate MFA Token documentation}
|
1047
|
+
def generate_mfa_token(user_id, expires_in=259200, reusable=false)
|
1048
|
+
clean_error
|
1049
|
+
prepare_token
|
1050
|
+
|
1051
|
+
begin
|
1052
|
+
if user_id.nil? || user_id.to_s.empty?
|
1053
|
+
@error = '400'
|
1054
|
+
@error_description = "user_id is required"
|
1055
|
+
@error_attribute = "user_id"
|
1056
|
+
return
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
url = url_for(GENERATE_MFA_TOKEN_URL, user_id)
|
1060
|
+
|
1061
|
+
data = {
|
1062
|
+
'expires_in' => expires_in,
|
1063
|
+
'reusable' => reusable
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
response = self.class.post(
|
1067
|
+
url,
|
1068
|
+
headers: authorized_headers,
|
1069
|
+
body: data.to_json
|
1070
|
+
)
|
1071
|
+
|
1072
|
+
if response.code == 201
|
1073
|
+
json_data = JSON.parse(response.body)
|
1074
|
+
if !json_data.empty?
|
1075
|
+
return OneLogin::Api::Models::MFAToken.new(json_data)
|
1076
|
+
end
|
1077
|
+
else
|
1078
|
+
@error = extract_status_code_from_response(response)
|
1079
|
+
@error_description = extract_error_message_from_response(response)
|
1080
|
+
end
|
1081
|
+
rescue Exception => e
|
1082
|
+
@error = '500'
|
1083
|
+
@error_description = e.message
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
nil
|
1087
|
+
end
|
1088
|
+
|
944
1089
|
# Generates a session login token in scenarios in which MFA may or may not be required.
|
945
1090
|
# A session login token expires two minutes after creation.
|
946
1091
|
#
|
@@ -1005,6 +1150,13 @@ module OneLogin
|
|
1005
1150
|
prepare_token
|
1006
1151
|
|
1007
1152
|
begin
|
1153
|
+
if device_id.nil? || device_id.to_s.empty?
|
1154
|
+
@error = '400'
|
1155
|
+
@error_description = "device_id is required"
|
1156
|
+
@error_attribute = "device_id"
|
1157
|
+
return
|
1158
|
+
end
|
1159
|
+
|
1008
1160
|
url = url_for(GET_TOKEN_VERIFY_FACTOR)
|
1009
1161
|
|
1010
1162
|
data = {
|
@@ -1042,6 +1194,351 @@ module OneLogin
|
|
1042
1194
|
nil
|
1043
1195
|
end
|
1044
1196
|
|
1197
|
+
###############################
|
1198
|
+
# Onelogin Connectors Methods #
|
1199
|
+
###############################
|
1200
|
+
|
1201
|
+
# Gets a list of Connector resources.
|
1202
|
+
#
|
1203
|
+
# @param params [Hash] Parameters to filter the result of the list
|
1204
|
+
#
|
1205
|
+
# @return [Array] list of Connector objects
|
1206
|
+
#
|
1207
|
+
# @see {https://developers.onelogin.com/api-docs/1/connectors/list-connectors List Connectors documentation}
|
1208
|
+
def get_connectors(params = {})
|
1209
|
+
clean_error
|
1210
|
+
prepare_token
|
1211
|
+
|
1212
|
+
begin
|
1213
|
+
url = url_for(GET_CONNECTORS_URL)
|
1214
|
+
|
1215
|
+
connectors = []
|
1216
|
+
response = self.class.get(
|
1217
|
+
url,
|
1218
|
+
headers: authorized_headers,
|
1219
|
+
query: params
|
1220
|
+
)
|
1221
|
+
|
1222
|
+
if response.code == 200
|
1223
|
+
json_data = JSON.parse(response.body)
|
1224
|
+
if !json_data.empty?
|
1225
|
+
json_data.each do |data|
|
1226
|
+
pp data
|
1227
|
+
connectors << OneLogin::Api::Models::ConnectorBasic.new(data)
|
1228
|
+
end
|
1229
|
+
end
|
1230
|
+
return connectors
|
1231
|
+
else
|
1232
|
+
@error = extract_status_code_from_response(response)
|
1233
|
+
@error_description = extract_error_message_from_response(response)
|
1234
|
+
end
|
1235
|
+
rescue Exception => e
|
1236
|
+
@error = '500'
|
1237
|
+
@error_description = e.message
|
1238
|
+
end
|
1239
|
+
|
1240
|
+
nil
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
#########################
|
1244
|
+
# Onelogin Apps Methods #
|
1245
|
+
#########################
|
1246
|
+
|
1247
|
+
# Gets a list of OneLoginAppV1 resources. (if no limit provided, by default get 50 elements)
|
1248
|
+
#
|
1249
|
+
# @param params [Hash] Parameters to filter the result of the list
|
1250
|
+
#
|
1251
|
+
# @return [Array] list of OneLoginAppV1 objects
|
1252
|
+
#
|
1253
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/get-apps Get Apps documentation}
|
1254
|
+
def get_apps_v1(params = {})
|
1255
|
+
clean_error
|
1256
|
+
prepare_token
|
1257
|
+
|
1258
|
+
begin
|
1259
|
+
options = {
|
1260
|
+
model: OneLogin::Api::Models::OneLoginAppV1,
|
1261
|
+
headers: authorized_headers,
|
1262
|
+
max_results: @max_results,
|
1263
|
+
params: params
|
1264
|
+
}
|
1265
|
+
|
1266
|
+
return Cursor.new(self, url_for(GET_APPS_URL_V1), options)
|
1267
|
+
|
1268
|
+
rescue Exception => e
|
1269
|
+
@error = '500'
|
1270
|
+
@error_description = e.message
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
nil
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
# Gets a list of OneLoginAppBasic resources.
|
1277
|
+
#
|
1278
|
+
# @param params [Hash] Parameters to filter the result of the list
|
1279
|
+
#
|
1280
|
+
# @return [Array] list of OneLoginAppBasic objects
|
1281
|
+
#
|
1282
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/list-apps Get Apps documentation}
|
1283
|
+
def get_apps(params = {})
|
1284
|
+
clean_error
|
1285
|
+
prepare_token
|
1286
|
+
|
1287
|
+
begin
|
1288
|
+
url = url_for(GET_APPS_URL)
|
1289
|
+
|
1290
|
+
apps = []
|
1291
|
+
response = self.class.get(
|
1292
|
+
url,
|
1293
|
+
headers: authorized_headers,
|
1294
|
+
query: params
|
1295
|
+
)
|
1296
|
+
|
1297
|
+
if response.code == 200
|
1298
|
+
json_data = JSON.parse(response.body)
|
1299
|
+
if !json_data.empty?
|
1300
|
+
json_data.each do |data|
|
1301
|
+
apps << OneLogin::Api::Models::OneLoginAppBasic.new(data)
|
1302
|
+
end
|
1303
|
+
end
|
1304
|
+
return apps
|
1305
|
+
else
|
1306
|
+
@error = extract_status_code_from_response(response)
|
1307
|
+
@error_description = extract_error_message_from_response(response)
|
1308
|
+
end
|
1309
|
+
rescue Exception => e
|
1310
|
+
@error = '500'
|
1311
|
+
@error_description = e.message
|
1312
|
+
end
|
1313
|
+
|
1314
|
+
nil
|
1315
|
+
end
|
1316
|
+
|
1317
|
+
# Creates an app
|
1318
|
+
#
|
1319
|
+
# @param app_params [Hash] App data (name, visible, policy_id, is_available, parameters, allow_assumed_signin,
|
1320
|
+
# configuration, notes, description, provisioning,
|
1321
|
+
# connector_id, auth_method, tab_id)
|
1322
|
+
#
|
1323
|
+
# @return [OneLoginApp] the created app
|
1324
|
+
#
|
1325
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/create-app Create App documentation}
|
1326
|
+
def create_app(app_params)
|
1327
|
+
clean_error
|
1328
|
+
prepare_token
|
1329
|
+
|
1330
|
+
begin
|
1331
|
+
url = url_for(CREATE_APP_URL)
|
1332
|
+
|
1333
|
+
unless app_params.has_key?('connector_id') || app_params['connector_id'].to_s.empty?
|
1334
|
+
@error = '400'
|
1335
|
+
@error_description = "connector_id is required"
|
1336
|
+
@error_attribute = "connector_id"
|
1337
|
+
return
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
response = self.class.post(
|
1341
|
+
url,
|
1342
|
+
headers: authorized_headers,
|
1343
|
+
body: app_params.to_json
|
1344
|
+
)
|
1345
|
+
|
1346
|
+
if response.code == 201
|
1347
|
+
json_data = JSON.parse(response.body)
|
1348
|
+
if json_data && json_data.has_key?('id')
|
1349
|
+
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1350
|
+
end
|
1351
|
+
else
|
1352
|
+
@error = extract_status_code_from_response(response)
|
1353
|
+
@error_description = extract_error_message_from_response(response)
|
1354
|
+
@error_attribute = extract_error_attribute_from_response(response)
|
1355
|
+
end
|
1356
|
+
rescue Exception => e
|
1357
|
+
@error = '500'
|
1358
|
+
@error_description = e.message
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
nil
|
1362
|
+
end
|
1363
|
+
|
1364
|
+
# Gets a OneLoginApp resource.
|
1365
|
+
#
|
1366
|
+
# @return [OneLoginApp] OneLoginApp object
|
1367
|
+
#
|
1368
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/get-app Get App documentation}
|
1369
|
+
def get_app(app_id)
|
1370
|
+
clean_error
|
1371
|
+
prepare_token
|
1372
|
+
|
1373
|
+
begin
|
1374
|
+
if app_id.nil? || app_id.to_s.empty?
|
1375
|
+
@error = '400'
|
1376
|
+
@error_description = "app_id is required"
|
1377
|
+
@error_attribute = "app_id"
|
1378
|
+
return
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
url = url_for(GET_APP_URL, app_id)
|
1382
|
+
|
1383
|
+
response = self.class.get(
|
1384
|
+
url,
|
1385
|
+
headers: authorized_headers
|
1386
|
+
)
|
1387
|
+
|
1388
|
+
if response.code == 200
|
1389
|
+
json_data = JSON.parse(response.body)
|
1390
|
+
if json_data && json_data.has_key?('id')
|
1391
|
+
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1392
|
+
end
|
1393
|
+
else
|
1394
|
+
@error = extract_status_code_from_response(response)
|
1395
|
+
@error_description = extract_error_message_from_response(response)
|
1396
|
+
end
|
1397
|
+
rescue Exception => e
|
1398
|
+
@error = '500'
|
1399
|
+
@error_description = e.message
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
nil
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
# Updates an app
|
1406
|
+
#
|
1407
|
+
# @param app_id [Integer] Id of the app
|
1408
|
+
# @param app_params [Hash] App data (name, visible, policy_id, is_available, parameters, allow_assumed_signin,
|
1409
|
+
# configuration, notes, description, provisioning,
|
1410
|
+
# connector_id, auth_method, tab_id)
|
1411
|
+
#
|
1412
|
+
# @return [User] the modified user
|
1413
|
+
#
|
1414
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/update-app Update App by ID documentation}
|
1415
|
+
def update_app(app_id, app_params)
|
1416
|
+
clean_error
|
1417
|
+
prepare_token
|
1418
|
+
|
1419
|
+
begin
|
1420
|
+
if app_id.nil? || app_id.to_s.empty?
|
1421
|
+
@error = '400'
|
1422
|
+
@error_description = "app_id is required"
|
1423
|
+
@error_attribute = "app_id"
|
1424
|
+
return
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
url = url_for(UPDATE_APP_URL, app_id)
|
1428
|
+
|
1429
|
+
response = self.class.put(
|
1430
|
+
url,
|
1431
|
+
headers: authorized_headers,
|
1432
|
+
body: app_params.to_json
|
1433
|
+
)
|
1434
|
+
|
1435
|
+
if response.code == 200
|
1436
|
+
json_data = JSON.parse(response.body)
|
1437
|
+
if json_data && json_data.has_key?('id')
|
1438
|
+
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1439
|
+
end
|
1440
|
+
else
|
1441
|
+
@error = response.code.to_s
|
1442
|
+
@error_description = extract_error_message_from_response(response)
|
1443
|
+
@error_attribute = extract_error_attribute_from_response(response)
|
1444
|
+
end
|
1445
|
+
rescue Exception => e
|
1446
|
+
@error = '500'
|
1447
|
+
@error_description = e.message
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
nil
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
# Deletes an app
|
1454
|
+
#
|
1455
|
+
# @param app_id [Integer] Id of the app to be removed
|
1456
|
+
#
|
1457
|
+
# @return [Boolean] if the action succeed
|
1458
|
+
#
|
1459
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/delete-app Delete App by ID documentation}
|
1460
|
+
def delete_app(app_id)
|
1461
|
+
clean_error
|
1462
|
+
prepare_token
|
1463
|
+
|
1464
|
+
begin
|
1465
|
+
if app_id.nil? || app_id.to_s.empty?
|
1466
|
+
@error = '400'
|
1467
|
+
@error_description = "app_id is required"
|
1468
|
+
@error_attribute = "app_id"
|
1469
|
+
return
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
url = url_for(DELETE_APP_URL, app_id)
|
1473
|
+
|
1474
|
+
response = self.class.delete(
|
1475
|
+
url,
|
1476
|
+
headers: authorized_headers
|
1477
|
+
)
|
1478
|
+
|
1479
|
+
if response.code == 204
|
1480
|
+
return true
|
1481
|
+
else
|
1482
|
+
@error = response.code.to_s
|
1483
|
+
@error_description = extract_error_message_from_response(response)
|
1484
|
+
@error_attribute = extract_error_attribute_from_response(response)
|
1485
|
+
end
|
1486
|
+
rescue Exception => e
|
1487
|
+
@error = '500'
|
1488
|
+
@error_description = e.message
|
1489
|
+
end
|
1490
|
+
|
1491
|
+
false
|
1492
|
+
end
|
1493
|
+
|
1494
|
+
# Deletes an App Parameter
|
1495
|
+
#
|
1496
|
+
# @param app_id [Integer] Id of the app
|
1497
|
+
# @param parameter_id [Integer] Id of the parameter to be removed
|
1498
|
+
#
|
1499
|
+
# @return [Boolean] if the action succeed
|
1500
|
+
#
|
1501
|
+
# @see {https://developers.onelogin.com/api-docs/1/apps/delete-parameter Delete an App Parameter documentation}
|
1502
|
+
def delete_parameter_from_app(app_id, parameter_id)
|
1503
|
+
clean_error
|
1504
|
+
prepare_token
|
1505
|
+
|
1506
|
+
begin
|
1507
|
+
if app_id.nil? || app_id.to_s.empty?
|
1508
|
+
@error = '400'
|
1509
|
+
@error_description = "app_id is required"
|
1510
|
+
@error_attribute = "app_id"
|
1511
|
+
return
|
1512
|
+
end
|
1513
|
+
|
1514
|
+
if parameter_id.nil? || parameter_id.to_s.empty?
|
1515
|
+
@error = '400'
|
1516
|
+
@error_description = "parameter_id is required"
|
1517
|
+
@error_attribute = "parameter_id"
|
1518
|
+
return
|
1519
|
+
end
|
1520
|
+
|
1521
|
+
url = url_for(DELETE_APP_PARAMETER_URL, app_id, parameter_id)
|
1522
|
+
|
1523
|
+
response = self.class.delete(
|
1524
|
+
url,
|
1525
|
+
headers: authorized_headers
|
1526
|
+
)
|
1527
|
+
|
1528
|
+
if response.code == 204
|
1529
|
+
return true
|
1530
|
+
else
|
1531
|
+
@error = response.code.to_s
|
1532
|
+
@error_description = extract_error_message_from_response(response)
|
1533
|
+
@error_attribute = extract_error_attribute_from_response(response)
|
1534
|
+
end
|
1535
|
+
rescue Exception => e
|
1536
|
+
@error = '500'
|
1537
|
+
@error_description = e.message
|
1538
|
+
end
|
1539
|
+
|
1540
|
+
false
|
1541
|
+
end
|
1045
1542
|
|
1046
1543
|
################
|
1047
1544
|
# Role Methods #
|
@@ -1066,7 +1563,7 @@ module OneLogin
|
|
1066
1563
|
params: params
|
1067
1564
|
}
|
1068
1565
|
|
1069
|
-
return Cursor.new(self
|
1566
|
+
return Cursor.new(self, url_for(GET_ROLES_URL), options)
|
1070
1567
|
|
1071
1568
|
rescue Exception => e
|
1072
1569
|
@error = '500'
|
@@ -1088,6 +1585,13 @@ module OneLogin
|
|
1088
1585
|
prepare_token
|
1089
1586
|
|
1090
1587
|
begin
|
1588
|
+
if role_id.nil? || role_id.to_s.empty?
|
1589
|
+
@error = '400'
|
1590
|
+
@error_description = "role_id is required"
|
1591
|
+
@error_attribute = "role_id"
|
1592
|
+
return
|
1593
|
+
end
|
1594
|
+
|
1091
1595
|
url = url_for(GET_ROLE_URL, role_id)
|
1092
1596
|
|
1093
1597
|
response = self.class.get(
|
@@ -1132,7 +1636,7 @@ module OneLogin
|
|
1132
1636
|
max_results: @max_results
|
1133
1637
|
}
|
1134
1638
|
|
1135
|
-
return Cursor.new(self
|
1639
|
+
return Cursor.new(self, url_for(GET_EVENT_TYPES_URL), options)
|
1136
1640
|
|
1137
1641
|
rescue Exception => e
|
1138
1642
|
@error = '500'
|
@@ -1161,7 +1665,7 @@ module OneLogin
|
|
1161
1665
|
params: params
|
1162
1666
|
}
|
1163
1667
|
|
1164
|
-
return Cursor.new(self
|
1668
|
+
return Cursor.new(self, url_for(GET_EVENTS_URL), options)
|
1165
1669
|
|
1166
1670
|
rescue Exception => e
|
1167
1671
|
@error = '500'
|
@@ -1183,6 +1687,13 @@ module OneLogin
|
|
1183
1687
|
prepare_token
|
1184
1688
|
|
1185
1689
|
begin
|
1690
|
+
if event_id.nil? || event_id.to_s.empty?
|
1691
|
+
@error = '400'
|
1692
|
+
@error_description = "event_id is required"
|
1693
|
+
@error_attribute = "event_id"
|
1694
|
+
return
|
1695
|
+
end
|
1696
|
+
|
1186
1697
|
url = url_for(GET_EVENT_URL, event_id)
|
1187
1698
|
|
1188
1699
|
response = self.class.get(
|
@@ -1269,7 +1780,7 @@ module OneLogin
|
|
1269
1780
|
params: params
|
1270
1781
|
}
|
1271
1782
|
|
1272
|
-
return Cursor.new(self
|
1783
|
+
return Cursor.new(self, url_for(GET_GROUPS_URL), options)
|
1273
1784
|
|
1274
1785
|
rescue Exception => e
|
1275
1786
|
@error = '500'
|
@@ -1291,6 +1802,13 @@ module OneLogin
|
|
1291
1802
|
prepare_token
|
1292
1803
|
|
1293
1804
|
begin
|
1805
|
+
if group_id.nil? || group_id.to_s.empty?
|
1806
|
+
@error = '400'
|
1807
|
+
@error_description = "group_id is required"
|
1808
|
+
@error_attribute = "group_id"
|
1809
|
+
return
|
1810
|
+
end
|
1811
|
+
|
1294
1812
|
url = url_for(GET_GROUP_URL, group_id)
|
1295
1813
|
|
1296
1814
|
response = self.class.get(
|
@@ -1385,6 +1903,19 @@ module OneLogin
|
|
1385
1903
|
prepare_token
|
1386
1904
|
|
1387
1905
|
begin
|
1906
|
+
if app_id.nil? || app_id.to_s.empty?
|
1907
|
+
@error = '400'
|
1908
|
+
@error_description = "app_id is required"
|
1909
|
+
@error_attribute = "app_id"
|
1910
|
+
return
|
1911
|
+
end
|
1912
|
+
|
1913
|
+
if device_id.nil? || device_id.to_s.empty?
|
1914
|
+
@error = '400'
|
1915
|
+
@error_description = "device_id is required"
|
1916
|
+
@error_attribute = "device_id"
|
1917
|
+
return
|
1918
|
+
end
|
1388
1919
|
|
1389
1920
|
if url_endpoint.nil? || url_endpoint.empty?
|
1390
1921
|
url = url_for(GET_SAML_VERIFY_FACTOR)
|
@@ -1439,6 +1970,13 @@ module OneLogin
|
|
1439
1970
|
prepare_token
|
1440
1971
|
|
1441
1972
|
begin
|
1973
|
+
if user_id.nil? || user_id.to_s.empty?
|
1974
|
+
@error = '400'
|
1975
|
+
@error_description = "user_id is required"
|
1976
|
+
@error_attribute = "user_id"
|
1977
|
+
return
|
1978
|
+
end
|
1979
|
+
|
1442
1980
|
url = url_for(GET_FACTORS_URL, user_id)
|
1443
1981
|
|
1444
1982
|
response = self.class.get(
|
@@ -1482,6 +2020,20 @@ module OneLogin
|
|
1482
2020
|
prepare_token
|
1483
2021
|
|
1484
2022
|
begin
|
2023
|
+
if user_id.nil? || user_id.to_s.empty?
|
2024
|
+
@error = '400'
|
2025
|
+
@error_description = "user_id is required"
|
2026
|
+
@error_attribute = "user_id"
|
2027
|
+
return
|
2028
|
+
end
|
2029
|
+
|
2030
|
+
if factor_id.nil? || factor_id.to_s.empty?
|
2031
|
+
@error = '400'
|
2032
|
+
@error_description = "factor_id is required"
|
2033
|
+
@error_attribute = "factor_id"
|
2034
|
+
return
|
2035
|
+
end
|
2036
|
+
|
1485
2037
|
url = url_for(ENROLL_FACTOR_URL, user_id)
|
1486
2038
|
|
1487
2039
|
data = {
|
@@ -1525,6 +2077,13 @@ module OneLogin
|
|
1525
2077
|
prepare_token
|
1526
2078
|
|
1527
2079
|
begin
|
2080
|
+
if user_id.nil? || user_id.to_s.empty?
|
2081
|
+
@error = '400'
|
2082
|
+
@error_description = "user_id is required"
|
2083
|
+
@error_attribute = "user_id"
|
2084
|
+
return
|
2085
|
+
end
|
2086
|
+
|
1528
2087
|
url = url_for(GET_ENROLLED_FACTORS_URL, user_id)
|
1529
2088
|
|
1530
2089
|
response = self.class.get(
|
@@ -1567,6 +2126,20 @@ module OneLogin
|
|
1567
2126
|
prepare_token
|
1568
2127
|
|
1569
2128
|
begin
|
2129
|
+
if user_id.nil? || user_id.to_s.empty?
|
2130
|
+
@error = '400'
|
2131
|
+
@error_description = "user_id is required"
|
2132
|
+
@error_attribute = "user_id"
|
2133
|
+
return
|
2134
|
+
end
|
2135
|
+
|
2136
|
+
if device_id.nil? || device_id.to_s.empty?
|
2137
|
+
@error = '400'
|
2138
|
+
@error_description = "device_id is required"
|
2139
|
+
@error_attribute = "device_id"
|
2140
|
+
return
|
2141
|
+
end
|
2142
|
+
|
1570
2143
|
url = url_for(ACTIVATE_FACTOR_URL, user_id, device_id)
|
1571
2144
|
|
1572
2145
|
response = self.class.post(
|
@@ -1611,6 +2184,21 @@ module OneLogin
|
|
1611
2184
|
prepare_token
|
1612
2185
|
|
1613
2186
|
begin
|
2187
|
+
if user_id.nil? || user_id.to_s.empty?
|
2188
|
+
@error = '400'
|
2189
|
+
@error_description = "user_id is required"
|
2190
|
+
@error_attribute = "user_id"
|
2191
|
+
return
|
2192
|
+
end
|
2193
|
+
|
2194
|
+
if device_id.nil? || device_id.to_s.empty?
|
2195
|
+
@error = '400'
|
2196
|
+
@error_description = "device_id is required"
|
2197
|
+
@error_attribute = "device_id"
|
2198
|
+
return
|
2199
|
+
end
|
2200
|
+
|
2201
|
+
|
1614
2202
|
url = url_for(VERIFY_FACTOR_URL, user_id, device_id)
|
1615
2203
|
|
1616
2204
|
data = {
|
@@ -1659,6 +2247,21 @@ module OneLogin
|
|
1659
2247
|
prepare_token
|
1660
2248
|
|
1661
2249
|
begin
|
2250
|
+
|
2251
|
+
if user_id.nil? || user_id.to_s.empty?
|
2252
|
+
@error = '400'
|
2253
|
+
@error_description = "user_id is required"
|
2254
|
+
@error_attribute = "user_id"
|
2255
|
+
return
|
2256
|
+
end
|
2257
|
+
|
2258
|
+
if device_id.nil? || device_id.to_s.empty?
|
2259
|
+
@error = '400'
|
2260
|
+
@error_description = "device_id is required"
|
2261
|
+
@error_attribute = "device_id"
|
2262
|
+
return
|
2263
|
+
end
|
2264
|
+
|
1662
2265
|
url = url_for(REMOVE_FACTOR_URL, user_id, device_id)
|
1663
2266
|
|
1664
2267
|
response = self.class.delete(
|
@@ -1697,6 +2300,13 @@ module OneLogin
|
|
1697
2300
|
prepare_token
|
1698
2301
|
|
1699
2302
|
begin
|
2303
|
+
if email.nil? || email.to_s.empty?
|
2304
|
+
@error = '400'
|
2305
|
+
@error_description = "email is required"
|
2306
|
+
@error_attribute = "email"
|
2307
|
+
return
|
2308
|
+
end
|
2309
|
+
|
1700
2310
|
url = url_for(GENERATE_INVITE_LINK_URL)
|
1701
2311
|
|
1702
2312
|
data = {
|
@@ -1747,7 +2357,7 @@ module OneLogin
|
|
1747
2357
|
'email'=> email
|
1748
2358
|
}
|
1749
2359
|
|
1750
|
-
unless personal_email.nil? || personal_email.empty?
|
2360
|
+
unless personal_email.nil? || personal_email.to_s.empty?
|
1751
2361
|
data['personal_email'] = personal_email
|
1752
2362
|
end
|
1753
2363
|
|
@@ -1950,6 +2560,12 @@ module OneLogin
|
|
1950
2560
|
prepare_token
|
1951
2561
|
|
1952
2562
|
begin
|
2563
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2564
|
+
@error = '400'
|
2565
|
+
@error_description = "privilege_id is required"
|
2566
|
+
@error_attribute = "privilege_id"
|
2567
|
+
return
|
2568
|
+
end
|
1953
2569
|
|
1954
2570
|
url = url_for(GET_PRIVILEGE_URL, privilege_id)
|
1955
2571
|
|
@@ -1991,9 +2607,16 @@ module OneLogin
|
|
1991
2607
|
prepare_token
|
1992
2608
|
|
1993
2609
|
begin
|
2610
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2611
|
+
@error = '400'
|
2612
|
+
@error_description = "privilege_id is required"
|
2613
|
+
@error_attribute = "privilege_id"
|
2614
|
+
return
|
2615
|
+
end
|
2616
|
+
|
1994
2617
|
url = url_for(UPDATE_PRIVILEGE_URL, privilege_id)
|
1995
2618
|
|
1996
|
-
|
2619
|
+
statement_data = []
|
1997
2620
|
for statement in statements
|
1998
2621
|
if statement.instance_of?(OneLogin::Api::Models::Statement)
|
1999
2622
|
statement_data << {
|
@@ -2053,6 +2676,13 @@ module OneLogin
|
|
2053
2676
|
prepare_token
|
2054
2677
|
|
2055
2678
|
begin
|
2679
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2680
|
+
@error = '400'
|
2681
|
+
@error_description = "privilege_id is required"
|
2682
|
+
@error_attribute = "privilege_id"
|
2683
|
+
return
|
2684
|
+
end
|
2685
|
+
|
2056
2686
|
url = url_for(DELETE_PRIVILEGE_URL, privilege_id)
|
2057
2687
|
|
2058
2688
|
response = self.class.delete(
|
@@ -2086,13 +2716,20 @@ module OneLogin
|
|
2086
2716
|
prepare_token
|
2087
2717
|
|
2088
2718
|
begin
|
2719
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2720
|
+
@error = '400'
|
2721
|
+
@error_description = "privilege_id is required"
|
2722
|
+
@error_attribute = "privilege_id"
|
2723
|
+
return
|
2724
|
+
end
|
2725
|
+
|
2089
2726
|
options = {
|
2090
2727
|
headers: authorized_headers,
|
2091
2728
|
max_results: @max_results,
|
2092
2729
|
container: 'roles'
|
2093
2730
|
}
|
2094
2731
|
|
2095
|
-
return Cursor.new(self
|
2732
|
+
return Cursor.new(self, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
|
2096
2733
|
|
2097
2734
|
rescue Exception => e
|
2098
2735
|
@error = '500'
|
@@ -2115,6 +2752,13 @@ module OneLogin
|
|
2115
2752
|
prepare_token
|
2116
2753
|
|
2117
2754
|
begin
|
2755
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2756
|
+
@error = '400'
|
2757
|
+
@error_description = "privilege_id is required"
|
2758
|
+
@error_attribute = "privilege_id"
|
2759
|
+
return
|
2760
|
+
end
|
2761
|
+
|
2118
2762
|
url = url_for(ASSIGN_ROLES_TO_PRIVILEGE_URL, privilege_id)
|
2119
2763
|
|
2120
2764
|
data = {
|
@@ -2155,6 +2799,13 @@ module OneLogin
|
|
2155
2799
|
prepare_token
|
2156
2800
|
|
2157
2801
|
begin
|
2802
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2803
|
+
@error = '400'
|
2804
|
+
@error_description = "privilege_id is required"
|
2805
|
+
@error_attribute = "privilege_id"
|
2806
|
+
return
|
2807
|
+
end
|
2808
|
+
|
2158
2809
|
url = url_for(REMOVE_ROLE_FROM_PRIVILEGE_URL, privilege_id, role_id)
|
2159
2810
|
|
2160
2811
|
response = self.class.delete(
|
@@ -2188,13 +2839,20 @@ module OneLogin
|
|
2188
2839
|
prepare_token
|
2189
2840
|
|
2190
2841
|
begin
|
2842
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2843
|
+
@error = '400'
|
2844
|
+
@error_description = "privilege_id is required"
|
2845
|
+
@error_attribute = "privilege_id"
|
2846
|
+
return
|
2847
|
+
end
|
2848
|
+
|
2191
2849
|
options = {
|
2192
2850
|
headers: authorized_headers,
|
2193
2851
|
max_results: @max_results,
|
2194
2852
|
container: 'users'
|
2195
2853
|
}
|
2196
2854
|
|
2197
|
-
return Cursor.new(self
|
2855
|
+
return Cursor.new(self, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
|
2198
2856
|
|
2199
2857
|
rescue Exception => e
|
2200
2858
|
@error = '500'
|
@@ -2217,6 +2875,13 @@ module OneLogin
|
|
2217
2875
|
prepare_token
|
2218
2876
|
|
2219
2877
|
begin
|
2878
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2879
|
+
@error = '400'
|
2880
|
+
@error_description = "privilege_id is required"
|
2881
|
+
@error_attribute = "privilege_id"
|
2882
|
+
return
|
2883
|
+
end
|
2884
|
+
|
2220
2885
|
url = url_for(ASSIGN_USERS_TO_PRIVILEGE_URL, privilege_id)
|
2221
2886
|
|
2222
2887
|
data = {
|
@@ -2256,6 +2921,13 @@ module OneLogin
|
|
2256
2921
|
prepare_token
|
2257
2922
|
|
2258
2923
|
begin
|
2924
|
+
if privilege_id.nil? || privilege_id.to_s.empty?
|
2925
|
+
@error = '400'
|
2926
|
+
@error_description = "privilege_id is required"
|
2927
|
+
@error_attribute = "privilege_id"
|
2928
|
+
return
|
2929
|
+
end
|
2930
|
+
|
2259
2931
|
url = url_for(REMOVE_USER_FROM_PRIVILEGE_URL, privilege_id, user_id)
|
2260
2932
|
|
2261
2933
|
response = self.class.delete(
|