onelogin 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.class, url_for(GET_USERS_URL), options)
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.class, url_for(GET_APPS_FOR_USER_URL, user_id), options)
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(
@@ -952,11 +1044,18 @@ module OneLogin
952
1044
  # @return [MFAToken] if the action succeed
953
1045
  #
954
1046
  # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/generate-mfa-token Generate MFA Token documentation}
955
- def generate_mfa_token(user_id, expires_in=259200, reusable=False)
1047
+ def generate_mfa_token(user_id, expires_in=259200, reusable=false)
956
1048
  clean_error
957
1049
  prepare_token
958
1050
 
959
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
+
960
1059
  url = url_for(GENERATE_MFA_TOKEN_URL, user_id)
961
1060
 
962
1061
  data = {
@@ -1051,6 +1150,13 @@ module OneLogin
1051
1150
  prepare_token
1052
1151
 
1053
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
+
1054
1160
  url = url_for(GET_TOKEN_VERIFY_FACTOR)
1055
1161
 
1056
1162
  data = {
@@ -1088,31 +1194,76 @@ module OneLogin
1088
1194
  nil
1089
1195
  end
1090
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
1091
1242
 
1092
1243
  #########################
1093
1244
  # Onelogin Apps Methods #
1094
1245
  #########################
1095
1246
 
1096
- # Gets a list of OneLoginApp resources. (if no limit provided, by default get 50 elements)
1247
+ # Gets a list of OneLoginAppV1 resources. (if no limit provided, by default get 50 elements)
1097
1248
  #
1098
1249
  # @param params [Hash] Parameters to filter the result of the list
1099
1250
  #
1100
- # @return [Array] list of OneLoginApp objects
1251
+ # @return [Array] list of OneLoginAppV1 objects
1101
1252
  #
1102
1253
  # @see {https://developers.onelogin.com/api-docs/1/apps/get-apps Get Apps documentation}
1103
- def get_apps(params = {})
1254
+ def get_apps_v1(params = {})
1104
1255
  clean_error
1105
1256
  prepare_token
1106
1257
 
1107
1258
  begin
1108
1259
  options = {
1109
- model: OneLogin::Api::Models::OneLoginApp,
1260
+ model: OneLogin::Api::Models::OneLoginAppV1,
1110
1261
  headers: authorized_headers,
1111
1262
  max_results: @max_results,
1112
1263
  params: params
1113
1264
  }
1114
1265
 
1115
- return Cursor.new(self.class, url_for(GET_APPS_URL), options)
1266
+ return Cursor.new(self, url_for(GET_APPS_URL_V1), options)
1116
1267
 
1117
1268
  rescue Exception => e
1118
1269
  @error = '500'
@@ -1122,6 +1273,272 @@ module OneLogin
1122
1273
  nil
1123
1274
  end
1124
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
1125
1542
 
1126
1543
  ################
1127
1544
  # Role Methods #
@@ -1146,7 +1563,7 @@ module OneLogin
1146
1563
  params: params
1147
1564
  }
1148
1565
 
1149
- return Cursor.new(self.class, url_for(GET_ROLES_URL), options)
1566
+ return Cursor.new(self, url_for(GET_ROLES_URL), options)
1150
1567
 
1151
1568
  rescue Exception => e
1152
1569
  @error = '500'
@@ -1168,6 +1585,13 @@ module OneLogin
1168
1585
  prepare_token
1169
1586
 
1170
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
+
1171
1595
  url = url_for(GET_ROLE_URL, role_id)
1172
1596
 
1173
1597
  response = self.class.get(
@@ -1212,7 +1636,7 @@ module OneLogin
1212
1636
  max_results: @max_results
1213
1637
  }
1214
1638
 
1215
- return Cursor.new(self.class, url_for(GET_EVENT_TYPES_URL), options)
1639
+ return Cursor.new(self, url_for(GET_EVENT_TYPES_URL), options)
1216
1640
 
1217
1641
  rescue Exception => e
1218
1642
  @error = '500'
@@ -1241,7 +1665,7 @@ module OneLogin
1241
1665
  params: params
1242
1666
  }
1243
1667
 
1244
- return Cursor.new(self.class, url_for(GET_EVENTS_URL), options)
1668
+ return Cursor.new(self, url_for(GET_EVENTS_URL), options)
1245
1669
 
1246
1670
  rescue Exception => e
1247
1671
  @error = '500'
@@ -1263,6 +1687,13 @@ module OneLogin
1263
1687
  prepare_token
1264
1688
 
1265
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
+
1266
1697
  url = url_for(GET_EVENT_URL, event_id)
1267
1698
 
1268
1699
  response = self.class.get(
@@ -1349,7 +1780,7 @@ module OneLogin
1349
1780
  params: params
1350
1781
  }
1351
1782
 
1352
- return Cursor.new(self.class, url_for(GET_GROUPS_URL), options)
1783
+ return Cursor.new(self, url_for(GET_GROUPS_URL), options)
1353
1784
 
1354
1785
  rescue Exception => e
1355
1786
  @error = '500'
@@ -1371,6 +1802,13 @@ module OneLogin
1371
1802
  prepare_token
1372
1803
 
1373
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
+
1374
1812
  url = url_for(GET_GROUP_URL, group_id)
1375
1813
 
1376
1814
  response = self.class.get(
@@ -1465,6 +1903,19 @@ module OneLogin
1465
1903
  prepare_token
1466
1904
 
1467
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
1468
1919
 
1469
1920
  if url_endpoint.nil? || url_endpoint.empty?
1470
1921
  url = url_for(GET_SAML_VERIFY_FACTOR)
@@ -1519,6 +1970,13 @@ module OneLogin
1519
1970
  prepare_token
1520
1971
 
1521
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
+
1522
1980
  url = url_for(GET_FACTORS_URL, user_id)
1523
1981
 
1524
1982
  response = self.class.get(
@@ -1562,6 +2020,20 @@ module OneLogin
1562
2020
  prepare_token
1563
2021
 
1564
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
+
1565
2037
  url = url_for(ENROLL_FACTOR_URL, user_id)
1566
2038
 
1567
2039
  data = {
@@ -1605,6 +2077,13 @@ module OneLogin
1605
2077
  prepare_token
1606
2078
 
1607
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
+
1608
2087
  url = url_for(GET_ENROLLED_FACTORS_URL, user_id)
1609
2088
 
1610
2089
  response = self.class.get(
@@ -1647,6 +2126,20 @@ module OneLogin
1647
2126
  prepare_token
1648
2127
 
1649
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
+
1650
2143
  url = url_for(ACTIVATE_FACTOR_URL, user_id, device_id)
1651
2144
 
1652
2145
  response = self.class.post(
@@ -1691,6 +2184,21 @@ module OneLogin
1691
2184
  prepare_token
1692
2185
 
1693
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
+
1694
2202
  url = url_for(VERIFY_FACTOR_URL, user_id, device_id)
1695
2203
 
1696
2204
  data = {
@@ -1739,6 +2247,21 @@ module OneLogin
1739
2247
  prepare_token
1740
2248
 
1741
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
+
1742
2265
  url = url_for(REMOVE_FACTOR_URL, user_id, device_id)
1743
2266
 
1744
2267
  response = self.class.delete(
@@ -1777,6 +2300,13 @@ module OneLogin
1777
2300
  prepare_token
1778
2301
 
1779
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
+
1780
2310
  url = url_for(GENERATE_INVITE_LINK_URL)
1781
2311
 
1782
2312
  data = {
@@ -1827,7 +2357,7 @@ module OneLogin
1827
2357
  'email'=> email
1828
2358
  }
1829
2359
 
1830
- unless personal_email.nil? || personal_email.empty?
2360
+ unless personal_email.nil? || personal_email.to_s.empty?
1831
2361
  data['personal_email'] = personal_email
1832
2362
  end
1833
2363
 
@@ -2030,6 +2560,12 @@ module OneLogin
2030
2560
  prepare_token
2031
2561
 
2032
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
2033
2569
 
2034
2570
  url = url_for(GET_PRIVILEGE_URL, privilege_id)
2035
2571
 
@@ -2071,9 +2607,16 @@ module OneLogin
2071
2607
  prepare_token
2072
2608
 
2073
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
+
2074
2617
  url = url_for(UPDATE_PRIVILEGE_URL, privilege_id)
2075
2618
 
2076
- statement_data = []
2619
+ statement_data = []
2077
2620
  for statement in statements
2078
2621
  if statement.instance_of?(OneLogin::Api::Models::Statement)
2079
2622
  statement_data << {
@@ -2133,6 +2676,13 @@ module OneLogin
2133
2676
  prepare_token
2134
2677
 
2135
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
+
2136
2686
  url = url_for(DELETE_PRIVILEGE_URL, privilege_id)
2137
2687
 
2138
2688
  response = self.class.delete(
@@ -2166,13 +2716,20 @@ module OneLogin
2166
2716
  prepare_token
2167
2717
 
2168
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
+
2169
2726
  options = {
2170
2727
  headers: authorized_headers,
2171
2728
  max_results: @max_results,
2172
2729
  container: 'roles'
2173
2730
  }
2174
2731
 
2175
- return Cursor.new(self.class, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
2732
+ return Cursor.new(self, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
2176
2733
 
2177
2734
  rescue Exception => e
2178
2735
  @error = '500'
@@ -2195,6 +2752,13 @@ module OneLogin
2195
2752
  prepare_token
2196
2753
 
2197
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
+
2198
2762
  url = url_for(ASSIGN_ROLES_TO_PRIVILEGE_URL, privilege_id)
2199
2763
 
2200
2764
  data = {
@@ -2235,6 +2799,13 @@ module OneLogin
2235
2799
  prepare_token
2236
2800
 
2237
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
+
2238
2809
  url = url_for(REMOVE_ROLE_FROM_PRIVILEGE_URL, privilege_id, role_id)
2239
2810
 
2240
2811
  response = self.class.delete(
@@ -2268,13 +2839,20 @@ module OneLogin
2268
2839
  prepare_token
2269
2840
 
2270
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
+
2271
2849
  options = {
2272
2850
  headers: authorized_headers,
2273
2851
  max_results: @max_results,
2274
2852
  container: 'users'
2275
2853
  }
2276
2854
 
2277
- return Cursor.new(self.class, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
2855
+ return Cursor.new(self, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
2278
2856
 
2279
2857
  rescue Exception => e
2280
2858
  @error = '500'
@@ -2297,6 +2875,13 @@ module OneLogin
2297
2875
  prepare_token
2298
2876
 
2299
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
+
2300
2885
  url = url_for(ASSIGN_USERS_TO_PRIVILEGE_URL, privilege_id)
2301
2886
 
2302
2887
  data = {
@@ -2336,6 +2921,13 @@ module OneLogin
2336
2921
  prepare_token
2337
2922
 
2338
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
+
2339
2931
  url = url_for(REMOVE_USER_FROM_PRIVILEGE_URL, privilege_id, user_id)
2340
2932
 
2341
2933
  response = self.class.delete(