onelogin 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03bb1cfe01588bca301fc933bc1dacd1c2cceffe
4
- data.tar.gz: ec4855fd9715e14b73d47931e7be472cbd4dd554
3
+ metadata.gz: 8a853d4babb81062c1848521170d52d214790795
4
+ data.tar.gz: b05724bd5d05456367fc6156a1a142e1520a1dc4
5
5
  SHA512:
6
- metadata.gz: fda3d372797a79145e935e7101e15e54ffdd802eb6dd7732a5a5a84b86f0c31bd9b4ead28013a64105b11713181e2074e90fe3809bc3f30e62a3696ea63db29b
7
- data.tar.gz: e68a4cf6bbb4e0ff7436256ca76ad9a7024042afefc9902fa35535e01056b0bca0b7b422e5f856bb27834f26542e8f103ad3c94ae88d1c65367cbbe427b17607
6
+ metadata.gz: d0d58e6cd9c59d3dc9c532c48884c316a1e14f5f59f6524de078c4caea08df37c5a9e92d194250846316f72a520c1ac579d95d9ca208b1a12a7f4937d9875ca5
7
+ data.tar.gz: 2f6ac6069d8ca15c0f705c103be55f50dd2258fdc8a381a64557fd7b1a08f91906ea87e2321d8035cd4eca752fcc78fa1e6c513f2102ab10541ac38ad5884268
data/README.md CHANGED
@@ -238,24 +238,6 @@ created_user = client.create_user(new_user_params)
238
238
  # Delete User
239
239
  result = client.delete_user(created_user.id)
240
240
 
241
- # Create Session Login Token
242
- session_login_token_params = {
243
- username_or_email: "user@example.com",
244
- password: "Aa765431-XxX",
245
- subdomain: "example-onelogin-subdomain"
246
- }
247
- session_token_data = client.create_session_login_token(session_login_token_params)
248
-
249
- # Create Session Login Token MFA , after verify
250
- session_login_token_mfa_params = {
251
- username_or_email: "usermfa@example.com",
252
- password: "Aa765432-YyY",
253
- subdomain: "example-onelogin-subdomain"
254
- }
255
- session_token_mfa_data = client.create_session_login_token(session_login_token_mfa_params)
256
- otp_token = "000000" # We get this value from OTP device
257
- session_token_data2 = client.get_session_token_verified(session_token_mfa_data.devices[0].id,session_token_mfa_data.state_token, otp_token)
258
-
259
241
  # Get EventTypes
260
242
  event_types = client.get_event_types
261
243
 
@@ -303,6 +285,44 @@ mfa = saml_endpoint_response2.mfa
303
285
  otp_token = "000000"
304
286
  saml_endpoint_response_after_verify = client.get_saml_assertion_verifying(app_id, mfa.devices[0].id, mfa.state_token, "78395727", nil)
305
287
 
288
+ # Create Session Login Token
289
+ session_login_token_params = {
290
+ username_or_email: "user@example.com",
291
+ password: "Aa765431-XxX",
292
+ subdomain: "example-onelogin-subdomain"
293
+ }
294
+ session_token_data = client.create_session_login_token(session_login_token_params)
295
+
296
+ # Create Session Via API Token
297
+ cookie = client..create_session_via_token(session_token_data.session_token)
298
+
299
+ # Create Session Login Token MFA , after verify
300
+ session_login_token_mfa_params = {
301
+ username_or_email: "usermfa@example.com",
302
+ password: "Aa765432-YyY",
303
+ subdomain: "example-onelogin-subdomain"
304
+ }
305
+ session_token_mfa_data = client.create_session_login_token(session_login_token_mfa_params)
306
+ otp_token = "000000" # We get this value from OTP device
307
+ session_token_data2 = client.get_session_token_verified(session_token_mfa_data.devices.first.id,session_token_mfa_data.state_token, otp_token)
308
+
309
+ user_id = 00000000
310
+ # Get Available Authentication Factors
311
+ auth_factors = client.get_factors(user_id)
312
+
313
+ # Enroll an Authentication Factor
314
+ enroll_factor = client.enroll_factor(user_id, auth_factors.first.id, 'My Device', '+14156456830')
315
+
316
+ # Get Enrolled Authentication Factors
317
+ otp_devices = client.get_enrolled_factors(user_id)
318
+
319
+ # Activate an Authentication Factor
320
+ device_id = 0000000
321
+ enrollment_response = client.activate_factor(user_id, device_id)
322
+
323
+ # Verify an Authentication Factor
324
+ result = client.verify_factor(user_id, device_id, otp_token="4242342423")
325
+
306
326
  # Generate Invite Link
