Class: OneLogin::Api::Client
- Inherits:
-
Object
- Object
- OneLogin::Api::Client
- Includes:
- HTTParty, Util
- Defined in:
- lib/onelogin/api/client.rb
Overview
Constant Summary collapse
- NOKOGIRI_OPTIONS =
Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NONET
- DEFAULT_USER_AGENT =
"onelogin-ruby-sdk v#{OneLogin::VERSION}".freeze
Constants included from Util::Constants
Util::Constants::ACTIVATE_FACTOR_URL, Util::Constants::ADD_ROLE_TO_USER_URL, Util::Constants::ASSIGN_ROLES_TO_PRIVILEGE_URL, Util::Constants::ASSIGN_USERS_TO_PRIVILEGE_URL, Util::Constants::CREATE_APP_URL, Util::Constants::CREATE_EVENT_URL, Util::Constants::CREATE_GROUP_URL, Util::Constants::CREATE_PRIVILEGE_URL, Util::Constants::CREATE_ROLE_URL, Util::Constants::CREATE_USER_URL, Util::Constants::DELETE_APP_PARAMETER_URL, Util::Constants::DELETE_APP_URL, Util::Constants::DELETE_PRIVILEGE_URL, Util::Constants::DELETE_ROLE_TO_USER_URL, Util::Constants::DELETE_USER_URL, Util::Constants::EMBED_APP_URL, Util::Constants::ENROLL_FACTOR_URL, Util::Constants::GENERATE_INVITE_LINK_URL, Util::Constants::GENERATE_MFA_TOKEN_URL, Util::Constants::GET_APPS_FOR_USER_URL, Util::Constants::GET_APPS_URL, Util::Constants::GET_APPS_URL_V1, Util::Constants::GET_APP_URL, Util::Constants::GET_CONNECTORS_URL, Util::Constants::GET_CUSTOM_ATTRIBUTES_URL, Util::Constants::GET_ENROLLED_FACTORS_URL, Util::Constants::GET_EVENTS_URL, Util::Constants::GET_EVENT_TYPES_URL, Util::Constants::GET_EVENT_URL, Util::Constants::GET_FACTORS_URL, Util::Constants::GET_GROUPS_URL, Util::Constants::GET_GROUP_URL, Util::Constants::GET_PRIVILEGE_URL, Util::Constants::GET_RATE_URL, Util::Constants::GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, Util::Constants::GET_ROLES_FOR_USER_URL, Util::Constants::GET_ROLES_URL, Util::Constants::GET_ROLE_URL, Util::Constants::GET_SAML_ASSERTION_URL, Util::Constants::GET_SAML_VERIFY_FACTOR, Util::Constants::GET_TOKEN_VERIFY_FACTOR, Util::Constants::GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, Util::Constants::GET_USERS_URL, Util::Constants::GET_USER_URL, Util::Constants::LIST_PRIVILEGES_URL, Util::Constants::LOCK_USER_URL, Util::Constants::LOG_USER_OUT_URL, Util::Constants::REMOVE_FACTOR_URL, Util::Constants::REMOVE_ROLE_FROM_PRIVILEGE_URL, Util::Constants::REMOVE_USER_FROM_PRIVILEGE_URL, Util::Constants::SEND_INVITE_LINK_URL, Util::Constants::SESSION_LOGIN_TOKEN_URL, Util::Constants::SET_CUSTOM_ATTRIBUTE_TO_USER_URL, Util::Constants::SET_PW_CLEARTEXT, Util::Constants::SET_PW_SALT, Util::Constants::SET_USER_STATE_URL, Util::Constants::TOKEN_REFRESH_URL, Util::Constants::TOKEN_REQUEST_URL, Util::Constants::TOKEN_REVOKE_URL, Util::Constants::UPDATE_APP_URL, Util::Constants::UPDATE_PRIVILEGE_URL, Util::Constants::UPDATE_USER_URL, Util::Constants::VALID_ACTIONS, Util::Constants::VERIFY_FACTOR_URL
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_attribute ⇒ Object
Returns the value of attribute error_attribute.
-
#error_description ⇒ Object
Returns the value of attribute error_description.
-
#region ⇒ Object
Returns the value of attribute region.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#access_token ⇒ OneLoginToken
Generates an access token and refresh token that you may use to call Onelogin's API methods.
-
#activate_factor(user_id, device_id) ⇒ FactorEnrollmentResponse
Triggers an SMS or Push notification containing a One-Time Password (OTP) that can be used to authenticate a user with the Verify Factor call.
-
#assign_role_to_user(user_id, role_ids) ⇒ Boolean
Assigns Roles to User.
-
#assign_roles_to_privilege(privilege_id, role_ids) ⇒ Boolean
Assign one or more roles to a privilege.
-
#assign_users_to_privilege(privilege_id, user_ids) ⇒ Boolean
Assign one or more users to a privilege.
- #authorized_headers(bearer = true) ⇒ Object
-
#clean_error ⇒ Object
Clean any previous error registered at the client.
-
#create_app(app_params) ⇒ OneLoginApp
Creates an app.
-
#create_event(event_params) ⇒ Boolean
Create an event in the OneLogin event log.
-
#create_privilege(name, version, statements) ⇒ Privilege
Creates a Privilege.
-
#create_session_login_token(query_params, allowed_origin = '') ⇒ SessionTokenInfo|SessionTokenMFAInfo
Generates a session login token in scenarios in which MFA may or may not be required.
-
#create_user(user_params) ⇒ User
Creates an user.
-
#delete_app(app_id) ⇒ Boolean
Deletes an app.
-
#delete_parameter_from_app(app_id, parameter_id) ⇒ Boolean
Deletes an App Parameter.
-
#delete_privilege(privilege_id) ⇒ Boolean
Deletes a Privilege.
-
#delete_user(user_id) ⇒ Boolean
Deletes an user.
-
#enroll_factor(user_id, factor_id, display_name, number) ⇒ OTPDevice
Enroll a user with a given authentication factor.
- #expired? ⇒ Boolean
-
#generate_invite_link(email) ⇒ String
Generates an invite link for a user that you have already created in your OneLogin account.
-
#generate_mfa_token(user_id, expires_in = 259200, reusable = false) ⇒ MFAToken
Use to generate a temporary MFA token that can be used in place of other MFA tokens for a set time period.
-
#get_app(app_id) ⇒ OneLoginApp
Gets a OneLoginApp resource.
-
#get_apps(params = {}) ⇒ Array
Gets a list of OneLoginAppBasic resources.
-
#get_apps_v1(params = {}) ⇒ Array
Gets a list of OneLoginAppV1 resources.
-
#get_connectors(params = {}) ⇒ Array
Gets a list of Connector resources.
-
#get_custom_attributes ⇒ Array
Gets a list of all custom attribute fields (also known as custom user fields) that have been defined for OL account.
-
#get_embed_apps(token, email) ⇒ Array
Lists apps accessible by a OneLogin user.
-
#get_enrolled_factors(user_id) ⇒ Array
Return a list of authentication factors registered to a particular user for multifactor authentication (MFA).
-
#get_event(event_id) ⇒ Event
Gets Event by ID.
-
#get_event_types ⇒ Array
List of all OneLogin event types available to the Events API.
-
#get_events(params = {}) ⇒ Array
Gets a list of Event resources.
-
#get_factors(user_id) ⇒ Array
Returns a list of authentication factors that are available for user enrollment via API.
-
#get_group(group_id) ⇒ Group
Gets Group by ID.
-
#get_groups(params = {}) ⇒ Array
Gets a list of Group resources (element of groups limited with the limit parameter).
-
#get_privilege(privilege_id) ⇒ Privilege
Get a Privilege.
-
#get_privileges ⇒ Array
Gets a list of the Privileges created in an account.
-
#get_rate_limits ⇒ RateLimit
Gets current rate limit details about an access token.
-
#get_role(role_id) ⇒ Role
Gets Role by ID.
-
#get_roles(params = {}) ⇒ Array
Gets a list of Role resources.
-
#get_roles_assigned_to_privilege(privilege_id) ⇒ Array
Gets a list of the roles assigned to a privilege.
-
#get_saml_assertion(username_or_email, password, app_id, subdomain, ip_address = nil) ⇒ SAMLEndpointResponse
Generates a SAML Assertion.
-
#get_saml_assertion_verifying(app_id, device_id, state_token, otp_token = nil, url_endpoint = nil, do_not_notify = false) ⇒ SAMLEndpointResponse
Verify a one-time password (OTP) value provided for a second factor when multi-factor authentication (MFA) is required for SAML authentication.
-
#get_session_token_verified(device_id, state_token, otp_token = nil, allowed_origin = '', do_not_notify = false) ⇒ SessionTokenInfo
Verify a one-time password (OTP) value provided for multi-factor authentication (MFA).
-
#get_user(user_id) ⇒ User
Gets User by ID.
-
#get_user_apps(user_id) ⇒ Array
Gets a list of apps accessible by a user, not including personal apps.
-
#get_user_roles(user_id) ⇒ Array
Gets a list of role IDs that have been assigned to a user.
-
#get_users(params = {}) ⇒ Array
Gets a list of User resources.
-
#get_users_assigned_to_privilege(privilege_id) ⇒ Array
Gets a list of the users assigned to a privilege.
- #handle_operation_response(response) ⇒ Object
- #handle_saml_endpoint_response(response) ⇒ Object
- #handle_session_token_response(response) ⇒ Object
- #headers ⇒ Object
-
#initialize(config) ⇒ Client
constructor
Create a new instance of the Client.
-
#lock_user(user_id, minutes) ⇒ Boolean
Use this call to lock a user's account based on the policy assigned to the user, for a specific time you define in the request, or until you unlock it.
-
#log_user_out(user_id) ⇒ Boolean
Log a user out of any and all sessions.
- #prepare_token ⇒ Object
-
#regenerate_token ⇒ OneLoginToken
Refreshing tokens provides a new set of access and refresh tokens.
-
#remove_factor(user_id, device_id) ⇒ Boolean
Remove an enrolled factor from a user.
-
#remove_role_from_privilege(privilege_id, role_id) ⇒ Boolean
Removes one role from the privilege.
-
#remove_role_from_user(user_id, role_ids) ⇒ Boolean
Removes Role from User.
-
#remove_user_from_privilege(privilege_id, user_id) ⇒ Boolean
Removes one user from the privilege.
- #retrieve_apps_from_xml(xml_content) ⇒ Object
-
#revoke_token ⇒ Boolean
Revokes an access token and refresh token pair.
-
#send_invite_link(email, personal_email = nil) ⇒ String
Sends an invite link to a user that you have already created in your OneLogin account.
-
#set_custom_attribute_to_user(user_id, custom_attributes) ⇒ Boolean
Set Custom Attribute Value.
-
#set_password_using_clear_text(user_id, password, password_confirmation, validate_policy = false) ⇒ Boolean
Sets Password by ID Using Cleartext.
-
#set_password_using_hash_salt(user_id, password, password_confirmation, password_algorithm, password_salt = nil) ⇒ Boolean
Set Password by ID Using Salt and SHA-256.
-
#set_state_to_user(user_id, state) ⇒ Boolean
Set User State.
-
#update_app(app_id, app_params) ⇒ User
Updates an app.
-
#update_privilege(privilege_id, name, version, statements) ⇒ Privilege
Updates a Privilege.
-
#update_user(user_id, user_params) ⇒ User
Updates an user.
- #validate_config ⇒ Object
-
#verify_factor(user_id, device_id, otp_token = nil, state_token = nil) ⇒ Boolean
Authenticates a one-time password (OTP) code provided by a multifactor authentication (MFA) device.
Methods included from Util::Parser
#extract_error_attribute_from_response, #extract_error_message_from_response, #extract_status_code_from_response
Methods included from Util::UrlBuilder
Constructor Details
#initialize(config) ⇒ Client
Create a new instance of the Client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/onelogin/api/client.rb', line 34 def initialize(config) = Hash[config.map { |(k, v)| [k.to_sym, v] }] @client_id = [:client_id] @client_secret = [:client_secret] @region = [:region] || 'us' @max_results = [:max_results] || 1000 if [:timeout] and defined? self.class.default_timeout self.class.default_timeout [:timeout] end if [:proxy_host] self.class.http_proxy [:proxy_host], [:proxy_port], [:proxy_user], [:proxy_pass] end self.class..update(verify: false) validate_config @user_agent = DEFAULT_USER_AGENT end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
22 23 24 |
# File 'lib/onelogin/api/client.rb', line 22 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
22 23 24 |
# File 'lib/onelogin/api/client.rb', line 22 def client_secret @client_secret end |
#error ⇒ Object
Returns the value of attribute error.
23 24 25 |
# File 'lib/onelogin/api/client.rb', line 23 def error @error end |
#error_attribute ⇒ Object
Returns the value of attribute error_attribute.
23 24 25 |
# File 'lib/onelogin/api/client.rb', line 23 def error_attribute @error_attribute end |
#error_description ⇒ Object
Returns the value of attribute error_description.
23 24 25 |
# File 'lib/onelogin/api/client.rb', line 23 def error_description @error_description end |
#region ⇒ Object
Returns the value of attribute region.
22 23 24 |
# File 'lib/onelogin/api/client.rb', line 22 def region @region end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
23 24 25 |
# File 'lib/onelogin/api/client.rb', line 23 def user_agent @user_agent end |
Instance Method Details
#access_token ⇒ OneLoginToken
Generates an access token and refresh token that you may use to call Onelogin's API methods.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/onelogin/api/client.rb', line 165 def access_token clean_error begin url = url_for(TOKEN_REQUEST_URL) data = { 'grant_type' => 'client_credentials' } response = self.class.post( url, headers: (false), body: data.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data.has_key?('status') @error = json_data['status']['code'].to_s @error_description = (response) else token = OneLogin::Api::Models::OneLoginToken.new(json_data) @access_token = token.access_token @refresh_token = token.refresh_token @expiration = token.created_at + token.expires_in return token end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#activate_factor(user_id, device_id) ⇒ FactorEnrollmentResponse
Triggers an SMS or Push notification containing a One-Time Password (OTP) that can be used to authenticate a user with the Verify Factor call.
2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 |
# File 'lib/onelogin/api/client.rb', line 2124 def activate_factor(user_id, device_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end if device_id.nil? || device_id.to_s.empty? @error = '400' @error_description = "device_id is required" @error_attribute = "device_id" return end url = url_for(ACTIVATE_FACTOR_URL, user_id, device_id) response = self.class.post( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::FactorEnrollmentResponse.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#assign_role_to_user(user_id, role_ids) ⇒ Boolean
Assigns Roles to User
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/onelogin/api/client.rb', line 618 def assign_role_to_user(user_id, role_ids) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(ADD_ROLE_TO_USER_URL, user_id) data = { 'role_id_array' => role_ids } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#assign_roles_to_privilege(privilege_id, role_ids) ⇒ Boolean
Assign one or more roles to a privilege.
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 |
# File 'lib/onelogin/api/client.rb', line 2750 def assign_roles_to_privilege(privilege_id, role_ids) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(ASSIGN_ROLES_TO_PRIVILEGE_URL, privilege_id) data = { 'roles' => role_ids } response = self.class.post( url, headers: , body: data.to_json ) if response.code == 201 return handle_operation_response(response) else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#assign_users_to_privilege(privilege_id, user_ids) ⇒ Boolean
Assign one or more users to a privilege.
2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 |
# File 'lib/onelogin/api/client.rb', line 2873 def assign_users_to_privilege(privilege_id, user_ids) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(ASSIGN_USERS_TO_PRIVILEGE_URL, privilege_id) data = { 'users' => user_ids } response = self.class.post( url, headers: , body: data.to_json ) if response.code == 201 return handle_operation_response(response) else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#authorized_headers(bearer = true) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/onelogin/api/client.rb', line 142 def (bearer = true) # Removed the ":" = if bearer "bearer #{@access_token}" else "client_id:#{@client_id},client_secret:#{@client_secret}" end headers.merge({ 'Authorization' => }) end |
#clean_error ⇒ Object
Clean any previous error registered at the client.
63 64 65 66 67 |
# File 'lib/onelogin/api/client.rb', line 63 def clean_error @error = nil @error_description = nil @error_attribute = nil end |
#create_app(app_params) ⇒ OneLoginApp
Creates an app
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 |
# File 'lib/onelogin/api/client.rb', line 1326 def create_app(app_params) clean_error prepare_token begin url = url_for(CREATE_APP_URL) unless app_params.has_key?('connector_id') || app_params['connector_id'].to_s.empty? @error = '400' @error_description = "connector_id is required" @error_attribute = "connector_id" return end response = self.class.post( url, headers: , body: app_params.to_json ) if response.code == 201 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::OneLoginApp.new(json_data) end else @error = extract_status_code_from_response(response) @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#create_event(event_params) ⇒ Boolean
Create an event in the OneLogin event log.
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 |
# File 'lib/onelogin/api/client.rb', line 1734 def create_event(event_params) clean_error prepare_token begin url = url_for(CREATE_EVENT_URL) response = self.class.post( url, headers: , body: event_params.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#create_privilege(name, version, statements) ⇒ Privilege
Creates a Privilege
2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 |
# File 'lib/onelogin/api/client.rb', line 2496 def create_privilege(name, version, statements) clean_error prepare_token begin url = url_for(CREATE_PRIVILEGE_URL) statement_data = [] for statement in statements if statement.instance_of?(OneLogin::Api::Models::Statement) statement_data << { 'Effect' => statement.effect, 'Action' => statement.actions, 'Scope' => statement.scopes } elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope') statement_data << statement else @error = 400.to_s @error_description = "statements is invalid. Provide a list of statements. The statement should be an Statement object or dict with the keys Effect, Action and Scope" return end end privilege_data = { 'name' => name, 'privilege' => { 'Version'=> version, 'Statement' => statement_data } } response = self.class.post( url, headers: , body: privilege_data.to_json ) if response.code == 201 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements) end else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#create_session_login_token(query_params, allowed_origin = '') ⇒ SessionTokenInfo|SessionTokenMFAInfo
Generates a session login token in scenarios in which MFA may or may not be required. A session login token expires two minutes after creation.
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/onelogin/api/client.rb', line 1101 def create_session_login_token(query_params, allowed_origin='') clean_error prepare_token begin url = url_for(SESSION_LOGIN_TOKEN_URL) if query_params.nil? || !query_params.has_key?('username_or_email') || !query_params.has_key?('password') || !query_params.has_key?('subdomain') raise "username_or_email, password and subdomain are required parameters" end headers = if allowed_origin headers = headers.merge({ 'Custom-Allowed-Origin-Header-1' => allowed_origin }) end response = self.class.post( url, headers: headers, body: query_params.to_json ) if response.code == 200 return handle_session_token_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#create_user(user_params) ⇒ User
Creates an user
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/onelogin/api/client.rb', line 528 def create_user(user_params) clean_error prepare_token begin url = url_for(CREATE_USER_URL) response = self.class.post( url, headers: , body: user_params.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::User.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#delete_app(app_id) ⇒ Boolean
Deletes an app
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 |
# File 'lib/onelogin/api/client.rb', line 1460 def delete_app(app_id) clean_error prepare_token begin if app_id.nil? || app_id.to_s.empty? @error = '400' @error_description = "app_id is required" @error_attribute = "app_id" return end url = url_for(DELETE_APP_URL, app_id) response = self.class.delete( url, headers: ) if response.code == 204 return true else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#delete_parameter_from_app(app_id, parameter_id) ⇒ Boolean
Deletes an App Parameter
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 |
# File 'lib/onelogin/api/client.rb', line 1502 def delete_parameter_from_app(app_id, parameter_id) clean_error prepare_token begin if app_id.nil? || app_id.to_s.empty? @error = '400' @error_description = "app_id is required" @error_attribute = "app_id" return end if parameter_id.nil? || parameter_id.to_s.empty? @error = '400' @error_description = "parameter_id is required" @error_attribute = "parameter_id" return end url = url_for(DELETE_APP_PARAMETER_URL, app_id, parameter_id) response = self.class.delete( url, headers: ) if response.code == 204 return true else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#delete_privilege(privilege_id) ⇒ Boolean
Deletes a Privilege
2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 |
# File 'lib/onelogin/api/client.rb', line 2674 def delete_privilege(privilege_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(DELETE_PRIVILEGE_URL, privilege_id) response = self.class.delete( url, headers: ) if response.code == 204 return handle_operation_response(response) else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#delete_user(user_id) ⇒ Boolean
Deletes an user
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
# File 'lib/onelogin/api/client.rb', line 1002 def delete_user(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(DELETE_USER_URL, user_id) response = self.class.delete( url, headers: ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#enroll_factor(user_id, factor_id, display_name, number) ⇒ OTPDevice
Enroll a user with a given authentication factor.
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 |
# File 'lib/onelogin/api/client.rb', line 2018 def enroll_factor(user_id, factor_id, display_name, number) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end if factor_id.nil? || factor_id.to_s.empty? @error = '400' @error_description = "factor_id is required" @error_attribute = "factor_id" return end url = url_for(ENROLL_FACTOR_URL, user_id) data = { 'factor_id'=> factor_id.to_i, 'display_name'=> display_name, 'number'=> number } response = self.class.post( url, :headers => , body: data.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data and json_data['data'] return OneLogin::Api::Models::OTPDevice.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#expired? ⇒ Boolean
69 70 71 |
# File 'lib/onelogin/api/client.rb', line 69 def expired? Time.now.utc > @expiration end |
#generate_invite_link(email) ⇒ String
Generates an invite link for a user that you have already created in your OneLogin account.
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 |
# File 'lib/onelogin/api/client.rb', line 2298 def generate_invite_link(email) clean_error prepare_token begin if email.nil? || email.to_s.empty? @error = '400' @error_description = "email is required" @error_attribute = "email" return end url = url_for(GENERATE_INVITE_LINK_URL) data = { 'email'=> email } response = self.class.post( url, headers: , body: data.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return json_data['data'][0] end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#generate_mfa_token(user_id, expires_in = 259200, reusable = false) ⇒ MFAToken
Use to generate a temporary MFA token that can be used in place of other MFA tokens for a set time period. For example, use this token for account recovery.
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
# File 'lib/onelogin/api/client.rb', line 1047 def generate_mfa_token(user_id, expires_in=259200, reusable=false) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(GENERATE_MFA_TOKEN_URL, user_id) data = { 'expires_in' => expires_in, 'reusable' => reusable } response = self.class.post( url, headers: , body: data.to_json ) if response.code == 201 json_data = JSON.parse(response.body) if !json_data.empty? return OneLogin::Api::Models::MFAToken.new(json_data) end else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_app(app_id) ⇒ OneLoginApp
Gets a OneLoginApp resource.
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 |
# File 'lib/onelogin/api/client.rb', line 1369 def get_app(app_id) clean_error prepare_token begin if app_id.nil? || app_id.to_s.empty? @error = '400' @error_description = "app_id is required" @error_attribute = "app_id" return end url = url_for(GET_APP_URL, app_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::OneLoginApp.new(json_data) end else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_apps(params = {}) ⇒ Array
Gets a list of OneLoginAppBasic resources.
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/onelogin/api/client.rb', line 1283 def get_apps(params = {}) clean_error prepare_token begin url = url_for(GET_APPS_URL) apps = [] response = self.class.get( url, headers: , query: params ) if response.code == 200 json_data = JSON.parse(response.body) if !json_data.empty? json_data.each do |data| apps << OneLogin::Api::Models::OneLoginAppBasic.new(data) end end return apps else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_apps_v1(params = {}) ⇒ Array
Gets a list of OneLoginAppV1 resources. (if no limit provided, by default get 50 elements)
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/onelogin/api/client.rb', line 1254 def get_apps_v1(params = {}) clean_error prepare_token begin = { model: OneLogin::Api::Models::OneLoginAppV1, headers: , max_results: @max_results, params: params } return Cursor.new(self, url_for(GET_APPS_URL_V1), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_connectors(params = {}) ⇒ Array
Gets a list of Connector resources.
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 |
# File 'lib/onelogin/api/client.rb', line 1208 def get_connectors(params = {}) clean_error prepare_token begin url = url_for(GET_CONNECTORS_URL) connectors = [] response = self.class.get( url, headers: , query: params ) if response.code == 200 json_data = JSON.parse(response.body) if !json_data.empty? json_data.each do |data| pp data connectors << OneLogin::Api::Models::ConnectorBasic.new(data) end end return connectors else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_custom_attributes ⇒ Array
Gets a list of all custom attribute fields (also known as custom user fields) that have been defined for OL account.
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/onelogin/api/client.rb', line 484 def get_custom_attributes clean_error prepare_token begin url = url_for(GET_CUSTOM_ATTRIBUTES_URL) response = self.class.get( url, headers: ) custom_attributes = [] if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] custom_attributes = json_data['data'][0] end else @error = response.code.to_s @error_description = (response) end return custom_attributes rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_embed_apps(token, email) ⇒ Array
Lists apps accessible by a OneLogin user.
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 |
# File 'lib/onelogin/api/client.rb', line 2392 def (token, email) clean_error begin response = self.class.get( EMBED_APP_URL, headers: { 'User-Agent' => @user_agent }, query: { token: token, email: email } ) if response.code == 200 && !(response.body.nil? || response.body.empty?) return retrieve_apps_from_xml(response.body) else @error = response.code.to_s unless response.body.nil? || response.body.empty? @error_description = response.body end end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_enrolled_factors(user_id) ⇒ Array
Return a list of authentication factors registered to a particular user for multifactor authentication (MFA)
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 |
# File 'lib/onelogin/api/client.rb', line 2075 def get_enrolled_factors(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(GET_ENROLLED_FACTORS_URL, user_id) response = self.class.get( url, :headers => ) otp_devices = [] if response.code == 200 json_data = JSON.parse(response.body) if json_data and json_data['data'] and json_data['data']['otp_devices'] json_data['data']['otp_devices'].each do |otp_device_data| otp_devices << OneLogin::Api::Models::OTPDevice.new(otp_device_data) end end else @error = response.code.to_s @error_description = (response) end return otp_devices rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_event(event_id) ⇒ Event
Gets Event by ID.
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 |
# File 'lib/onelogin/api/client.rb', line 1685 def get_event(event_id) clean_error prepare_token begin if event_id.nil? || event_id.to_s.empty? @error = '400' @error_description = "event_id is required" @error_attribute = "event_id" return end url = url_for(GET_EVENT_URL, event_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::Event.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_event_types ⇒ Array
List of all OneLogin event types available to the Events API.
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 |
# File 'lib/onelogin/api/client.rb', line 1628 def get_event_types clean_error prepare_token begin = { model: OneLogin::Api::Models::EventType, headers: , max_results: @max_results } return Cursor.new(self, url_for(GET_EVENT_TYPES_URL), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_events(params = {}) ⇒ Array
Gets a list of Event resources. (if no limit provided, by default get 50 elements)
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 |
# File 'lib/onelogin/api/client.rb', line 1656 def get_events(params={}) clean_error prepare_token begin = { model: OneLogin::Api::Models::Event, headers: , max_results: @max_results, params: params } return Cursor.new(self, url_for(GET_EVENTS_URL), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_factors(user_id) ⇒ Array
Returns a list of authentication factors that are available for user enrollment via API.
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 |
# File 'lib/onelogin/api/client.rb', line 1968 def get_factors(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(GET_FACTORS_URL, user_id) response = self.class.get( url, :headers => ) factors = [] if response.code == 200 json_data = JSON.parse(response.body) if json_data and json_data['data'] and json_data['data']['auth_factors'] json_data['data']['auth_factors'].each do |factor_data| factors << OneLogin::Api::Models::AuthFactor.new(factor_data) end end else @error = response.code.to_s @error_description = (response) end return factors rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_group(group_id) ⇒ Group
Gets Group by ID.
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 |
# File 'lib/onelogin/api/client.rb', line 1800 def get_group(group_id) clean_error prepare_token begin if group_id.nil? || group_id.to_s.empty? @error = '400' @error_description = "group_id is required" @error_attribute = "group_id" return end url = url_for(GET_GROUP_URL, group_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::Group.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_groups(params = {}) ⇒ Array
Gets a list of Group resources (element of groups limited with the limit parameter).
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 |
# File 'lib/onelogin/api/client.rb', line 1771 def get_groups(params = {}) clean_error prepare_token begin = { model: OneLogin::Api::Models::Group, headers: , max_results: @max_results, params: params } return Cursor.new(self, url_for(GET_GROUPS_URL), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_privilege(privilege_id) ⇒ Privilege
Get a Privilege.
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 |
# File 'lib/onelogin/api/client.rb', line 2558 def get_privilege(privilege_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(GET_PRIVILEGE_URL, privilege_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::Privilege.new(json_data) end else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_privileges ⇒ Array
Gets a list of the Privileges created in an account.
2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 |
# File 'lib/onelogin/api/client.rb', line 2453 def get_privileges() clean_error prepare_token begin url = url_for(LIST_PRIVILEGES_URL) privileges = [] response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if !json_data.empty? json_data.each do |data| privileges << OneLogin::Api::Models::Privilege.new(data) end end return privileges else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_rate_limits ⇒ RateLimit
Gets current rate limit details about an access token.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/onelogin/api/client.rb', line 295 def get_rate_limits clean_error prepare_token begin url = url_for(GET_RATE_URL) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::RateLimit.new(json_data['data']) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_role(role_id) ⇒ Role
Gets Role by ID.
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/onelogin/api/client.rb', line 1583 def get_role(role_id) clean_error prepare_token begin if role_id.nil? || role_id.to_s.empty? @error = '400' @error_description = "role_id is required" @error_attribute = "role_id" return end url = url_for(GET_ROLE_URL, role_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::Role.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_roles(params = {}) ⇒ Array
Gets a list of Role resources. (if no limit provided, by default get 50 elements)
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 |
# File 'lib/onelogin/api/client.rb', line 1554 def get_roles(params = {}) clean_error prepare_token begin = { model: OneLogin::Api::Models::Role, headers: , max_results: @max_results, params: params } return Cursor.new(self, url_for(GET_ROLES_URL), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_roles_assigned_to_privilege(privilege_id) ⇒ Array
Gets a list of the roles assigned to a privilege.
2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 |
# File 'lib/onelogin/api/client.rb', line 2714 def get_roles_assigned_to_privilege(privilege_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end = { headers: , max_results: @max_results, container: 'roles' } return Cursor.new(self, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_saml_assertion(username_or_email, password, app_id, subdomain, ip_address = nil) ⇒ SAMLEndpointResponse
Generates a SAML Assertion.
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 |
# File 'lib/onelogin/api/client.rb', line 1851 def get_saml_assertion(username_or_email, password, app_id, subdomain, ip_address=nil) clean_error prepare_token begin url = url_for(GET_SAML_ASSERTION_URL) data = { 'username_or_email'=> username_or_email, 'password'=> password, 'app_id'=> app_id, 'subdomain'=> subdomain, } unless ip_address.nil? || ip_address.empty? data['ip_address'] = ip_address end response = self.class.post( url, headers: , body: data.to_json ) if response.code == 200 return handle_saml_endpoint_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_saml_assertion_verifying(app_id, device_id, state_token, otp_token = nil, url_endpoint = nil, do_not_notify = false) ⇒ SAMLEndpointResponse
Verify a one-time password (OTP) value provided for a second factor when multi-factor authentication (MFA) is required for SAML authentication.
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 |
# File 'lib/onelogin/api/client.rb', line 1901 def (app_id, device_id, state_token, otp_token=nil, url_endpoint=nil, do_not_notify=false) clean_error prepare_token begin if app_id.nil? || app_id.to_s.empty? @error = '400' @error_description = "app_id is required" @error_attribute = "app_id" return end if device_id.nil? || device_id.to_s.empty? @error = '400' @error_description = "device_id is required" @error_attribute = "device_id" return end if url_endpoint.nil? || url_endpoint.empty? url = url_for(GET_SAML_VERIFY_FACTOR) else url = url_endpoint end data = { 'app_id'=> app_id, 'device_id'=> device_id.to_s, 'state_token'=> state_token, 'do_not_notify'=> do_not_notify } unless otp_token.nil? || otp_token.empty? data['otp_token'] = otp_token end response = self.class.post( url, headers: , body: data.to_json ) if response.code == 200 return handle_saml_endpoint_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_session_token_verified(device_id, state_token, otp_token = nil, allowed_origin = '', do_not_notify = false) ⇒ SessionTokenInfo
Verify a one-time password (OTP) value provided for multi-factor authentication (MFA).
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 |
# File 'lib/onelogin/api/client.rb', line 1148 def get_session_token_verified(device_id, state_token, otp_token=nil, allowed_origin='', do_not_notify=false) clean_error prepare_token begin if device_id.nil? || device_id.to_s.empty? @error = '400' @error_description = "device_id is required" @error_attribute = "device_id" return end url = url_for(GET_TOKEN_VERIFY_FACTOR) data = { 'device_id'=> device_id.to_s, 'state_token'=> state_token, 'do_not_notify'=> do_not_notify } unless otp_token.nil? || otp_token.empty? data['otp_token'] = otp_token end headers = if allowed_origin headers = headers.merge({ 'Custom-Allowed-Origin-Header-1' => allowed_origin }) end response = self.class.post( url, headers: headers, body: data.to_json ) if response.code == 200 return handle_session_token_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_user(user_id) ⇒ User
Gets User by ID.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/onelogin/api/client.rb', line 364 def get_user(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(GET_USER_URL, user_id) response = self.class.get( url, headers: ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::User.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_user_apps(user_id) ⇒ Array
Gets a list of apps accessible by a user, not including personal apps.
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/onelogin/api/client.rb', line 407 def get_user_apps(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end = { model: OneLogin::Api::Models::App, headers: , max_results: @max_results } return Cursor.new(self, url_for(GET_APPS_FOR_USER_URL, user_id), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_user_roles(user_id) ⇒ Array
Gets a list of role IDs that have been assigned to a user.
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/onelogin/api/client.rb', line 442 def get_user_roles(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(GET_ROLES_FOR_USER_URL, user_id) response = self.class.get( url, headers: ) role_ids = [] if response.code == 200 json_data = JSON.parse(response.body) role_ids = json_data['data'][0] if json_data && json_data['data'] else @error = response.code.to_s @error_description = (response) end return role_ids rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_users(params = {}) ⇒ Array
Gets a list of User resources. (if no limit provided, by default gt 50 elements)
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/onelogin/api/client.rb', line 335 def get_users(params = {}) clean_error prepare_token begin = { model: OneLogin::Api::Models::User, headers: , max_results: @max_results, params: params } return Cursor.new(self, url_for(GET_USERS_URL), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#get_users_assigned_to_privilege(privilege_id) ⇒ Array
Gets a list of the users assigned to a privilege.
2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 |
# File 'lib/onelogin/api/client.rb', line 2837 def get_users_assigned_to_privilege(privilege_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end = { headers: , max_results: @max_results, container: 'users' } return Cursor.new(self, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), ) rescue Exception => e @error = '500' @error_description = e. end nil end |
#handle_operation_response(response) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/onelogin/api/client.rb', line 81 def handle_operation_response(response) result = false begin content = JSON.parse(response.body) if content if content.has_key?('status') && content['status'].has_key?('type') && content['status']['type'] == "success" result = true elsif content.has_key?('success') && content['success'] result = true end end rescue Exception => e result = false end result end |
#handle_saml_endpoint_response(response) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/onelogin/api/client.rb', line 114 def handle_saml_endpoint_response(response) content = JSON.parse(response.body) if content && content.has_key?('status') && content['status'].has_key?('message') && content['status'].has_key?('type') status_type = content['status']['type'] = content['status']['message'] saml_endpoint_response = OneLogin::Api::Models::SAMLEndpointResponse.new(status_type, ) if content.has_key?('data') if == 'Success' saml_endpoint_response.saml_response = content['data'] else mfa = OneLogin::Api::Models::MFA.new(content['data'][0]) saml_endpoint_response.mfa = mfa end end return saml_endpoint_response end nil end |
#handle_session_token_response(response) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/onelogin/api/client.rb', line 99 def handle_session_token_response(response) content = JSON.parse(response.body) if content && content.has_key?('status') && content['status'].has_key?('message') && content.has_key?('data') if content['status']['message'] == "Success" return OneLogin::Api::Models::SessionTokenInfo.new(content['data'][0]) elsif content['status']['message'] == "MFA is required for this user" return OneLogin::Api::Models::SessionTokenMFAInfo.new(content['data'][0]) else raise "Status Message type not reognized: %s" % content['status']['message'] end end nil end |
#headers ⇒ Object
135 136 137 138 139 140 |
# File 'lib/onelogin/api/client.rb', line 135 def headers { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent } end |
#lock_user(user_id, minutes) ⇒ Boolean
Use this call to lock a user's account based on the policy assigned to the user, for a specific time you define in the request, or until you unlock it.
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
# File 'lib/onelogin/api/client.rb', line 956 def lock_user(user_id, minutes) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(LOCK_USER_URL, user_id) data = { 'locked_until' => minutes } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#log_user_out(user_id) ⇒ Boolean
Log a user out of any and all sessions.
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 |
# File 'lib/onelogin/api/client.rb', line 912 def log_user_out(user_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(LOG_USER_OUT_URL, user_id) response = self.class.put( url, headers: ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#prepare_token ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/onelogin/api/client.rb', line 73 def prepare_token if @access_token.nil? access_token elsif expired? regenerate_token end end |
#regenerate_token ⇒ OneLoginToken
Refreshing tokens provides a new set of access and refresh tokens.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/onelogin/api/client.rb', line 210 def regenerate_token clean_error begin url = url_for(TOKEN_REQUEST_URL) data = { 'grant_type' => 'refresh_token', 'access_token' => @access_token, 'refresh_token' => @refresh_token } response = self.class.post( url, headers: headers, body: data.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data.has_key?('status') @error = json_data['status']['code'].to_s @error_description = (response) else token = OneLogin::Api::Models::OneLoginToken.new(json_data) @access_token = token.access_token @refresh_token = token.refresh_token @expiration = token.created_at + token.expires_in return token end else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#remove_factor(user_id, device_id) ⇒ Boolean
Remove an enrolled factor from a user.
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 |
# File 'lib/onelogin/api/client.rb', line 2245 def remove_factor(user_id, device_id) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end if device_id.nil? || device_id.to_s.empty? @error = '400' @error_description = "device_id is required" @error_attribute = "device_id" return end url = url_for(REMOVE_FACTOR_URL, user_id, device_id) response = self.class.delete( url, :headers => ) if response.code == 200 return true else @error = response.code.to_s @error_description = (response) return false end rescue Exception => e @error = '500' @error_description = e. end nil end |
#remove_role_from_privilege(privilege_id, role_id) ⇒ Boolean
Removes one role from the privilege.
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 |
# File 'lib/onelogin/api/client.rb', line 2797 def remove_role_from_privilege(privilege_id, role_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(REMOVE_ROLE_FROM_PRIVILEGE_URL, privilege_id, role_id) response = self.class.delete( url, headers: ) if response.code == 204 return true else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#remove_role_from_user(user_id, role_ids) ⇒ Boolean
Removes Role from User
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/onelogin/api/client.rb', line 665 def remove_role_from_user(user_id, role_ids) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(DELETE_ROLE_TO_USER_URL, user_id) data = { 'role_id_array' => role_ids } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#remove_user_from_privilege(privilege_id, user_id) ⇒ Boolean
Removes one user from the privilege.
2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 |
# File 'lib/onelogin/api/client.rb', line 2919 def remove_user_from_privilege(privilege_id, user_id) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(REMOVE_USER_FROM_PRIVILEGE_URL, privilege_id, user_id) response = self.class.delete( url, headers: ) if response.code == 204 return true else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#retrieve_apps_from_xml(xml_content) ⇒ Object
2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 |
# File 'lib/onelogin/api/client.rb', line 2423 def retrieve_apps_from_xml(xml_content) doc = Nokogiri::XML(xml_content) do |config| config. = NOKOGIRI_OPTIONS end node_list = doc.xpath("/apps/app") attributes = ['id', 'icon', 'name', 'provisioned', 'extension_required', 'personal', 'login_id'] apps = [] node_list.each do |node| app_data = {} node.children.each do |children| if attributes.include? children.name app_data[children.name] = children.content end end apps << OneLogin::Api::Models::EmbedApp.new(app_data) end apps end |
#revoke_token ⇒ Boolean
Revokes an access token and refresh token pair.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/onelogin/api/client.rb', line 257 def revoke_token clean_error begin url = url_for(TOKEN_REVOKE_URL) data = { access_token: @access_token } response = self.class.post( url, headers: (false), body: data.to_json ) if response.code == 200 @access_token = nil @refresh_token = nil @expiration = nil return true else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#send_invite_link(email, personal_email = nil) ⇒ String
Sends an invite link to a user that you have already created in your OneLogin account.
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 |
# File 'lib/onelogin/api/client.rb', line 2349 def send_invite_link(email, personal_email=nil) clean_error prepare_token begin url = url_for(SEND_INVITE_LINK_URL) data = { 'email'=> email } unless personal_email.nil? || personal_email.to_s.empty? data['personal_email'] = personal_email end response = self.class.post( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#set_custom_attribute_to_user(user_id, custom_attributes) ⇒ Boolean
Set Custom Attribute Value
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/onelogin/api/client.rb', line 866 def set_custom_attribute_to_user(user_id, custom_attributes) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(SET_CUSTOM_ATTRIBUTE_TO_USER_URL, user_id) data = { 'custom_attributes' => custom_attributes } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#set_password_using_clear_text(user_id, password, password_confirmation, validate_policy = false) ⇒ Boolean
Sets Password by ID Using Cleartext
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
# File 'lib/onelogin/api/client.rb', line 714 def set_password_using_clear_text(user_id, password, password_confirmation, validate_policy=false) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(SET_PW_CLEARTEXT, user_id) data = { 'password' => password, 'password_confirmation' => password_confirmation, 'validate_policy' => validate_policy } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#set_password_using_hash_salt(user_id, password, password_confirmation, password_algorithm, password_salt = nil) ⇒ Boolean
Set Password by ID Using Salt and SHA-256
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/onelogin/api/client.rb', line 766 def set_password_using_hash_salt(user_id, password, password_confirmation, password_algorithm, password_salt=nil) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(SET_PW_SALT, user_id) data = { 'password' => password, 'password_confirmation' => password_confirmation, 'password_algorithm' => password_algorithm } unless password_salt.nil? data['password_salt'] = password_salt end response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#set_state_to_user(user_id, state) ⇒ Boolean
Set User State
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/onelogin/api/client.rb', line 819 def set_state_to_user(user_id, state) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(SET_USER_STATE_URL, user_id) data = { 'state' => state } response = self.class.put( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end false end |
#update_app(app_id, app_params) ⇒ User
Updates an app
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 |
# File 'lib/onelogin/api/client.rb', line 1415 def update_app(app_id, app_params) clean_error prepare_token begin if app_id.nil? || app_id.to_s.empty? @error = '400' @error_description = "app_id is required" @error_attribute = "app_id" return end url = url_for(UPDATE_APP_URL, app_id) response = self.class.put( url, headers: , body: app_params.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::OneLoginApp.new(json_data) end else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#update_privilege(privilege_id, name, version, statements) ⇒ Privilege
Updates a Privilege
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 |
# File 'lib/onelogin/api/client.rb', line 2605 def update_privilege(privilege_id, name, version, statements) clean_error prepare_token begin if privilege_id.nil? || privilege_id.to_s.empty? @error = '400' @error_description = "privilege_id is required" @error_attribute = "privilege_id" return end url = url_for(UPDATE_PRIVILEGE_URL, privilege_id) statement_data = [] for statement in statements if statement.instance_of?(OneLogin::Api::Models::Statement) statement_data << { 'Effect' => statement.effect, 'Action' => statement.actions, 'Scope' => statement.scopes } elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope') statement_data << statement else @error = 400.to_s @error_description = "statements is invalid. Provide a list of statements. The statement should be an Statement object or dict with the keys Effect, Action and Scope" return end end privilege_data = { 'name' => name, 'privilege' => { 'Version'=> version, 'Statement' => statement_data } } response = self.class.put( url, headers: , body: privilege_data.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data.has_key?('id') return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements) end else @error = extract_status_code_from_response(response) @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#update_user(user_id, user_params) ⇒ User
Updates an user
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/onelogin/api/client.rb', line 572 def update_user(user_id, user_params) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end url = url_for(UPDATE_USER_URL, user_id) response = self.class.put( url, headers: , body: user_params.to_json ) if response.code == 200 json_data = JSON.parse(response.body) if json_data && json_data['data'] return OneLogin::Api::Models::User.new(json_data['data'][0]) end else @error = response.code.to_s @error_description = (response) @error_attribute = extract_error_attribute_from_response(response) end rescue Exception => e @error = '500' @error_description = e. end nil end |
#validate_config ⇒ Object
57 58 59 |
# File 'lib/onelogin/api/client.rb', line 57 def validate_config raise ArgumentError, 'client_id & client_secret are required' unless @client_id && @client_secret end |
#verify_factor(user_id, device_id, otp_token = nil, state_token = nil) ⇒ Boolean
Authenticates a one-time password (OTP) code provided by a multifactor authentication (MFA) device.
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 |
# File 'lib/onelogin/api/client.rb', line 2182 def verify_factor(user_id, device_id, otp_token=nil, state_token=nil) clean_error prepare_token begin if user_id.nil? || user_id.to_s.empty? @error = '400' @error_description = "user_id is required" @error_attribute = "user_id" return end if device_id.nil? || device_id.to_s.empty? @error = '400' @error_description = "device_id is required" @error_attribute = "device_id" return end url = url_for(VERIFY_FACTOR_URL, user_id, device_id) data = { 'user_id'=> user_id, 'device_id'=> device_id } unless otp_token.nil? || otp_token.empty? data['otp_token'] = otp_token end unless state_token.nil? || state_token.empty? data['state_token'] = state_token end response = self.class.post( url, headers: , body: data.to_json ) if response.code == 200 return handle_operation_response(response) else @error = response.code.to_s @error_description = (response) end rescue Exception => e @error = '500' @error_description = e. end false end |