307
327
  url_link = client.generate_invite_link("user@example.com")
308
328
 
data/examples/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'onelogin'
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ httparty (0.16.0)
5
+ multi_xml (>= 0.5.2)
6
+ mini_portile2 (2.3.0)
7
+ multi_xml (0.6.0)
8
+ nokogiri (1.8.2)
9
+ mini_portile2 (~> 2.3.0)
10
+ onelogin (1.0.1)
11
+ httparty (>= 0.13.7)
12
+ nokogiri (>= 1.6.3.1)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ onelogin
19
+
20
+ BUNDLED WITH
21
+ 1.16.0.pre.3
@@ -0,0 +1,19 @@
1
+ # Ruby SDK Examples
2
+
3
+ This folder contains various samples that make use of the OneLogin
4
+ Ruby SDK.
5
+
6
+ It assumes that you have a valid OneLogin `client_id` and `client_secret`
7
+ with the appropriate level of access for each example.
8
+
9
+ ## Try the examples in terminal
10
+
11
+ First install the OneLogin gem and any other required gems
12
+ ```shell
13
+ bundle install
14
+ ```
15
+
16
+ Then update your API credentials in the example file and run it
17
+ ```shell
18
+ ruby create-user.rb
19
+ ```
@@ -0,0 +1,47 @@
1
+ require 'onelogin'
2
+
3
+ #
4
+ # This example shows how you can export user details from OneLogin using the Ruby SDK
5
+ #
6
+ # Usage:
7
+ # 1. Set your own CLIENT_ID and CLIENT_SECRET below
8
+ # 2. From terminal run "ruby all-users-to-csv.rb" to extract all users including
9
+ # any custom attributes that might have been defined for the each user
10
+ #
11
+
12
+ client = OneLogin::Api::Client.new(
13
+ client_id: 'ONELOGIN_CLIENT_ID',
14
+ client_secret:'ONELOGIN_CLIENT_SECRET',
15
+ region: 'us'
16
+ )
17
+
18
+ attribute_names = ['id', 'external_id', 'email', 'username', 'firstname', 'lastname', 'distinguished_name',
19
+ 'phone', 'company', 'department', 'status', 'member_of', 'samaccountname', 'userprincipalname',
20
+ 'group_id', 'role_ids', 'custom_attributes', 'openid_name', 'locale_code', 'comment', 'directory_id',
21
+ 'manager_ad_id', 'trusted_idp_id', 'activated_at', 'created_at', 'updated_at',
22
+ 'password_changed_at', 'invitation_sent_at', 'invalid_login_attempts', 'last_login', 'locked_until']
23
+
24
+ custom_attribute_names = client.get_custom_attributes
25
+
26
+ CSV.open('users.csv', 'wb') do |csv|
27
+ # header row
28
+ csv << attribute_names + custom_attribute_names
29
+
30
+ client.get_users.each do |user|
31
+
32
+ row = []
33
+
34
+ # standard attributes
35
+ attribute_names.each do |attribute_name|
36
+ row << user.send(attribute_name)
37
+ end
38
+
39
+ # custom attributes
40
+ custom_attribute_names.each do |attribute_name|
41
+ row << user.custom_attributes[attribute_name] unless user.custom_attributes.empty?
42
+ end
43
+
44
+ csv << row
45
+ end
46
+ end
47
+
@@ -0,0 +1,16 @@
1
+ require 'onelogin'
2
+
3
+ client = OneLogin::Api::Client.new(
4
+ client_id: 'ONELOGIN_CLIENT_ID',
5
+ client_secret:'ONELOGIN_CLIENT_SECRET',
6
+ region: 'us'
7
+ )
8
+
9
+ user = client.create_user(
10
+ firstname: "Mick",
11
+ lastname: "Fanning",
12
+ email: "mick@onelogin.com",
13
+ username: "mick"
14
+ )
15
+
16
+ puts user
@@ -0,0 +1,77 @@
1
+ require 'onelogin'
2
+ require 'optparse'
3
+ require 'optparse/time'
4
+
5
+ #
6
+ # This example shows how you can export events from OneLogin using the Ruby SDK
7
+ #
8
+ # Usage:
9
+ # 1. Set your own CLIENT_ID and CLIENT_SECRET below
10
+ # 2. From terminal run "ruby events-to-csv.rb" for the last 1000 events
11
+ # 3. Use the command line args to filter events
12
+ #
13
+ # e.g. "ruby events-to-csv.rb -t 5 -s 2018-01-01" for login events since Jan 1 2018
14
+ #
15
+
16
+
17
+ # Parse CLI arguments
18
+ options = {}
19
+
20
+ OptionParser.new do |opts|
21
+ opts.banner = "Usage: events-to-csv.rb [options]"
22
+
23
+ opts.on("-sSINCE", "--since=SINCE", Time, "Events after this date") do |s|
24
+ options[:since] = s.iso8601
25
+ end
26
+
27
+ opts.on("-uUNTIL", "--UNTIL=UNTIL", Time, "Events before this date") do |u|
28
+ options[:until] = u.iso8601
29
+ end
30
+
31
+ opts.on("-lLIMIT", "--limit=LIMIT", Integer, "Only return this many events, Default 1000") do |l|
32
+ options[:limit] = l
33
+ end
34
+
35
+ opts.on("-tTYPE", "--type=TYPE", Integer, "Filter by event type id") do |t|
36
+ options[:event_type_id] = t
37
+ end
38
+ end.parse!
39
+
40
+ # Fetch the events
41
+ client = OneLogin::Api::Client.new(
42
+ client_id: 'ONELOGIN_CLIENT_ID',
43
+ client_secret: 'ONELOGIN_CLIENT_SECRET',
44
+ region: 'us'
45
+ )
46
+
47
+ attribute_names = ['id', 'created_at', 'account_id', 'user_id', 'user_name', 'event_type_id',
48
+ 'notes', 'ipaddr', 'actor_user_id', 'actor_user_name', 'assuming_acting_user_id',
49
+ 'role_id', 'role_name', 'app_id', 'group_id', 'group_name', 'otp_device_id',
50
+ 'otp_device_name', 'policy_id', 'policy_name', 'actor_system', 'custom_message',
51
+ 'operation_name', 'directory_sync_run_id', 'directory_id', 'resolution', 'client_id',
52
+ 'resource_type_id', 'error_description']
53
+
54
+ counter = 0
55
+ limit = options[:limit] || 1000
56
+
57
+ # We remove limit from options parsed to the api as we want to fetch
58
+ # the max number of records possible and then use the cursor that is
59
+ # built into the ruby sdk to limit the results
60
+ options.delete(:limit)
61
+
62
+ CSV.open('events.csv', 'wb') do |csv|
63
+ puts "Exporting events to events.csv"
64
+
65
+ # header row
66
+ csv << attribute_names
67
+
68
+ # fetch the events
69
+ client.get_events(options).take(limit).each do |event|
70
+ csv << attribute_names.map { |attribute_name| event.send(attribute_name) }
71
+ end
72
+ end
73
+
74
+ puts "Exported #{counter} events to events.csv"
75
+
76
+
77
+
@@ -0,0 +1,15 @@
1
+ require 'onelogin'
2
+
3
+ client = OneLogin::Api::Client.new(
4
+ client_id: 'ONELOGIN_CLIENT_ID',
5
+ client_secret:'ONELOGIN_CLIENT_SECRET',
6
+ region: 'us'
7
+ )
8
+
9
+ # List all of the users in your account
10
+ # the sdk uses a cursor to keep requesting
11
+ # chunks of users as you loop through
12
+
13
+ client.get_users.each do |user|
14
+ puts "#{user.id} - #{user.firstname} - #{user.email}"
15
+ end
@@ -900,17 +900,13 @@ module OneLogin
900
900
  begin
901
901
  url = url_for(SESSION_LOGIN_TOKEN_URL)
902
902
 
903
- unless allowed_origin.nil? || allowed_origin.empty?
904
- headers['Custom-Allowed-Origin-Header-1'] = allowed_origin
905
- end
906
-
907
903
  if query_params.nil? || !query_params.has_key?('username_or_email') || !query_params.has_key?('password') || !query_params.has_key?('subdomain')
908
904
  raise "username_or_email, password and subdomain are required parameters"
909
905
  end
910
906
 
911
907
  response = HTTParty.post(
912
908
  url,
913
- headers: authorized_headers,
909
+ headers: authorized_headers.merge({ 'Custom-Allowed-Origin-Header-1' => allowed_origin }),
914
910
  body: query_params.to_json
915
911
  )
916
912
 
@@ -973,6 +969,45 @@ module OneLogin
973
969
  nil
974
970
  end
975
971
 
972
+ # Post a session token to this API endpoint to start a session and set a cookie to log a user into an app.
973
+ #
974
+ # @param session_token [String] The session token
975
+ #
976
+ # @return [String] return the 'Set-Cookie' value of the HTTP Header if any
977
+ #
978
+ # @see {https://developers.onelogin.com/api-docs/1/login-page/create-session-via-token Create Session Via API Token documentation}
979
+ def create_session_via_token(session_token)
980
+ clean_error
981
+
982
+ begin
983
+ url = url_for(SESSION_API_TOKEN_URL)
984
+
985
+ data = {
986
+ 'session_token'=> session_token
987
+ }
988
+
989
+ response = HTTParty.post(
990
+ url,
991
+ headers: headers,
992
+ body: data.to_json
993
+ )
994
+
995
+ if response.code == 200
996
+ if response.headers.key?('Set-Cookie')
997
+ return response.headers['Set-Cookie']
998
+ end
999
+ else
1000
+ @error = response.code.to_s
1001
+ @error_description = extract_error_message_from_response(response)
1002
+ end
1003
+ rescue Exception => e
1004
+ @error = '500'
1005
+ @error_description = e.message
1006
+ end
1007
+
1008
+ nil
1009
+ end
1010
+
976
1011
  ################
977
1012
  # Role Methods #
978
1013
  ################
@@ -1350,6 +1385,229 @@ module OneLogin
1350
1385
  nil
1351
1386
  end
1352
1387
 
1388
+ #############################
1389
+ # Multi-factor Auth Methods #
1390
+ #############################
1391
+
1392
+ # Returns a list of authentication factors that are available for user enrollment via API.
1393
+ #
1394
+ # @param user_id [Integer] The id of the user.
1395
+ #
1396
+ # @return [Array] AuthFactor list
1397
+ #
1398
+ # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/available-factors Get Available Authentication Factors documentation}
1399
+ def get_factors(user_id)
1400
+ clean_error
1401
+ prepare_token
1402
+
1403
+ begin
1404
+ url = url_for(GET_FACTORS_URL, user_id)
1405
+
1406
+ response = HTTParty.get(
1407
+ url,
1408
+ :headers => authorized_headers
1409
+ )
1410
+
1411
+ factors = []
1412
+ if response.code == 200
1413
+ json_data = JSON.parse(response.body)
1414
+ if json_data and json_data['data'] and json_data['data']['auth_factors']
1415
+ json_data['data']['auth_factors'].each do |factor_data|
1416
+ factors << OneLogin::Api::Models::AuthFactor.new(factor_data)
1417
+ end
1418
+ end
1419
+ else
1420
+ @error = response.code.to_s
1421
+ @error_description = extract_error_message_from_response(response)
1422
+ end
1423
+ return factors
1424
+ rescue Exception => e
1425
+ @error = '500'
1426
+ @error_description = e.message
1427
+ end
1428
+
1429
+ nil
1430
+ end
1431
+
1432
+ # Enroll a user with a given authentication factor.
1433
+ #
1434
+ # @param user_id [Integer] The id of the user.
1435
+ # @param factor_id [Integer] The identifier of the factor to enroll the user with.
1436
+ # @param display_name [String] A name for the users device.
1437
+ # @param number [String] The phone number of the user in E.164 format.
1438
+ #
1439
+ # @return [OTPDevice] MFA device
1440
+ #
1441
+ # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/enroll-factor Enroll an Authentication Factor documentation}
1442
+ def enroll_factor(user_id, factor_id, display_name, number)
1443
+ clean_error
1444
+ prepare_token
1445
+
1446
+ begin
1447
+ url = url_for(ENROLL_FACTOR_URL, user_id)
1448
+
1449
+ data = {
1450
+ 'factor_id'=> factor_id.to_i,
1451
+ 'display_name'=> display_name,
1452
+ 'number'=> number
1453
+ }
1454
+
1455
+ response = HTTParty.post(
1456
+ url,
1457
+ :headers => authorized_headers,
1458
+ body: data.to_json
1459
+ )
1460
+
1461
+ if response.code == 200
1462
+ json_data = JSON.parse(response.body)
1463
+ if json_data and json_data['data']
1464
+ return OneLogin::Api::Models::OTPDevice.new(json_data['data'][0])
1465
+ end
1466
+ else
1467
+ @error = response.code.to_s
1468
+ @error_description = extract_error_message_from_response(response)
1469
+ end
1470
+ rescue Exception => e
1471
+ @error = '500'
1472
+ @error_description = e.message
1473
+ end
1474
+
1475
+ nil
1476
+ end
1477
+
1478
+ # Return a list of authentication factors registered to a particular user for multifactor authentication (MFA)
1479
+ #
1480
+ # @param user_id [Integer] The id of the user.
1481
+ #
1482
+ # @return [Array] OTPDevice List
1483
+ #
1484
+ # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/enrolled-factors Get Enrolled Authentication Factors documentation}
1485
+ def get_enrolled_factors(user_id)
1486
+ clean_error
1487
+ prepare_token
1488
+
1489
+ begin
1490
+ url = url_for(GET_ENROLLED_FACTORS_URL, user_id)
1491
+
1492
+ response = HTTParty.get(
1493
+ url,
1494
+ :headers => authorized_headers
1495
+ )
1496
+
1497
+ otp_devices = []
1498
+ if response.code == 200
1499
+ json_data = JSON.parse(response.body)
1500
+ if json_data and json_data['data'] and json_data['data']['otp_devices']
1501
+ json_data['data']['otp_devices'].each do |otp_device_data|
1502
+ otp_devices << OneLogin::Api::Models::OTPDevice.new(otp_device_data)
1503
+ end
1504
+ end
1505
+ else
1506
+ @error = response.code.to_s
1507
+ @error_description = extract_error_message_from_response(response)
1508
+ end
1509
+ return otp_devices
1510
+ rescue Exception => e
1511
+ @error = '500'
1512
+ @error_description = e.message
1513
+ end
1514
+
1515
+ nil
1516
+ end
1517
+
1518
+ # Triggers an SMS or Push notification containing a One-Time Password (OTP)
1519
+ # that can be used to authenticate a user with the Verify Factor call.
1520
+ #
1521
+ # @param user_id [Integer] The id of the user.
1522
+ # @param device_id [Integer] The id of the MFA device.
1523
+ #
1524
+ # @return [FactorEnrollmentResponse] Info with User Id, Device Id, and OTP Device
1525
+ #
1526
+ # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/activate-factor Activate an Authentication Factor documentation}
1527
+ def activate_factor(user_id, device_id)
1528
+ clean_error
1529
+ prepare_token
1530
+
1531
+ begin
1532
+ url = url_for(ACTIVATE_FACTOR_URL, user_id, device_id)
1533
+
1534
+ response = HTTParty.post(
1535
+ url,
1536
+ headers: authorized_headers
1537
+ )
1538
+
1539
+ if response.code == 200
1540
+ json_data = JSON.parse(response.body)
1541
+ if json_data && json_data['data']
1542
+ return OneLogin::Api::Models::FactorEnrollmentResponse.new(json_data['data'][0])
1543
+ end
1544
+ else
1545
+ @error = response.code.to_s
1546
+ @error_description = extract_error_message_from_response(response)
1547
+ end
1548
+ rescue Exception => e
1549
+ @error = '500'
1550
+ @error_description = e.message
1551
+ end
1552
+
1553
+ nil
1554
+ end
1555
+
1556
+ # Authenticates a one-time password (OTP) code provided by a multifactor authentication (MFA) device.
1557
+ #
1558
+ # @param user_id [Integer] The id of the user.
1559
+ # @param device_id [Integer] The id of the MFA device.
1560
+ # @param otp_token [String] OTP code provided by the device or SMS message sent to user.
1561
+ # When a device like OneLogin Protect that supports Push has
1562
+ # been used you do not need to provide the otp_token.
1563
+ # @param state_token [String] The state_token is returned after a successful request
1564
+ # to Enroll a Factor or Activate a Factor.
1565
+ # MUST be provided if the needs_trigger attribute from
1566
+ # the proceeding calls is set to true.
1567
+ #
1568
+ # @return [Boolean] True if Factor is verified
1569
+ #
1570
+ # @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/verify-factor Verify an Authentication Factor documentation}
1571
+ def verify_factor(user_id, device_id, otp_token=nil, state_token=nil)
1572
+ clean_error
1573
+ prepare_token
1574
+
1575
+ begin
1576
+ url = url_for(VERIFY_FACTOR_URL, user_id, device_id)
1577
+
1578
+ data = {
1579
+ 'user_id'=> user_id,
1580
+ 'device_id'=> device_id
1581
+ }
1582
+
1583
+ unless otp_token.nil? || otp_token.empty?
1584
+ data['otp_token'] = otp_token
1585
+ end
1586
+
1587
+ unless state_token.nil? || state_token.empty?
1588
+ data['state_token'] = state_token
1589
+ end
1590
+
1591
+ response = HTTParty.post(
1592
+ url,
1593
+ headers: authorized_headers,
1594
+ body: data.to_json
1595
+ )
1596
+
1597
+ if response.code == 200
1598
+ return handle_operation_response(response)
1599
+ else
1600
+ @error = response.code.to_s
1601
+ @error_description = extract_error_message_from_response(response)
1602
+ end
1603
+ rescue Exception => e
1604
+ @error = '500'
1605
+ @error_description = e.message
1606
+ end
1607
+
1608
+ false
1609
+ end
1610
+
1353
1611
  ########################
1354
1612
  # Invite Links Methods #
1355
1613
  ########################
@@ -0,0 +1,16 @@
1
+ module OneLogin
2
+ module Api
3
+ module Models
4
+
5
+ class AuthFactor
6
+
7
+ attr_accessor :id, :name
8
+
9
+ def initialize(data)
10
+ @id = data['factor_id']
11
+ @name = data['name'].to_s
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module OneLogin
2
+ module Api
3
+ module Models
4
+
5
+ class FactorEnrollmentResponse
6
+
7
+ attr_accessor :device_id, :user_id, :active, :auth_factor_name,
8
+ :type_display_name, :user_display_name, :state_token
9
+
10
+ def initialize(data)
11
+ @device_id = data['device_id']? data['device_id'].to_i : nil
12
+ @user_id = data['id']? data['id'].to_i : nil
13
+ @active = data['active']
14
+ @auth_factor_name = data['auth_factor_name']
15
+ @type_display_name = data['type_display_name']
16
+ @user_display_name = data['user_display_name']
17
+ @state_token = data['state_token']
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ module OneLogin
2
+ module Api
3
+ module Models
4
+
5
+ class OTPDevice
6
+
7
+ attr_accessor :id, :active, :default, :auth_factor_name, :phone_number,
8
+ :type_display_name, :needs_trigger, :user_display_name,
9
+ :state_token
10
+
11
+ def initialize(data)
12
+ @id = data['id']? data['id'].to_i : nil
13
+ @active = data['active']
14
+ @default = data['default']
15
+ @auth_factor_name = data['auth_factor_name']
16
+ @phone_number = data['phone_number']
17
+ @type_display_name = data['type_display_name']
18
+ @needs_trigger = data['needs_trigger']
19
+ @user_display_name = data['user_display_name']
20
+ @state_token = data['state_token']
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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, :member_of, :samaccountname, :userprincipalname,
9
9
  :group_id, :role_ids, :custom_attributes, :openid_name, :locale_code, :comment, :directory_id,
10
- :manager_ad_id, :trusted_idp_id, :activated_at, :created_at, :updated_at,
10
+ :title, :manager_ad_id, :trusted_idp_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)
@@ -21,6 +21,7 @@ module OneLogin
21
21
  @phone = data['phone'].to_s
22
22
  @company = data['company'].to_s
23
23
  @department = data['department'].to_s
24
+ @title = data['title'].to_s
24
25
  @status = data['status']
25
26
  @member_of = data['member_of'].to_s
26
27
  @samaccountname = data['samaccountname'].to_s
@@ -39,7 +40,7 @@ module OneLogin
39
40
  @password_changed_at = data['password_changed_at']? Time.iso8601(data['password_changed_at']) : nil
40
41
  @invitation_sent_at = data['invitation_sent_at']? Time.iso8601(data['invitation_sent_at']) : nil
41
42
  @invalid_login_attempts = data['invalid_login_attempts']
42
- @last_login = data['last_login']? Time.iso8601(data['last_login']) : nil
43
+ @last_login = data['last_login']? Time.iso8601(data['last_login']) : nil
43
44
  @locked_until = data['locked_until']? Time.iso8601(data['locked_until']) : nil
44
45
  end
45
46
 
@@ -63,6 +64,7 @@ module OneLogin
63
64
  user_data.phone = @phone
64
65
  user_data.company = @company
65
66
  user_data.department = @department
67
+ user_data.title = @title
66
68
  user_data.status = @status
67
69
  user_data.member_of = @member_of
68
70
  user_data.samaccountname = @samaccountname
@@ -73,7 +75,7 @@ module OneLogin
73
75
  user_data.manager_ad_id = @manager_ad_id
74
76
  user_data.trusted_idp_id = @trusted_idp_id
75
77
  return user_data
76
- end
78
+ end
77
79
 
78
80
  def get_user_metadata
79
81
  user_metadata = UserMetadata.new
@@ -106,6 +108,7 @@ module OneLogin
106
108
  "phone"=> self.phone,
107
109
  "company"=> self.company,
108
110
  "department"=> self.department,
111
+ "title"=> self.title,
109
112
  "status"=> self.status,
110
113
  "member_of"=> self.member_of,
111
114
  "samaccountname"=> self.samaccountname,
@@ -122,4 +125,4 @@ module OneLogin
122
125
  end
123
126
  end
124
127
  end
125
- end
128
+ 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, :member_of, :samaccountname, :userprincipalname,
9
- :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
10
10
  end
11
11
  end
12
12
  end
@@ -1,10 +1,13 @@
1
1
  require 'onelogin/api/models/app'
2
+ require 'onelogin/api/models/auth_factor'
2
3
  require 'onelogin/api/models/device'
3
4
  require 'onelogin/api/models/event'
4
5
  require 'onelogin/api/models/event_type'
6
+ require 'onelogin/api/models/factor_enrollment_response'
5
7
  require 'onelogin/api/models/group'
6
8
  require 'onelogin/api/models/mfa'
7
9
  require 'onelogin/api/models/onelogin_token'
10
+ require 'onelogin/api/models/otp_device'
8
11
  require 'onelogin/api/models/rate_limit'
9
12
  require 'onelogin/api/models/role'
10
13
  require 'onelogin/api/models/saml_endpoint_response'
@@ -53,6 +53,13 @@ module OneLogin
53
53
  GET_SAML_ASSERTION_URL = "https://api.%s.onelogin.com/api/1/saml_assertion"
54
54
  GET_SAML_VERIFY_FACTOR = "https://api.%s.onelogin.com/api/1/saml_assertion/verify_factor"
55
55
 
56
+ # Multi-Factor Authentication URLs
57
+ GET_FACTORS_URL = "https://api.%s.onelogin.com/api/1/users/%s/auth_factors"
58
+ ENROLL_FACTOR_URL = "https://api.%s.onelogin.com/api/1/users/%s/otp_devices"
59
+ GET_ENROLLED_FACTORS_URL = "https://api.%s.onelogin.com/api/1/users/%s/otp_devices"
60
+ ACTIVATE_FACTOR_URL = "https://api.%s.onelogin.com/api/1/users/%s/otp_devices/%s/trigger"
61
+ VERIFY_FACTOR_URL = "https://api.%s.onelogin.com/api/1/users/%s/otp_devices/%s/verify"
62
+
56
63
  # Invite Link URLS
57
64
  GENERATE_INVITE_LINK_URL = "https://api.%s.onelogin.com/api/1/invites/get_invite_link"
58
65
  SEND_INVITE_LINK_URL = "https://api.%s.onelogin.com/api/1/invites/send_invite_link"
@@ -7,12 +7,15 @@ module OneLogin
7
7
  #
8
8
  # @param base [String] Base of the endpoint
9
9
  # @param obj_id [String, nil] Id of the referenced object
10
+ # @param extra_id [String, nil] Id of the secundary referenced object
10
11
  #
11
- def url_for(base, obj_id=nil)
12
+ def url_for(base, obj_id=nil, extra_id=nil)
12
13
  if obj_id.nil? || obj_id.to_s.empty?
13
14
  base % [@region]
14
- else
15
+ elsif extra_id.nil? || extra_id.to_s.empty?
15
16
  base % [@region, obj_id]
17
+ else
18
+ base % [@region, obj_id, extra_id]
16
19
  end
17
20
  end
18
21
  end
@@ -1,3 +1,3 @@
1
1
  module OneLogin
2
- VERSION = "1.0.1"
3
- end
2
+ VERSION = "1.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.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneLogin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -99,19 +99,29 @@ files:
99
99
  - Rakefile
100
100
  - bin/console
101
101
  - bin/setup
102
+ - examples/Gemfile
103
+ - examples/Gemfile.lock
104
+ - examples/README.md
105
+ - examples/all-users-to-csv.rb
106
+ - examples/create-user.rb
107
+ - examples/events-to-csv.rb
108
+ - examples/list-users.rb
102
109
  - lib/onelogin.rb
103
110
  - lib/onelogin/api.rb
104
111
  - lib/onelogin/api/client.rb
105
112
  - lib/onelogin/api/cursor.rb
106
113
  - lib/onelogin/api/models.rb
107
114
  - lib/onelogin/api/models/app.rb
115
+ - lib/onelogin/api/models/auth_factor.rb
108
116
  - lib/onelogin/api/models/device.rb
109
117
  - lib/onelogin/api/models/embed_app.rb
110
118
  - lib/onelogin/api/models/event.rb
111
119
  - lib/onelogin/api/models/event_type.rb
120
+ - lib/onelogin/api/models/factor_enrollment_response.rb
112
121
  - lib/onelogin/api/models/group.rb
113
122
  - lib/onelogin/api/models/mfa.rb
114
123
  - lib/onelogin/api/models/onelogin_token.rb
124
+ - lib/onelogin/api/models/otp_device.rb
115
125
  - lib/onelogin/api/models/rate_limit.rb
116
126
  - lib/onelogin/api/models/role.rb
117
127
  - lib/onelogin/api/models/saml_endpoint_response.rb