onelogin 1.6.0 → 3.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +7 -4
- data/README.md +245 -484
- data/Rakefile +7 -3
- data/docs/Action.md +26 -0
- data/docs/ActivateFactorRequest.md +24 -0
- data/docs/AddAccessTokenClaimRequest.md +22 -0
- data/docs/AddClientAppRequest.md +20 -0
- data/docs/AddRoleUsers200ResponseInner.md +18 -0
- data/docs/AddScopeRequest.md +20 -0
- data/docs/AuthMethod.md +15 -0
- data/docs/AuthServerConfiguration.md +24 -0
- data/docs/ClientApp.md +20 -0
- data/docs/Condition.md +22 -0
- data/docs/Connector.md +26 -0
- data/docs/CreateAuthorizationServerRequest.md +22 -0
- data/docs/CreateEnvironmentVariableRequest.md +20 -0
- data/docs/CreateRoles201ResponseInner.md +18 -0
- data/docs/DefaultApi.md +6812 -0
- data/docs/Device.md +26 -0
- data/docs/EnrollFactorRequest.md +28 -0
- data/docs/Envvar.md +24 -0
- data/docs/ErrorStatus.md +22 -0
- data/docs/ErrorStatusErrorsInner.md +20 -0
- data/docs/FactorInner.md +32 -0
- data/docs/FactorInnerFactorData.md +20 -0
- data/docs/GenerateMfaToken200Response.md +24 -0
- data/docs/GenerateMfaToken422Response.md +24 -0
- data/docs/GenerateMfaToken422ResponseDetails.md +18 -0
- data/docs/GenerateMfaTokenRequest.md +20 -0
- data/docs/GenerateSamlAssertionRequest.md +26 -0
- data/docs/GenerateToken200Response.md +28 -0
- data/docs/GenerateToken400Response.md +18 -0
- data/docs/GenerateTokenRequest.md +18 -0
- data/docs/GetAuthorizationServer200Response.md +24 -0
- data/docs/GetAvailableFactors200ResponseInner.md +22 -0
- data/docs/GetClientApps200ResponseInner.md +24 -0
- data/docs/GetClientApps200ResponseInnerScopesInner.md +22 -0
- data/docs/GetRateLimit200Response.md +20 -0
- data/docs/GetRateLimit200ResponseData.md +22 -0
- data/docs/GetRiskScore200Response.md +20 -0
- data/docs/GetRiskScore400Response.md +18 -0
- data/docs/GetRiskScoreRequest.md +30 -0
- data/docs/GetScoreInsights200Response.md +20 -0
- data/docs/GetScoreInsights200ResponseScores.md +26 -0
- data/docs/GetUserApps200ResponseInner.md +32 -0
- data/docs/Hook.md +46 -0
- data/docs/HookConditionsInner.md +22 -0
- data/docs/HookOptions.md +22 -0
- data/docs/HookStatus.md +20 -0
- data/docs/Id.md +18 -0
- data/docs/ListAccessTokenClaims200ResponseInner.md +34 -0
- data/docs/ListActions200ResponseInner.md +20 -0
- data/docs/ListAppUsers200ResponseInner.md +26 -0
- data/docs/ListAuthorizationServers200ResponseInner.md +24 -0
- data/docs/ListAuthorizationServers200ResponseInnerConfiguration.md +20 -0
- data/docs/ListConditionOperators200ResponseInner.md +20 -0
- data/docs/ListConditionValues200ResponseInner.md +20 -0
- data/docs/ListConditions200ResponseInner.md +20 -0
- data/docs/ListMappingConditionOperators200ResponseInner.md +20 -0
- data/docs/ListMappingConditions200ResponseInner.md +20 -0
- data/docs/ListScopes200ResponseInner.md +22 -0
- data/docs/Log.md +24 -0
- data/docs/Mapping.md +30 -0
- data/docs/Registration.md +22 -0
- data/docs/RemoveRoleUsersRequest.md +18 -0
- data/docs/RevokeTokenRequest.md +18 -0
- data/docs/RiskDevice.md +18 -0
- data/docs/RiskRule.md +30 -0
- data/docs/RiskUser.md +22 -0
- data/docs/Role.md +26 -0
- data/docs/Rule.md +30 -0
- data/docs/RuleId.md +18 -0
- data/docs/Schema.md +56 -0
- data/docs/Schema1.md +28 -0
- data/docs/Schema1AddedBy.md +20 -0
- data/docs/SchemaProvisioning.md +18 -0
- data/docs/Session.md +18 -0
- data/docs/SetRoleApps200ResponseInner.md +18 -0
- data/docs/Source.md +20 -0
- data/docs/Status.md +24 -0
- data/docs/Status1.md +22 -0
- data/docs/Status2.md +18 -0
- data/docs/Status2Status.md +24 -0
- data/docs/TrackEventRequest.md +34 -0
- data/docs/UpdateAuthorizationServer400Response.md +24 -0
- data/docs/UpdateClientAppRequest.md +18 -0
- data/docs/UpdateEnvironmentVariableRequest.md +18 -0
- data/docs/UpdateRole200Response.md +18 -0
- data/docs/User.md +90 -0
- data/docs/VerifyEnrollmentRequest.md +18 -0
- data/docs/VerifyFactorRequest.md +20 -0
- data/docs/VerifyFactorSaml200Response.md +20 -0
- data/docs/VerifyFactorSamlRequest.md +26 -0
- data/docs/VerifyFactorVoice200ResponseInner.md +22 -0
- data/git_push.sh +57 -0
- data/lib/onelogin/api/default_api.rb +7334 -0
- data/lib/onelogin/api_client.rb +391 -0
- data/lib/onelogin/api_error.rb +57 -0
- data/lib/onelogin/configuration.rb +282 -0
- data/lib/onelogin/models/action.rb +262 -0
- data/lib/onelogin/models/activate_factor_request.rb +250 -0
- data/lib/onelogin/models/add_access_token_claim_request.rb +237 -0
- data/lib/onelogin/models/add_client_app_request.rb +230 -0
- data/lib/onelogin/models/add_role_users200_response_inner.rb +219 -0
- data/lib/onelogin/models/add_scope_request.rb +228 -0
- data/lib/onelogin/models/auth_method.rb +43 -0
- data/lib/onelogin/models/auth_server_configuration.rb +248 -0
- data/lib/onelogin/models/client_app.rb +228 -0
- data/lib/onelogin/models/condition.rb +240 -0
- data/lib/onelogin/models/connector.rb +259 -0
- data/lib/onelogin/models/create_authorization_server_request.rb +237 -0
- data/lib/onelogin/models/create_environment_variable_request.rb +240 -0
- data/lib/onelogin/models/create_roles201_response_inner.rb +219 -0
- data/lib/onelogin/models/device.rb +255 -0
- data/lib/onelogin/models/enroll_factor_request.rb +280 -0
- data/lib/onelogin/models/envvar.rb +250 -0
- data/lib/onelogin/models/error_status.rb +239 -0
- data/lib/onelogin/models/error_status_errors_inner.rb +230 -0
- data/lib/onelogin/models/factor_inner.rb +323 -0
- data/lib/onelogin/models/factor_inner_factor_data.rb +231 -0
- data/lib/onelogin/models/generate_mfa_token200_response.rb +250 -0
- data/lib/onelogin/models/generate_mfa_token422_response.rb +246 -0
- data/lib/onelogin/models/generate_mfa_token422_response_details.rb +221 -0
- data/lib/onelogin/models/generate_mfa_token_request.rb +230 -0
- data/lib/onelogin/models/generate_saml_assertion_request.rb +280 -0
- data/lib/onelogin/models/generate_token200_response.rb +264 -0
- data/lib/onelogin/models/generate_token400_response.rb +219 -0
- data/lib/onelogin/models/generate_token_request.rb +253 -0
- data/lib/onelogin/models/get_authorization_server200_response.rb +246 -0
- data/lib/onelogin/models/get_available_factors200_response_inner.rb +240 -0
- data/lib/onelogin/models/get_client_apps200_response_inner.rb +248 -0
- data/lib/onelogin/models/get_client_apps200_response_inner_scopes_inner.rb +237 -0
- data/lib/onelogin/models/get_rate_limit200_response.rb +228 -0
- data/lib/onelogin/models/get_rate_limit200_response_data.rb +237 -0
- data/lib/onelogin/models/get_risk_score200_response.rb +256 -0
- data/lib/onelogin/models/get_risk_score400_response.rb +221 -0
- data/lib/onelogin/models/get_risk_score_request.rb +291 -0
- data/lib/onelogin/models/get_score_insights200_response.rb +228 -0
- data/lib/onelogin/models/get_score_insights200_response_scores.rb +255 -0
- data/lib/onelogin/models/get_user_apps200_response_inner.rb +335 -0
- data/lib/onelogin/models/hook.rb +462 -0
- data/lib/onelogin/models/hook_conditions_inner.rb +237 -0
- data/lib/onelogin/models/hook_options.rb +238 -0
- data/lib/onelogin/models/hook_status.rb +228 -0
- data/lib/onelogin/models/id.rb +219 -0
- data/lib/onelogin/models/list_access_token_claims200_response_inner.rb +293 -0
- data/lib/onelogin/models/list_actions200_response_inner.rb +230 -0
- data/lib/onelogin/models/list_app_users200_response_inner.rb +255 -0
- data/lib/onelogin/models/list_authorization_servers200_response_inner.rb +246 -0
- data/lib/onelogin/models/list_authorization_servers200_response_inner_configuration.rb +230 -0
- data/lib/onelogin/models/list_condition_operators200_response_inner.rb +230 -0
- data/lib/onelogin/models/list_condition_values200_response_inner.rb +228 -0
- data/lib/onelogin/models/list_conditions200_response_inner.rb +230 -0
- data/lib/onelogin/models/list_mapping_condition_operators200_response_inner.rb +230 -0
- data/lib/onelogin/models/list_mapping_conditions200_response_inner.rb +230 -0
- data/lib/onelogin/models/list_scopes200_response_inner.rb +237 -0
- data/lib/onelogin/models/log.rb +248 -0
- data/lib/onelogin/models/mapping.rb +342 -0
- data/lib/onelogin/models/registration.rb +274 -0
- data/lib/onelogin/models/remove_role_users_request.rb +221 -0
- data/lib/onelogin/models/revoke_token_request.rb +219 -0
- data/lib/onelogin/models/risk_device.rb +221 -0
- data/lib/onelogin/models/risk_rule.rb +325 -0
- data/lib/onelogin/models/risk_user.rb +248 -0
- data/lib/onelogin/models/role.rb +266 -0
- data/lib/onelogin/models/rule.rb +317 -0
- data/lib/onelogin/models/rule_id.rb +219 -0
- data/lib/onelogin/models/schema.rb +441 -0
- data/lib/onelogin/models/schema1.rb +265 -0
- data/lib/onelogin/models/schema1_added_by.rb +228 -0
- data/lib/onelogin/models/schema_provisioning.rb +220 -0
- data/lib/onelogin/models/session.rb +221 -0
- data/lib/onelogin/models/set_role_apps200_response_inner.rb +220 -0
- data/lib/onelogin/models/source.rb +230 -0
- data/lib/onelogin/models/status.rb +246 -0
- data/lib/onelogin/models/status1.rb +237 -0
- data/lib/onelogin/models/status2.rb +219 -0
- data/lib/onelogin/models/status2_status.rb +246 -0
- data/lib/onelogin/models/track_event_request.rb +316 -0
- data/lib/onelogin/models/update_authorization_server400_response.rb +246 -0
- data/lib/onelogin/models/update_client_app_request.rb +221 -0
- data/lib/onelogin/models/update_environment_variable_request.rb +225 -0
- data/lib/onelogin/models/update_role200_response.rb +219 -0
- data/lib/onelogin/models/user.rb +615 -0
- data/lib/onelogin/models/verify_enrollment_request.rb +219 -0
- data/lib/onelogin/models/verify_factor_request.rb +230 -0
- data/lib/onelogin/models/verify_factor_saml200_response.rb +230 -0
- data/lib/onelogin/models/verify_factor_saml_request.rb +275 -0
- data/lib/onelogin/models/verify_factor_voice200_response_inner.rb +271 -0
- data/lib/onelogin/version.rb +13 -1
- data/lib/onelogin.rb +130 -1
- data/onelogin.gemspec +35 -42
- data/spec/api/default_api_spec.rb +1259 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/action_spec.rb +58 -0
- data/spec/models/activate_factor_request_spec.rb +52 -0
- data/spec/models/add_access_token_claim_request_spec.rb +46 -0
- data/spec/models/add_client_app_request_spec.rb +40 -0
- data/spec/models/add_role_users200_response_inner_spec.rb +34 -0
- data/spec/models/add_scope_request_spec.rb +40 -0
- data/spec/models/auth_method_spec.rb +28 -0
- data/spec/models/auth_server_configuration_spec.rb +52 -0
- data/spec/models/client_app_spec.rb +40 -0
- data/spec/models/condition_spec.rb +46 -0
- data/spec/models/connector_spec.rb +58 -0
- data/spec/models/create_authorization_server_request_spec.rb +46 -0
- data/spec/models/create_environment_variable_request_spec.rb +40 -0
- data/spec/models/create_roles201_response_inner_spec.rb +34 -0
- data/spec/models/device_spec.rb +58 -0
- data/spec/models/enroll_factor_request_spec.rb +64 -0
- data/spec/models/envvar_spec.rb +52 -0
- data/spec/models/error_status_errors_inner_spec.rb +40 -0
- data/spec/models/error_status_spec.rb +46 -0
- data/spec/models/factor_inner_factor_data_spec.rb +40 -0
- data/spec/models/factor_inner_spec.rb +80 -0
- data/spec/models/generate_mfa_token200_response_spec.rb +52 -0
- data/spec/models/generate_mfa_token422_response_details_spec.rb +34 -0
- data/spec/models/generate_mfa_token422_response_spec.rb +52 -0
- data/spec/models/generate_mfa_token_request_spec.rb +40 -0
- data/spec/models/generate_saml_assertion_request_spec.rb +58 -0
- data/spec/models/generate_token200_response_spec.rb +64 -0
- data/spec/models/generate_token400_response_spec.rb +34 -0
- data/spec/models/generate_token_request_spec.rb +38 -0
- data/spec/models/get_authorization_server200_response_spec.rb +52 -0
- data/spec/models/get_available_factors200_response_inner_spec.rb +46 -0
- data/spec/models/get_client_apps200_response_inner_scopes_inner_spec.rb +46 -0
- data/spec/models/get_client_apps200_response_inner_spec.rb +52 -0
- data/spec/models/get_rate_limit200_response_data_spec.rb +46 -0
- data/spec/models/get_rate_limit200_response_spec.rb +40 -0
- data/spec/models/get_risk_score200_response_spec.rb +40 -0
- data/spec/models/get_risk_score400_response_spec.rb +34 -0
- data/spec/models/get_risk_score_request_spec.rb +70 -0
- data/spec/models/get_score_insights200_response_scores_spec.rb +58 -0
- data/spec/models/get_score_insights200_response_spec.rb +40 -0
- data/spec/models/get_user_apps200_response_inner_spec.rb +84 -0
- data/spec/models/hook_conditions_inner_spec.rb +46 -0
- data/spec/models/hook_options_spec.rb +46 -0
- data/spec/models/hook_spec.rb +122 -0
- data/spec/models/hook_status_spec.rb +40 -0
- data/spec/models/id_spec.rb +34 -0
- data/spec/models/list_access_token_claims200_response_inner_spec.rb +82 -0
- data/spec/models/list_actions200_response_inner_spec.rb +40 -0
- data/spec/models/list_app_users200_response_inner_spec.rb +58 -0
- data/spec/models/list_authorization_servers200_response_inner_configuration_spec.rb +40 -0
- data/spec/models/list_authorization_servers200_response_inner_spec.rb +52 -0
- data/spec/models/list_condition_operators200_response_inner_spec.rb +40 -0
- data/spec/models/list_condition_values200_response_inner_spec.rb +40 -0
- data/spec/models/list_conditions200_response_inner_spec.rb +40 -0
- data/spec/models/list_mapping_condition_operators200_response_inner_spec.rb +40 -0
- data/spec/models/list_mapping_conditions200_response_inner_spec.rb +40 -0
- data/spec/models/list_scopes200_response_inner_spec.rb +46 -0
- data/spec/models/log_spec.rb +52 -0
- data/spec/models/mapping_spec.rb +74 -0
- data/spec/models/registration_spec.rb +50 -0
- data/spec/models/remove_role_users_request_spec.rb +34 -0
- data/spec/models/revoke_token_request_spec.rb +34 -0
- data/spec/models/risk_device_spec.rb +34 -0
- data/spec/models/risk_rule_spec.rb +78 -0
- data/spec/models/risk_user_spec.rb +46 -0
- data/spec/models/role_spec.rb +58 -0
- data/spec/models/rule_id_spec.rb +34 -0
- data/spec/models/rule_spec.rb +74 -0
- data/spec/models/schema1_added_by_spec.rb +40 -0
- data/spec/models/schema1_spec.rb +64 -0
- data/spec/models/schema_provisioning_spec.rb +34 -0
- data/spec/models/schema_spec.rb +152 -0
- data/spec/models/session_spec.rb +34 -0
- data/spec/models/set_role_apps200_response_inner_spec.rb +34 -0
- data/spec/models/source_spec.rb +40 -0
- data/spec/models/status1_spec.rb +46 -0
- data/spec/models/status2_spec.rb +34 -0
- data/spec/models/status2_status_spec.rb +52 -0
- data/spec/models/status_spec.rb +52 -0
- data/spec/models/track_event_request_spec.rb +82 -0
- data/spec/models/update_authorization_server400_response_spec.rb +52 -0
- data/spec/models/update_client_app_request_spec.rb +34 -0
- data/spec/models/update_environment_variable_request_spec.rb +34 -0
- data/spec/models/update_role200_response_spec.rb +34 -0
- data/spec/models/user_spec.rb +258 -0
- data/spec/models/verify_enrollment_request_spec.rb +34 -0
- data/spec/models/verify_factor_request_spec.rb +40 -0
- data/spec/models/verify_factor_saml200_response_spec.rb +40 -0
- data/spec/models/verify_factor_saml_request_spec.rb +58 -0
- data/spec/models/verify_factor_voice200_response_inner_spec.rb +50 -0
- data/spec/spec_helper.rb +111 -0
- metadata +401 -216
- data/.github/workflows/git-secrets-public.yml +0 -55
- data/.gitignore +0 -12
- data/.travis.yml +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -6
- data/examples/Gemfile +0 -3
- data/examples/Gemfile.lock +0 -25
- data/examples/README.md +0 -19
- data/examples/all-users-to-csv.rb +0 -48
- data/examples/another-get-all-login-events-of-last-day-to-csv.rb +0 -141
- data/examples/create-user.rb +0 -16
- data/examples/events-to-csv.rb +0 -93
- data/examples/get-all-login-events-of-last-day-to-csv.rb +0 -88
- data/examples/last-app-user-login-to-csv.rb +0 -72
- data/examples/list-users.rb +0 -15
- data/examples/rails-custom-login-page/.gitignore +0 -45
- data/examples/rails-custom-login-page/.ruby-version +0 -1
- data/examples/rails-custom-login-page/Gemfile +0 -57
- data/examples/rails-custom-login-page/Gemfile.lock +0 -212
- data/examples/rails-custom-login-page/README.md +0 -137
- data/examples/rails-custom-login-page/Rakefile +0 -6
- data/examples/rails-custom-login-page/app/assets/config/manifest.js +0 -3
- data/examples/rails-custom-login-page/app/assets/images/.keep +0 -0
- data/examples/rails-custom-login-page/app/assets/javascripts/application.js +0 -18
- data/examples/rails-custom-login-page/app/assets/javascripts/cable.js +0 -13
- data/examples/rails-custom-login-page/app/assets/javascripts/channels/.keep +0 -0
- data/examples/rails-custom-login-page/app/assets/javascripts/dashboard.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/javascripts/home.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/javascripts/sessions.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/application.css +0 -15
- data/examples/rails-custom-login-page/app/assets/stylesheets/dashboard.scss +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/home.scss +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/sessions.scss +0 -3
- data/examples/rails-custom-login-page/app/channels/application_cable/channel.rb +0 -4
- data/examples/rails-custom-login-page/app/channels/application_cable/connection.rb +0 -4
- data/examples/rails-custom-login-page/app/controllers/application_controller.rb +0 -23
- data/examples/rails-custom-login-page/app/controllers/concerns/.keep +0 -0
- data/examples/rails-custom-login-page/app/controllers/dashboard_controller.rb +0 -10
- data/examples/rails-custom-login-page/app/controllers/home_controller.rb +0 -5
- data/examples/rails-custom-login-page/app/controllers/sessions_controller.rb +0 -46
- data/examples/rails-custom-login-page/app/controllers/users_controller.rb +0 -120
- data/examples/rails-custom-login-page/app/helpers/application_helper.rb +0 -2
- data/examples/rails-custom-login-page/app/helpers/dashboard_helper.rb +0 -28
- data/examples/rails-custom-login-page/app/helpers/home_helper.rb +0 -2
- data/examples/rails-custom-login-page/app/helpers/sessions_helper.rb +0 -87
- data/examples/rails-custom-login-page/app/helpers/users_helper.rb +0 -3
- data/examples/rails-custom-login-page/app/jobs/application_job.rb +0 -2
- data/examples/rails-custom-login-page/app/mailers/application_mailer.rb +0 -4
- data/examples/rails-custom-login-page/app/models/application_record.rb +0 -3
- data/examples/rails-custom-login-page/app/models/concerns/.keep +0 -0
- data/examples/rails-custom-login-page/app/views/dashboard/index.html.erb +0 -43
- data/examples/rails-custom-login-page/app/views/home/index.html.erb +0 -272
- data/examples/rails-custom-login-page/app/views/layouts/application.html.erb +0 -31
- data/examples/rails-custom-login-page/app/views/layouts/mailer.html.erb +0 -13
- data/examples/rails-custom-login-page/app/views/layouts/mailer.text.erb +0 -1
- data/examples/rails-custom-login-page/app/views/users/_form.html.erb +0 -1
- data/examples/rails-custom-login-page/app/views/users/_user.json.jbuilder +0 -2
- data/examples/rails-custom-login-page/app/views/users/edit.html.erb +0 -33
- data/examples/rails-custom-login-page/app/views/users/index.html.erb +0 -33
- data/examples/rails-custom-login-page/app/views/users/index.json.jbuilder +0 -1
- data/examples/rails-custom-login-page/app/views/users/new.html.erb +0 -60
- data/examples/rails-custom-login-page/app/views/users/onboard.html.erb +0 -54
- data/examples/rails-custom-login-page/app/views/users/show.html.erb +0 -17
- data/examples/rails-custom-login-page/app/views/users/show.json.jbuilder +0 -1
- data/examples/rails-custom-login-page/bin/bundle +0 -3
- data/examples/rails-custom-login-page/bin/rails +0 -9
- data/examples/rails-custom-login-page/bin/rake +0 -9
- data/examples/rails-custom-login-page/bin/setup +0 -38
- data/examples/rails-custom-login-page/bin/spring +0 -17
- data/examples/rails-custom-login-page/bin/update +0 -29
- data/examples/rails-custom-login-page/bin/yarn +0 -11
- data/examples/rails-custom-login-page/config/application.rb +0 -18
- data/examples/rails-custom-login-page/config/boot.rb +0 -3
- data/examples/rails-custom-login-page/config/cable.yml +0 -10
- data/examples/rails-custom-login-page/config/database.yml +0 -25
- data/examples/rails-custom-login-page/config/environment.rb +0 -5
- data/examples/rails-custom-login-page/config/environments/development.rb +0 -54
- data/examples/rails-custom-login-page/config/environments/production.rb +0 -91
- data/examples/rails-custom-login-page/config/environments/test.rb +0 -42
- data/examples/rails-custom-login-page/config/initializers/application_controller_renderer.rb +0 -8
- data/examples/rails-custom-login-page/config/initializers/assets.rb +0 -14
- data/examples/rails-custom-login-page/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/rails-custom-login-page/config/initializers/cookies_serializer.rb +0 -5
- data/examples/rails-custom-login-page/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/rails-custom-login-page/config/initializers/inflections.rb +0 -16
- data/examples/rails-custom-login-page/config/initializers/mime_types.rb +0 -4
- data/examples/rails-custom-login-page/config/initializers/onelogin.rb +0 -6
- data/examples/rails-custom-login-page/config/initializers/wrap_parameters.rb +0 -14
- data/examples/rails-custom-login-page/config/locales/en.yml +0 -33
- data/examples/rails-custom-login-page/config/puma.rb +0 -56
- data/examples/rails-custom-login-page/config/routes.rb +0 -23
- data/examples/rails-custom-login-page/config/secrets.yml.sample +0 -38
- data/examples/rails-custom-login-page/config/spring.rb +0 -6
- data/examples/rails-custom-login-page/config.ru +0 -5
- data/examples/rails-custom-login-page/db/seeds.rb +0 -7
- data/examples/rails-custom-login-page/lib/assets/.keep +0 -0
- data/examples/rails-custom-login-page/lib/tasks/.keep +0 -0
- data/examples/rails-custom-login-page/package.json +0 -5
- data/examples/rails-custom-login-page/public/404.html +0 -67
- data/examples/rails-custom-login-page/public/422.html +0 -67
- data/examples/rails-custom-login-page/public/500.html +0 -66
- data/examples/rails-custom-login-page/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/rails-custom-login-page/public/apple-touch-icon.png +0 -0
- data/examples/rails-custom-login-page/public/favicon.ico +0 -0
- data/examples/rails-custom-login-page/public/robots.txt +0 -1
- data/examples/rails-custom-login-page/test/application_system_test_case.rb +0 -5
- data/examples/rails-custom-login-page/test/controllers/.keep +0 -0
- data/examples/rails-custom-login-page/test/controllers/dashboard_controller_test.rb +0 -9
- data/examples/rails-custom-login-page/test/controllers/home_controller_test.rb +0 -9
- data/examples/rails-custom-login-page/test/controllers/sessions_controller_test.rb +0 -7
- data/examples/rails-custom-login-page/test/controllers/users_controller_test.rb +0 -48
- data/examples/rails-custom-login-page/test/fixtures/.keep +0 -0
- data/examples/rails-custom-login-page/test/fixtures/files/.keep +0 -0
- data/examples/rails-custom-login-page/test/helpers/.keep +0 -0
- data/examples/rails-custom-login-page/test/integration/.keep +0 -0
- data/examples/rails-custom-login-page/test/mailers/.keep +0 -0
- data/examples/rails-custom-login-page/test/models/.keep +0 -0
- data/examples/rails-custom-login-page/test/system/.keep +0 -0
- data/examples/rails-custom-login-page/test/test_helper.rb +0 -9
- data/examples/rails-custom-login-page/vendor/.keep +0 -0
- data/lib/onelogin/api/apiexception.rb +0 -10
- data/lib/onelogin/api/client.rb +0 -2954
- data/lib/onelogin/api/cursor.rb +0 -114
- data/lib/onelogin/api/models/app.rb +0 -22
- data/lib/onelogin/api/models/auth_factor.rb +0 -16
- data/lib/onelogin/api/models/connector_basic.rb +0 -20
- data/lib/onelogin/api/models/device.rb +0 -18
- data/lib/onelogin/api/models/embed_app.rb +0 -31
- data/lib/onelogin/api/models/event.rb +0 -54
- data/lib/onelogin/api/models/event_type.rb +0 -17
- data/lib/onelogin/api/models/factor_enrollment_response.rb +0 -22
- data/lib/onelogin/api/models/group.rb +0 -17
- data/lib/onelogin/api/models/mfa.rb +0 -26
- data/lib/onelogin/api/models/mfa_token.rb +0 -18
- data/lib/onelogin/api/models/onelogin_app.rb +0 -62
- data/lib/onelogin/api/models/onelogin_app_basic.rb +0 -51
- data/lib/onelogin/api/models/onelogin_app_v1.rb +0 -22
- data/lib/onelogin/api/models/onelogin_token.rb +0 -20
- data/lib/onelogin/api/models/otp_device.rb +0 -25
- data/lib/onelogin/api/models/privilege.rb +0 -51
- data/lib/onelogin/api/models/rate_limit.rb +0 -17
- data/lib/onelogin/api/models/role.rb +0 -16
- data/lib/onelogin/api/models/saml_endpoint_response.rb +0 -18
- data/lib/onelogin/api/models/session_token_info.rb +0 -21
- data/lib/onelogin/api/models/session_token_mfa_info.rb +0 -26
- data/lib/onelogin/api/models/statement.rb +0 -36
- data/lib/onelogin/api/models/user.rb +0 -135
- data/lib/onelogin/api/models/user_data.rb +0 -13
- data/lib/onelogin/api/models/user_metadata.rb +0 -13
- data/lib/onelogin/api/models.rb +0 -26
- data/lib/onelogin/api/util/constants.rb +0 -177
- data/lib/onelogin/api/util/parser.rb +0 -56
- data/lib/onelogin/api/util/url_builder.rb +0 -24
- data/lib/onelogin/api/util.rb +0 -13
- data/lib/onelogin/api.rb +0 -2
data/lib/onelogin/api/client.rb
DELETED
@@ -1,2954 +0,0 @@
|
|
1
|
-
require 'onelogin/version'
|
2
|
-
require 'onelogin/api/apiexception'
|
3
|
-
require 'onelogin/api/cursor'
|
4
|
-
require 'onelogin/api/util'
|
5
|
-
require 'json'
|
6
|
-
require 'httparty'
|
7
|
-
require 'nokogiri'
|
8
|
-
require 'time'
|
9
|
-
|
10
|
-
module OneLogin
|
11
|
-
module Api
|
12
|
-
# Client class
|
13
|
-
#
|
14
|
-
# Client class of the OneLogin's Ruby SDK.
|
15
|
-
# It makes the API calls to the Onelogin's platform described
|
16
|
-
# at https://developers.onelogin.com/api-docs/1/getting-started/dev-overview.
|
17
|
-
#
|
18
|
-
class Client
|
19
|
-
include OneLogin::Api::Util
|
20
|
-
include HTTParty
|
21
|
-
|
22
|
-
attr_accessor :client_id, :client_secret, :region
|
23
|
-
attr_accessor :user_agent, :error, :error_description, :error_attribute
|
24
|
-
|
25
|
-
NOKOGIRI_OPTIONS = Nokogiri::XML::ParseOptions::STRICT |
|
26
|
-
Nokogiri::XML::ParseOptions::NONET
|
27
|
-
|
28
|
-
DEFAULT_USER_AGENT = "onelogin-ruby-sdk v#{OneLogin::VERSION}".freeze
|
29
|
-
|
30
|
-
# Create a new instance of the Client.
|
31
|
-
#
|
32
|
-
# @param config [Hash] Client Id, Client Secret and Region
|
33
|
-
#
|
34
|
-
def initialize(config)
|
35
|
-
options = Hash[config.map { |(k, v)| [k.to_sym, v] }]
|
36
|
-
|
37
|
-
@client_id = options[:client_id]
|
38
|
-
@client_secret = options[:client_secret]
|
39
|
-
@region = options[:region] || 'us'
|
40
|
-
@max_results = options[:max_results] || 1000
|
41
|
-
|
42
|
-
if options[:timeout] and defined? self.class.default_timeout
|
43
|
-
self.class.default_timeout options[:timeout]
|
44
|
-
end
|
45
|
-
|
46
|
-
if options[:proxy_host]
|
47
|
-
self.class.http_proxy options[:proxy_host], options[:proxy_port], options[:proxy_user], options[:proxy_pass]
|
48
|
-
end
|
49
|
-
|
50
|
-
self.class.default_options.update(verify: false)
|
51
|
-
|
52
|
-
validate_config
|
53
|
-
|
54
|
-
@user_agent = DEFAULT_USER_AGENT
|
55
|
-
end
|
56
|
-
|
57
|
-
def validate_config
|
58
|
-
raise ArgumentError, 'client_id & client_secret are required' unless @client_id && @client_secret
|
59
|
-
end
|
60
|
-
|
61
|
-
# Clean any previous error registered at the client.
|
62
|
-
#
|
63
|
-
def clean_error
|
64
|
-
@error = nil
|
65
|
-
@error_description = nil
|
66
|
-
@error_attribute = nil
|
67
|
-
end
|
68
|
-
|
69
|
-
def expired?
|
70
|
-
Time.now.utc > @expiration
|
71
|
-
end
|
72
|
-
|
73
|
-
def prepare_token
|
74
|
-
if @access_token.nil?
|
75
|
-
access_token
|
76
|
-
elsif expired?
|
77
|
-
regenerate_token
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def handle_operation_response(response)
|
82
|
-
result = false
|
83
|
-
begin
|
84
|
-
content = JSON.parse(response.body)
|
85
|
-
if content
|
86
|
-
if content.has_key?('status') && content['status'].has_key?('type') && content['status']['type'] == "success"
|
87
|
-
result = true
|
88
|
-
elsif content.has_key?('success') && content['success']
|
89
|
-
result = true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
rescue Exception => e
|
93
|
-
result = false
|
94
|
-
end
|
95
|
-
|
96
|
-
result
|
97
|
-
end
|
98
|
-
|
99
|
-
def handle_session_token_response(response)
|
100
|
-
content = JSON.parse(response.body)
|
101
|
-
if content && content.has_key?('status') && content['status'].has_key?('message') && content.has_key?('data')
|
102
|
-
if content['status']['message'] == "Success"
|
103
|
-
return OneLogin::Api::Models::SessionTokenInfo.new(content['data'][0])
|
104
|
-
elsif content['status']['message'] == "MFA is required for this user"
|
105
|
-
return OneLogin::Api::Models::SessionTokenMFAInfo.new(content['data'][0])
|
106
|
-
else
|
107
|
-
raise "Status Message type not reognized: %s" % content['status']['message']
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
nil
|
112
|
-
end
|
113
|
-
|
114
|
-
def handle_saml_endpoint_response(response)
|
115
|
-
content = JSON.parse(response.body)
|
116
|
-
if content && content.has_key?('status') && content['status'].has_key?('message') && content['status'].has_key?('type')
|
117
|
-
status_type = content['status']['type']
|
118
|
-
status_message = content['status']['message']
|
119
|
-
saml_endpoint_response = OneLogin::Api::Models::SAMLEndpointResponse.new(status_type, status_message)
|
120
|
-
if content.has_key?('data')
|
121
|
-
if status_message == 'Success'
|
122
|
-
saml_endpoint_response.saml_response = content['data']
|
123
|
-
else
|
124
|
-
mfa = OneLogin::Api::Models::MFA.new(content['data'][0])
|
125
|
-
saml_endpoint_response.mfa = mfa
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
return saml_endpoint_response
|
130
|
-
end
|
131
|
-
|
132
|
-
nil
|
133
|
-
end
|
134
|
-
|
135
|
-
def headers
|
136
|
-
{
|
137
|
-
'Content-Type' => 'application/json',
|
138
|
-
'User-Agent' => @user_agent
|
139
|
-
}
|
140
|
-
end
|
141
|
-
|
142
|
-
def authorized_headers(bearer = true)
|
143
|
-
# Removed the ":"
|
144
|
-
authorization = if bearer
|
145
|
-
"bearer #{@access_token}"
|
146
|
-
else
|
147
|
-
"client_id:#{@client_id},client_secret:#{@client_secret}"
|
148
|
-
end
|
149
|
-
|
150
|
-
headers.merge({
|
151
|
-
'Authorization' => authorization
|
152
|
-
})
|
153
|
-
end
|
154
|
-
|
155
|
-
############################
|
156
|
-
# OAuth 2.0 Tokens Methods #
|
157
|
-
############################
|
158
|
-
|
159
|
-
# Generates an access token and refresh token that you may use to
|
160
|
-
# call Onelogin's API methods.
|
161
|
-
#
|
162
|
-
# @return [OneLoginToken] Returns the generated OAuth Token info
|
163
|
-
#
|
164
|
-
# @see {https://developers.onelogin.com/api-docs/1/oauth20-tokens/generate-tokens Generate Tokens documentation}
|
165
|
-
def access_token
|
166
|
-
clean_error
|
167
|
-
|
168
|
-
begin
|
169
|
-
url = url_for(TOKEN_REQUEST_URL)
|
170
|
-
|
171
|
-
data = {
|
172
|
-
'grant_type' => 'client_credentials'
|
173
|
-
}
|
174
|
-
|
175
|
-
response = self.class.post(
|
176
|
-
url,
|
177
|
-
headers: authorized_headers(false),
|
178
|
-
body: data.to_json
|
179
|
-
)
|
180
|
-
|
181
|
-
if response.code == 200
|
182
|
-
json_data = JSON.parse(response.body)
|
183
|
-
if json_data.has_key?('status')
|
184
|
-
@error = json_data['status']['code'].to_s
|
185
|
-
@error_description = extract_error_message_from_response(response)
|
186
|
-
else
|
187
|
-
token = OneLogin::Api::Models::OneLoginToken.new(json_data)
|
188
|
-
@access_token = token.access_token
|
189
|
-
@refresh_token = token.refresh_token
|
190
|
-
@expiration = token.created_at + token.expires_in
|
191
|
-
return token
|
192
|
-
end
|
193
|
-
else
|
194
|
-
@error = response.code.to_s
|
195
|
-
@error_description = extract_error_message_from_response(response)
|
196
|
-
end
|
197
|
-
rescue Exception => e
|
198
|
-
@error = '500'
|
199
|
-
@error_description = e.message
|
200
|
-
end
|
201
|
-
|
202
|
-
nil
|
203
|
-
end
|
204
|
-
|
205
|
-
# Refreshing tokens provides a new set of access and refresh tokens.
|
206
|
-
#
|
207
|
-
# @return [OneLoginToken] Returns the refreshed OAuth Token info
|
208
|
-
#
|
209
|
-
# @see {https://developers.onelogin.com/api-docs/1/oauth20-tokens/refresh-tokens Refresh Tokens documentation}
|
210
|
-
def regenerate_token
|
211
|
-
clean_error
|
212
|
-
|
213
|
-
begin
|
214
|
-
url = url_for(TOKEN_REQUEST_URL)
|
215
|
-
|
216
|
-
data = {
|
217
|
-
'grant_type' => 'refresh_token',
|
218
|
-
'access_token' => @access_token,
|
219
|
-
'refresh_token' => @refresh_token
|
220
|
-
}
|
221
|
-
|
222
|
-
response = self.class.post(
|
223
|
-
url,
|
224
|
-
headers: headers,
|
225
|
-
body: data.to_json
|
226
|
-
)
|
227
|
-
|
228
|
-
if response.code == 200
|
229
|
-
json_data = JSON.parse(response.body)
|
230
|
-
if json_data.has_key?('status')
|
231
|
-
@error = json_data['status']['code'].to_s
|
232
|
-
@error_description = extract_error_message_from_response(response)
|
233
|
-
else
|
234
|
-
token = OneLogin::Api::Models::OneLoginToken.new(json_data)
|
235
|
-
@access_token = token.access_token
|
236
|
-
@refresh_token = token.refresh_token
|
237
|
-
@expiration = token.created_at + token.expires_in
|
238
|
-
return token
|
239
|
-
end
|
240
|
-
else
|
241
|
-
@error = response.code.to_s
|
242
|
-
@error_description = extract_error_message_from_response(response)
|
243
|
-
end
|
244
|
-
rescue Exception => e
|
245
|
-
@error = '500'
|
246
|
-
@error_description = e.message
|
247
|
-
end
|
248
|
-
|
249
|
-
nil
|
250
|
-
end
|
251
|
-
|
252
|
-
# Revokes an access token and refresh token pair.
|
253
|
-
#
|
254
|
-
# @return [Boolean] If the opeation succeded
|
255
|
-
#
|
256
|
-
# @see {https://developers.onelogin.com/api-docs/1/oauth20-tokens/revoke-tokens Revoke Tokens documentation}
|
257
|
-
def revoke_token
|
258
|
-
clean_error
|
259
|
-
|
260
|
-
begin
|
261
|
-
url = url_for(TOKEN_REVOKE_URL)
|
262
|
-
|
263
|
-
data = {
|
264
|
-
access_token: @access_token
|
265
|
-
}
|
266
|
-
|
267
|
-
response = self.class.post(
|
268
|
-
url,
|
269
|
-
headers: authorized_headers(false),
|
270
|
-
body: data.to_json
|
271
|
-
)
|
272
|
-
|
273
|
-
if response.code == 200
|
274
|
-
@access_token = nil
|
275
|
-
@refresh_token = nil
|
276
|
-
@expiration = nil
|
277
|
-
return true
|
278
|
-
else
|
279
|
-
@error = response.code.to_s
|
280
|
-
@error_description = extract_error_message_from_response(response)
|
281
|
-
end
|
282
|
-
rescue Exception => e
|
283
|
-
@error = '500'
|
284
|
-
@error_description = e.message
|
285
|
-
end
|
286
|
-
|
287
|
-
false
|
288
|
-
end
|
289
|
-
|
290
|
-
# Gets current rate limit details about an access token.
|
291
|
-
#
|
292
|
-
# @return [RateLimit] Returns the rate limit info
|
293
|
-
#
|
294
|
-
# @see {https://developers.onelogin.com/api-docs/1/oauth20-tokens/get-rate-limit Get Rate Limit documentation}
|
295
|
-
def get_rate_limits
|
296
|
-
clean_error
|
297
|
-
prepare_token
|
298
|
-
|
299
|
-
begin
|
300
|
-
url = url_for(GET_RATE_URL)
|
301
|
-
|
302
|
-
response = self.class.get(
|
303
|
-
url,
|
304
|
-
headers: authorized_headers
|
305
|
-
)
|
306
|
-
|
307
|
-
if response.code == 200
|
308
|
-
json_data = JSON.parse(response.body)
|
309
|
-
if json_data && json_data['data']
|
310
|
-
return OneLogin::Api::Models::RateLimit.new(json_data['data'])
|
311
|
-
end
|
312
|
-
else
|
313
|
-
@error = response.code.to_s
|
314
|
-
@error_description = extract_error_message_from_response(response)
|
315
|
-
end
|
316
|
-
rescue Exception => e
|
317
|
-
@error = '500'
|
318
|
-
@error_description = e.message
|
319
|
-
end
|
320
|
-
|
321
|
-
nil
|
322
|
-
end
|
323
|
-
|
324
|
-
################
|
325
|
-
# User Methods #
|
326
|
-
################
|
327
|
-
|
328
|
-
# Gets a list of User resources. (if no limit provided, by default gt 50 elements)
|
329
|
-
#
|
330
|
-
# @param params [Hash] Parameters to filter the result of the list
|
331
|
-
#
|
332
|
-
# @return [Array] list of User objects
|
333
|
-
#
|
334
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/get-users Get Users documentation}
|
335
|
-
def get_users(params = {})
|
336
|
-
clean_error
|
337
|
-
prepare_token
|
338
|
-
|
339
|
-
begin
|
340
|
-
options = {
|
341
|
-
model: OneLogin::Api::Models::User,
|
342
|
-
headers: authorized_headers,
|
343
|
-
max_results: @max_results,
|
344
|
-
params: params
|
345
|
-
}
|
346
|
-
|
347
|
-
return Cursor.new(self, url_for(GET_USERS_URL), options)
|
348
|
-
|
349
|
-
rescue Exception => e
|
350
|
-
@error = '500'
|
351
|
-
@error_description = e.message
|
352
|
-
end
|
353
|
-
|
354
|
-
nil
|
355
|
-
end
|
356
|
-
|
357
|
-
# Gets User by ID.
|
358
|
-
#
|
359
|
-
# @param user_id [Integer] Id of the user
|
360
|
-
#
|
361
|
-
# @return [User] the user identified by the id
|
362
|
-
#
|
363
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/get-user-by-id Get User by ID documentation}
|
364
|
-
def get_user(user_id)
|
365
|
-
clean_error
|
366
|
-
prepare_token
|
367
|
-
|
368
|
-
begin
|
369
|
-
if user_id.nil? || user_id.to_s.empty?
|
370
|
-
@error = '400'
|
371
|
-
@error_description = "user_id is required"
|
372
|
-
@error_attribute = "user_id"
|
373
|
-
return
|
374
|
-
end
|
375
|
-
|
376
|
-
url = url_for(GET_USER_URL, user_id)
|
377
|
-
|
378
|
-
response = self.class.get(
|
379
|
-
url,
|
380
|
-
headers: authorized_headers
|
381
|
-
)
|
382
|
-
|
383
|
-
if response.code == 200
|
384
|
-
json_data = JSON.parse(response.body)
|
385
|
-
if json_data && json_data['data']
|
386
|
-
return OneLogin::Api::Models::User.new(json_data['data'][0])
|
387
|
-
end
|
388
|
-
else
|
389
|
-
@error = response.code.to_s
|
390
|
-
@error_description = extract_error_message_from_response(response)
|
391
|
-
end
|
392
|
-
rescue Exception => e
|
393
|
-
@error = '500'
|
394
|
-
@error_description = e.message
|
395
|
-
end
|
396
|
-
|
397
|
-
nil
|
398
|
-
end
|
399
|
-
|
400
|
-
# Gets a list of apps accessible by a user, not including personal apps.
|
401
|
-
#
|
402
|
-
# @param user_id [Integer] Id of the user
|
403
|
-
#
|
404
|
-
# @return [Array] the apps of the user identified by the id
|
405
|
-
#
|
406
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/get-apps-for-user Get Apps for a User documentation}
|
407
|
-
def get_user_apps(user_id)
|
408
|
-
clean_error
|
409
|
-
prepare_token
|
410
|
-
|
411
|
-
begin
|
412
|
-
if user_id.nil? || user_id.to_s.empty?
|
413
|
-
@error = '400'
|
414
|
-
@error_description = "user_id is required"
|
415
|
-
@error_attribute = "user_id"
|
416
|
-
return
|
417
|
-
end
|
418
|
-
|
419
|
-
options = {
|
420
|
-
model: OneLogin::Api::Models::App,
|
421
|
-
headers: authorized_headers,
|
422
|
-
max_results: @max_results
|
423
|
-
}
|
424
|
-
|
425
|
-
return Cursor.new(self, url_for(GET_APPS_FOR_USER_URL, user_id), options)
|
426
|
-
|
427
|
-
rescue Exception => e
|
428
|
-
@error = '500'
|
429
|
-
@error_description = e.message
|
430
|
-
end
|
431
|
-
|
432
|
-
nil
|
433
|
-
end
|
434
|
-
|
435
|
-
# Gets a list of role IDs that have been assigned to a user.
|
436
|
-
#
|
437
|
-
# @param user_id [Integer] Id of the user
|
438
|
-
#
|
439
|
-
# @return [Array] the role ids of the user identified by the id
|
440
|
-
#
|
441
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/get-roles-for-user Get Roles for a User documentation}
|
442
|
-
def get_user_roles(user_id)
|
443
|
-
clean_error
|
444
|
-
prepare_token
|
445
|
-
|
446
|
-
begin
|
447
|
-
if user_id.nil? || user_id.to_s.empty?
|
448
|
-
@error = '400'
|
449
|
-
@error_description = "user_id is required"
|
450
|
-
@error_attribute = "user_id"
|
451
|
-
return
|
452
|
-
end
|
453
|
-
|
454
|
-
url = url_for(GET_ROLES_FOR_USER_URL, user_id)
|
455
|
-
|
456
|
-
response = self.class.get(
|
457
|
-
url,
|
458
|
-
headers: authorized_headers
|
459
|
-
)
|
460
|
-
|
461
|
-
role_ids = []
|
462
|
-
if response.code == 200
|
463
|
-
json_data = JSON.parse(response.body)
|
464
|
-
role_ids = json_data['data'][0] if json_data && json_data['data']
|
465
|
-
else
|
466
|
-
@error = response.code.to_s
|
467
|
-
@error_description = extract_error_message_from_response(response)
|
468
|
-
end
|
469
|
-
|
470
|
-
return role_ids
|
471
|
-
rescue Exception => e
|
472
|
-
@error = '500'
|
473
|
-
@error_description = e.message
|
474
|
-
end
|
475
|
-
|
476
|
-
nil
|
477
|
-
end
|
478
|
-
|
479
|
-
# Gets a list of all custom attribute fields (also known as custom user fields) that have been defined for OL account.
|
480
|
-
#
|
481
|
-
# @return [Array] the custom attributes of the account
|
482
|
-
#
|
483
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/get-custom-attributes Get Custom Attributes documentation}
|
484
|
-
def get_custom_attributes
|
485
|
-
clean_error
|
486
|
-
prepare_token
|
487
|
-
|
488
|
-
begin
|
489
|
-
url = url_for(GET_CUSTOM_ATTRIBUTES_URL)
|
490
|
-
|
491
|
-
response = self.class.get(
|
492
|
-
url,
|
493
|
-
headers: authorized_headers
|
494
|
-
)
|
495
|
-
|
496
|
-
custom_attributes = []
|
497
|
-
if response.code == 200
|
498
|
-
json_data = JSON.parse(response.body)
|
499
|
-
if json_data && json_data['data']
|
500
|
-
custom_attributes = json_data['data'][0]
|
501
|
-
end
|
502
|
-
else
|
503
|
-
@error = response.code.to_s
|
504
|
-
@error_description = extract_error_message_from_response(response)
|
505
|
-
end
|
506
|
-
|
507
|
-
return custom_attributes
|
508
|
-
rescue Exception => e
|
509
|
-
@error = '500'
|
510
|
-
@error_description = e.message
|
511
|
-
end
|
512
|
-
|
513
|
-
nil
|
514
|
-
end
|
515
|
-
|
516
|
-
# Creates an user
|
517
|
-
#
|
518
|
-
# @param user_params [Hash] User data (firstname, lastname, email, username, company,
|
519
|
-
# department, directory_id, distinguished_name,
|
520
|
-
# external_id, group_id, invalid_login_attempts,
|
521
|
-
# locale_code, manager_ad_id, member_of,
|
522
|
-
# openid_name, phone, samaccountname, title,
|
523
|
-
# userprincipalname)
|
524
|
-
#
|
525
|
-
# @return [User] the created user
|
526
|
-
#
|
527
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/create-user Create User documentation}
|
528
|
-
def create_user(user_params)
|
529
|
-
clean_error
|
530
|
-
prepare_token
|
531
|
-
|
532
|
-
begin
|
533
|
-
url = url_for(CREATE_USER_URL)
|
534
|
-
|
535
|
-
response = self.class.post(
|
536
|
-
url,
|
537
|
-
headers: authorized_headers,
|
538
|
-
body: user_params.to_json
|
539
|
-
)
|
540
|
-
|
541
|
-
if response.code == 200
|
542
|
-
json_data = JSON.parse(response.body)
|
543
|
-
if json_data && json_data['data']
|
544
|
-
return OneLogin::Api::Models::User.new(json_data['data'][0])
|
545
|
-
end
|
546
|
-
else
|
547
|
-
@error = response.code.to_s
|
548
|
-
@error_description = extract_error_message_from_response(response)
|
549
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
550
|
-
end
|
551
|
-
rescue Exception => e
|
552
|
-
@error = '500'
|
553
|
-
@error_description = e.message
|
554
|
-
end
|
555
|
-
|
556
|
-
nil
|
557
|
-
end
|
558
|
-
|
559
|
-
# Updates an user
|
560
|
-
#
|
561
|
-
# @param user_id [Integer] Id of the user
|
562
|
-
# @param user_params [Hash] User data (firstname, lastname, email, username, company,
|
563
|
-
# department, directory_id, distinguished_name,
|
564
|
-
# external_id, group_id, invalid_login_attempts,
|
565
|
-
# locale_code, manager_ad_id, member_of,
|
566
|
-
# openid_name, phone, samaccountname, title,
|
567
|
-
# userprincipalname)
|
568
|
-
#
|
569
|
-
# @return [User] the modified user
|
570
|
-
#
|
571
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/update-user Update User by ID documentation}
|
572
|
-
def update_user(user_id, user_params)
|
573
|
-
clean_error
|
574
|
-
prepare_token
|
575
|
-
|
576
|
-
begin
|
577
|
-
if user_id.nil? || user_id.to_s.empty?
|
578
|
-
@error = '400'
|
579
|
-
@error_description = "user_id is required"
|
580
|
-
@error_attribute = "user_id"
|
581
|
-
return
|
582
|
-
end
|
583
|
-
|
584
|
-
url = url_for(UPDATE_USER_URL, user_id)
|
585
|
-
|
586
|
-
response = self.class.put(
|
587
|
-
url,
|
588
|
-
headers: authorized_headers,
|
589
|
-
body: user_params.to_json
|
590
|
-
)
|
591
|
-
|
592
|
-
if response.code == 200
|
593
|
-
json_data = JSON.parse(response.body)
|
594
|
-
if json_data && json_data['data']
|
595
|
-
return OneLogin::Api::Models::User.new(json_data['data'][0])
|
596
|
-
end
|
597
|
-
else
|
598
|
-
@error = response.code.to_s
|
599
|
-
@error_description = extract_error_message_from_response(response)
|
600
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
601
|
-
end
|
602
|
-
rescue Exception => e
|
603
|
-
@error = '500'
|
604
|
-
@error_description = e.message
|
605
|
-
end
|
606
|
-
|
607
|
-
nil
|
608
|
-
end
|
609
|
-
|
610
|
-
# Assigns Roles to User
|
611
|
-
#
|
612
|
-
# @param user_id [Integer] Id of the user
|
613
|
-
# @param role_ids [Array] List of role ids to be added
|
614
|
-
#
|
615
|
-
# @return [Boolean] if the action succeed
|
616
|
-
#
|
617
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/assign-role-to-user Assign Role to User documentation}
|
618
|
-
def assign_role_to_user(user_id, role_ids)
|
619
|
-
clean_error
|
620
|
-
prepare_token
|
621
|
-
|
622
|
-
begin
|
623
|
-
if user_id.nil? || user_id.to_s.empty?
|
624
|
-
@error = '400'
|
625
|
-
@error_description = "user_id is required"
|
626
|
-
@error_attribute = "user_id"
|
627
|
-
return
|
628
|
-
end
|
629
|
-
|
630
|
-
url = url_for(ADD_ROLE_TO_USER_URL, user_id)
|
631
|
-
|
632
|
-
data = {
|
633
|
-
'role_id_array' => role_ids
|
634
|
-
}
|
635
|
-
|
636
|
-
response = self.class.put(
|
637
|
-
url,
|
638
|
-
headers: authorized_headers,
|
639
|
-
body: data.to_json
|
640
|
-
)
|
641
|
-
|
642
|
-
if response.code == 200
|
643
|
-
return handle_operation_response(response)
|
644
|
-
else
|
645
|
-
@error = response.code.to_s
|
646
|
-
@error_description = extract_error_message_from_response(response)
|
647
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
648
|
-
end
|
649
|
-
rescue Exception => e
|
650
|
-
@error = '500'
|
651
|
-
@error_description = e.message
|
652
|
-
end
|
653
|
-
|
654
|
-
false
|
655
|
-
end
|
656
|
-
|
657
|
-
# Removes Role from User
|
658
|
-
#
|
659
|
-
# @param user_id [Integer] Id of the user
|
660
|
-
# @param role_ids [Array] List of role ids to be removed
|
661
|
-
#
|
662
|
-
# @return [Boolean] if the action succeed
|
663
|
-
#
|
664
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/remove-role-from-user Remove Role from User documentation}
|
665
|
-
def remove_role_from_user(user_id, role_ids)
|
666
|
-
clean_error
|
667
|
-
prepare_token
|
668
|
-
|
669
|
-
begin
|
670
|
-
if user_id.nil? || user_id.to_s.empty?
|
671
|
-
@error = '400'
|
672
|
-
@error_description = "user_id is required"
|
673
|
-
@error_attribute = "user_id"
|
674
|
-
return
|
675
|
-
end
|
676
|
-
|
677
|
-
url = url_for(DELETE_ROLE_TO_USER_URL, user_id)
|
678
|
-
|
679
|
-
data = {
|
680
|
-
'role_id_array' => role_ids
|
681
|
-
}
|
682
|
-
|
683
|
-
response = self.class.put(
|
684
|
-
url,
|
685
|
-
headers: authorized_headers,
|
686
|
-
body: data.to_json
|
687
|
-
)
|
688
|
-
|
689
|
-
if response.code == 200
|
690
|
-
return handle_operation_response(response)
|
691
|
-
else
|
692
|
-
@error = response.code.to_s
|
693
|
-
@error_description = extract_error_message_from_response(response)
|
694
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
695
|
-
end
|
696
|
-
rescue Exception => e
|
697
|
-
@error = '500'
|
698
|
-
@error_description = e.message
|
699
|
-
end
|
700
|
-
|
701
|
-
false
|
702
|
-
end
|
703
|
-
|
704
|
-
# Sets Password by ID Using Cleartext
|
705
|
-
#
|
706
|
-
# @param user_id [Integer] Id of the user
|
707
|
-
# @param password [String] Set to the password value using cleartext.
|
708
|
-
# @param password_confirmation [String] Ensure that this value matches the password value exactly.
|
709
|
-
# @validate_policy [Boolean] Force validation against assigned OneLogin user password policy
|
710
|
-
#
|
711
|
-
# @return [Boolean] if the action succeed
|
712
|
-
#
|
713
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/set-password-in-cleartext Set Password by ID Using Cleartext documentation}
|
714
|
-
def set_password_using_clear_text(user_id, password, password_confirmation, validate_policy=false)
|
715
|
-
clean_error
|
716
|
-
prepare_token
|
717
|
-
|
718
|
-
begin
|
719
|
-
if user_id.nil? || user_id.to_s.empty?
|
720
|
-
@error = '400'
|
721
|
-
@error_description = "user_id is required"
|
722
|
-
@error_attribute = "user_id"
|
723
|
-
return
|
724
|
-
end
|
725
|
-
|
726
|
-
url = url_for(SET_PW_CLEARTEXT, user_id)
|
727
|
-
|
728
|
-
data = {
|
729
|
-
'password' => password,
|
730
|
-
'password_confirmation' => password_confirmation,
|
731
|
-
'validate_policy' => validate_policy
|
732
|
-
}
|
733
|
-
|
734
|
-
response = self.class.put(
|
735
|
-
url,
|
736
|
-
headers: authorized_headers,
|
737
|
-
body: data.to_json
|
738
|
-
)
|
739
|
-
|
740
|
-
if response.code == 200
|
741
|
-
return handle_operation_response(response)
|
742
|
-
else
|
743
|
-
@error = response.code.to_s
|
744
|
-
@error_description = extract_error_message_from_response(response)
|
745
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
746
|
-
end
|
747
|
-
rescue Exception => e
|
748
|
-
@error = '500'
|
749
|
-
@error_description = e.message
|
750
|
-
end
|
751
|
-
|
752
|
-
false
|
753
|
-
end
|
754
|
-
|
755
|
-
# Set Password by ID Using Salt and SHA-256
|
756
|
-
#
|
757
|
-
# @param user_id [Integer] Id of the user
|
758
|
-
# @param password [String] Set to the password value using cleartext.
|
759
|
-
# @param password_confirmation [String] Ensure that this value matches the password value exactly.
|
760
|
-
# @param password_algorithm [String] Set to salt+sha256.
|
761
|
-
# @param password_salt [String] (Optional) To provide your own salt value.
|
762
|
-
#
|
763
|
-
# @return [Boolean] if the action succeed
|
764
|
-
#
|
765
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/set-password-using-sha-256 Set Password by ID Using Salt and SHA-256 documentation}
|
766
|
-
def set_password_using_hash_salt(user_id, password, password_confirmation, password_algorithm, password_salt=nil)
|
767
|
-
clean_error
|
768
|
-
prepare_token
|
769
|
-
|
770
|
-
begin
|
771
|
-
if user_id.nil? || user_id.to_s.empty?
|
772
|
-
@error = '400'
|
773
|
-
@error_description = "user_id is required"
|
774
|
-
@error_attribute = "user_id"
|
775
|
-
return
|
776
|
-
end
|
777
|
-
|
778
|
-
url = url_for(SET_PW_SALT, user_id)
|
779
|
-
|
780
|
-
data = {
|
781
|
-
'password' => password,
|
782
|
-
'password_confirmation' => password_confirmation,
|
783
|
-
'password_algorithm' => password_algorithm
|
784
|
-
}
|
785
|
-
|
786
|
-
unless password_salt.nil?
|
787
|
-
data['password_salt'] = password_salt
|
788
|
-
end
|
789
|
-
|
790
|
-
response = self.class.put(
|
791
|
-
url,
|
792
|
-
headers: authorized_headers,
|
793
|
-
body: data.to_json
|
794
|
-
)
|
795
|
-
|
796
|
-
if response.code == 200
|
797
|
-
return handle_operation_response(response)
|
798
|
-
else
|
799
|
-
@error = response.code.to_s
|
800
|
-
@error_description = extract_error_message_from_response(response)
|
801
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
802
|
-
end
|
803
|
-
rescue Exception => e
|
804
|
-
@error = '500'
|
805
|
-
@error_description = e.message
|
806
|
-
end
|
807
|
-
|
808
|
-
false
|
809
|
-
end
|
810
|
-
|
811
|
-
# Set User State
|
812
|
-
#
|
813
|
-
# @param id [Integer] Id of the user to be modified
|
814
|
-
# @param state [Integer] Set to the state value. [Unapproved: 0, Approved (licensed): 1, Rejected: 2, Unlicensed: 3]
|
815
|
-
#
|
816
|
-
# @return [Boolean] if the action succeed
|
817
|
-
#
|
818
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/set-state Set User State documentation}
|
819
|
-
def set_state_to_user(user_id, state)
|
820
|
-
clean_error
|
821
|
-
prepare_token
|
822
|
-
|
823
|
-
begin
|
824
|
-
if user_id.nil? || user_id.to_s.empty?
|
825
|
-
@error = '400'
|
826
|
-
@error_description = "user_id is required"
|
827
|
-
@error_attribute = "user_id"
|
828
|
-
return
|
829
|
-
end
|
830
|
-
|
831
|
-
url = url_for(SET_USER_STATE_URL, user_id)
|
832
|
-
|
833
|
-
data = {
|
834
|
-
'state' => state
|
835
|
-
}
|
836
|
-
|
837
|
-
response = self.class.put(
|
838
|
-
url,
|
839
|
-
headers: authorized_headers,
|
840
|
-
body: data.to_json
|
841
|
-
)
|
842
|
-
|
843
|
-
if response.code == 200
|
844
|
-
return handle_operation_response(response)
|
845
|
-
else
|
846
|
-
@error = response.code.to_s
|
847
|
-
@error_description = extract_error_message_from_response(response)
|
848
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
849
|
-
end
|
850
|
-
rescue Exception => e
|
851
|
-
@error = '500'
|
852
|
-
@error_description = e.message
|
853
|
-
end
|
854
|
-
|
855
|
-
false
|
856
|
-
end
|
857
|
-
|
858
|
-
# Set Custom Attribute Value
|
859
|
-
#
|
860
|
-
# @param user_id [Integer] Id of the user
|
861
|
-
# @param custom_attributes [Hash] Provide one or more key value pairs composed of the custom attribute field shortname and the value that you want to set the field to.
|
862
|
-
#
|
863
|
-
# @return [Boolean] if the action succeed
|
864
|
-
#
|
865
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/set-custom-attribute Set Custom Attribute Value documentation}
|
866
|
-
def set_custom_attribute_to_user(user_id, custom_attributes)
|
867
|
-
clean_error
|
868
|
-
prepare_token
|
869
|
-
|
870
|
-
begin
|
871
|
-
if user_id.nil? || user_id.to_s.empty?
|
872
|
-
@error = '400'
|
873
|
-
@error_description = "user_id is required"
|
874
|
-
@error_attribute = "user_id"
|
875
|
-
return
|
876
|
-
end
|
877
|
-
|
878
|
-
url = url_for(SET_CUSTOM_ATTRIBUTE_TO_USER_URL, user_id)
|
879
|
-
|
880
|
-
data = {
|
881
|
-
'custom_attributes' => custom_attributes
|
882
|
-
}
|
883
|
-
|
884
|
-
response = self.class.put(
|
885
|
-
url,
|
886
|
-
headers: authorized_headers,
|
887
|
-
body: data.to_json
|
888
|
-
)
|
889
|
-
|
890
|
-
if response.code == 200
|
891
|
-
return handle_operation_response(response)
|
892
|
-
else
|
893
|
-
@error = response.code.to_s
|
894
|
-
@error_description = extract_error_message_from_response(response)
|
895
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
896
|
-
end
|
897
|
-
rescue Exception => e
|
898
|
-
@error = '500'
|
899
|
-
@error_description = e.message
|
900
|
-
end
|
901
|
-
|
902
|
-
false
|
903
|
-
end
|
904
|
-
|
905
|
-
# Log a user out of any and all sessions.
|
906
|
-
#
|
907
|
-
# @param user_id [Integer] Id of the user to be logged out
|
908
|
-
#
|
909
|
-
# @return [Boolean] if the action succeed
|
910
|
-
#
|
911
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/log-user-out Log User Out documentation}
|
912
|
-
def log_user_out(user_id)
|
913
|
-
clean_error
|
914
|
-
prepare_token
|
915
|
-
|
916
|
-
begin
|
917
|
-
if user_id.nil? || user_id.to_s.empty?
|
918
|
-
@error = '400'
|
919
|
-
@error_description = "user_id is required"
|
920
|
-
@error_attribute = "user_id"
|
921
|
-
return
|
922
|
-
end
|
923
|
-
|
924
|
-
url = url_for(LOG_USER_OUT_URL, user_id)
|
925
|
-
|
926
|
-
response = self.class.put(
|
927
|
-
url,
|
928
|
-
headers: authorized_headers
|
929
|
-
)
|
930
|
-
|
931
|
-
if response.code == 200
|
932
|
-
return handle_operation_response(response)
|
933
|
-
else
|
934
|
-
@error = response.code.to_s
|
935
|
-
@error_description = extract_error_message_from_response(response)
|
936
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
937
|
-
end
|
938
|
-
rescue Exception => e
|
939
|
-
@error = '500'
|
940
|
-
@error_description = e.message
|
941
|
-
end
|
942
|
-
|
943
|
-
false
|
944
|
-
end
|
945
|
-
|
946
|
-
# Use this call to lock a user's account based on the policy assigned to
|
947
|
-
# the user, for a specific time you define in the request, or until you
|
948
|
-
# unlock it.
|
949
|
-
#
|
950
|
-
# @param user_id [Integer] Id of the user to be locked
|
951
|
-
# @param minutes [Integer] Set to the number of minutes for which you want to lock the user account. (0 to delegate on policy)
|
952
|
-
#
|
953
|
-
# @return [Boolean] if the action succeed
|
954
|
-
#
|
955
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/lock-user-account Lock User Account documentation}
|
956
|
-
def lock_user(user_id, minutes)
|
957
|
-
clean_error
|
958
|
-
prepare_token
|
959
|
-
|
960
|
-
begin
|
961
|
-
if user_id.nil? || user_id.to_s.empty?
|
962
|
-
@error = '400'
|
963
|
-
@error_description = "user_id is required"
|
964
|
-
@error_attribute = "user_id"
|
965
|
-
return
|
966
|
-
end
|
967
|
-
|
968
|
-
url = url_for(LOCK_USER_URL, user_id)
|
969
|
-
|
970
|
-
data = {
|
971
|
-
'locked_until' => minutes
|
972
|
-
}
|
973
|
-
|
974
|
-
response = self.class.put(
|
975
|
-
url,
|
976
|
-
headers: authorized_headers,
|
977
|
-
body: data.to_json
|
978
|
-
)
|
979
|
-
|
980
|
-
if response.code == 200
|
981
|
-
return handle_operation_response(response)
|
982
|
-
else
|
983
|
-
@error = response.code.to_s
|
984
|
-
@error_description = extract_error_message_from_response(response)
|
985
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
986
|
-
end
|
987
|
-
rescue Exception => e
|
988
|
-
@error = '500'
|
989
|
-
@error_description = e.message
|
990
|
-
end
|
991
|
-
|
992
|
-
false
|
993
|
-
end
|
994
|
-
|
995
|
-
# Deletes an user
|
996
|
-
#
|
997
|
-
# @param user_id [Integer] Id of the user to be removed
|
998
|
-
#
|
999
|
-
# @return [Boolean] if the action succeed
|
1000
|
-
#
|
1001
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/delete-user Delete User by ID documentation}
|
1002
|
-
def delete_user(user_id)
|
1003
|
-
clean_error
|
1004
|
-
prepare_token
|
1005
|
-
|
1006
|
-
begin
|
1007
|
-
if user_id.nil? || user_id.to_s.empty?
|
1008
|
-
@error = '400'
|
1009
|
-
@error_description = "user_id is required"
|
1010
|
-
@error_attribute = "user_id"
|
1011
|
-
return
|
1012
|
-
end
|
1013
|
-
|
1014
|
-
url = url_for(DELETE_USER_URL, user_id)
|
1015
|
-
|
1016
|
-
response = self.class.delete(
|
1017
|
-
url,
|
1018
|
-
headers: authorized_headers
|
1019
|
-
)
|
1020
|
-
|
1021
|
-
if response.code == 200
|
1022
|
-
return handle_operation_response(response)
|
1023
|
-
else
|
1024
|
-
@error = response.code.to_s
|
1025
|
-
@error_description = extract_error_message_from_response(response)
|
1026
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1027
|
-
end
|
1028
|
-
rescue Exception => e
|
1029
|
-
@error = '500'
|
1030
|
-
@error_description = e.message
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
false
|
1034
|
-
end
|
1035
|
-
|
1036
|
-
# Use to generate a temporary MFA token that can be used in place of other MFA tokens for a set time period.
|
1037
|
-
# For example, use this token for account recovery.
|
1038
|
-
#
|
1039
|
-
# @param user_id [Integer] Id of the user
|
1040
|
-
# @param expires_in [Integer] Set the duration of the token in seconds.
|
1041
|
-
# (default: 259200 seconds = 72h) 72 hours is the max value.
|
1042
|
-
# @param reusable [Boolean] Defines if the token reusable. (default: false) If set to true, token can be used for multiple apps, until it expires.
|
1043
|
-
#
|
1044
|
-
# @return [MFAToken] if the action succeed
|
1045
|
-
#
|
1046
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/generate-mfa-token Generate MFA Token documentation}
|
1047
|
-
def generate_mfa_token(user_id, expires_in=259200, reusable=false)
|
1048
|
-
clean_error
|
1049
|
-
prepare_token
|
1050
|
-
|
1051
|
-
begin
|
1052
|
-
if user_id.nil? || user_id.to_s.empty?
|
1053
|
-
@error = '400'
|
1054
|
-
@error_description = "user_id is required"
|
1055
|
-
@error_attribute = "user_id"
|
1056
|
-
return
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
url = url_for(GENERATE_MFA_TOKEN_URL, user_id)
|
1060
|
-
|
1061
|
-
data = {
|
1062
|
-
'expires_in' => expires_in,
|
1063
|
-
'reusable' => reusable
|
1064
|
-
}
|
1065
|
-
|
1066
|
-
response = self.class.post(
|
1067
|
-
url,
|
1068
|
-
headers: authorized_headers,
|
1069
|
-
body: data.to_json
|
1070
|
-
)
|
1071
|
-
|
1072
|
-
if response.code == 201
|
1073
|
-
json_data = JSON.parse(response.body)
|
1074
|
-
if !json_data.empty?
|
1075
|
-
return OneLogin::Api::Models::MFAToken.new(json_data)
|
1076
|
-
end
|
1077
|
-
else
|
1078
|
-
@error = extract_status_code_from_response(response)
|
1079
|
-
@error_description = extract_error_message_from_response(response)
|
1080
|
-
end
|
1081
|
-
rescue Exception => e
|
1082
|
-
@error = '500'
|
1083
|
-
@error_description = e.message
|
1084
|
-
end
|
1085
|
-
|
1086
|
-
nil
|
1087
|
-
end
|
1088
|
-
|
1089
|
-
# Generates a session login token in scenarios in which MFA may or may not be required.
|
1090
|
-
# A session login token expires two minutes after creation.
|
1091
|
-
#
|
1092
|
-
# @param query_params [Hash] Query Parameters (username_or_email, password, subdomain, return_to_url,
|
1093
|
-
# ip_address, browser_id)
|
1094
|
-
# @param allowed_origin [String] Custom-Allowed-Origin-Header. Required for CORS requests only.
|
1095
|
-
# Set to the Origin URI from which you are allowed to send a request
|
1096
|
-
# using CORS.
|
1097
|
-
#
|
1098
|
-
# @return [SessionTokenInfo|SessionTokenMFAInfo] if the action succeed
|
1099
|
-
#
|
1100
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/create-session-login-token Create Session Login Token documentation}
|
1101
|
-
def create_session_login_token(query_params, allowed_origin='')
|
1102
|
-
clean_error
|
1103
|
-
prepare_token
|
1104
|
-
|
1105
|
-
begin
|
1106
|
-
url = url_for(SESSION_LOGIN_TOKEN_URL)
|
1107
|
-
|
1108
|
-
if query_params.nil? || !query_params.has_key?('username_or_email') || !query_params.has_key?('password') || !query_params.has_key?('subdomain')
|
1109
|
-
raise "username_or_email, password and subdomain are required parameters"
|
1110
|
-
end
|
1111
|
-
|
1112
|
-
headers = authorized_headers
|
1113
|
-
if allowed_origin
|
1114
|
-
headers = headers.merge({ 'Custom-Allowed-Origin-Header-1' => allowed_origin })
|
1115
|
-
end
|
1116
|
-
|
1117
|
-
response = self.class.post(
|
1118
|
-
url,
|
1119
|
-
headers: headers,
|
1120
|
-
body: query_params.to_json
|
1121
|
-
)
|
1122
|
-
|
1123
|
-
if response.code == 200
|
1124
|
-
return handle_session_token_response(response)
|
1125
|
-
else
|
1126
|
-
@error = response.code.to_s
|
1127
|
-
@error_description = extract_error_message_from_response(response)
|
1128
|
-
end
|
1129
|
-
rescue Exception => e
|
1130
|
-
@error = '500'
|
1131
|
-
@error_description = e.message
|
1132
|
-
end
|
1133
|
-
|
1134
|
-
nil
|
1135
|
-
end
|
1136
|
-
|
1137
|
-
# Verify a one-time password (OTP) value provided for multi-factor authentication (MFA).
|
1138
|
-
#
|
1139
|
-
# @param device_id [String] Provide the MFA device_id you are submitting for verification.
|
1140
|
-
# @param state_token [String] Provide the state_token associated with the MFA device_id you are submitting for verification.
|
1141
|
-
# @param otp_token [String] (Optional) Provide the OTP value for the MFA factor you are submitting for verification.
|
1142
|
-
# @param allowed_origin [String] (Optional) Required for CORS requests only. Set to the Origin URI from which you are allowed to send a request using CORS.
|
1143
|
-
# @param do_not_notify [String] (Optional) When verifying MFA via Protect Push, set this to true to stop additional push notifications being sent to the OneLogin Protect device.
|
1144
|
-
#
|
1145
|
-
# @return [SessionTokenInfo] if the action succeed
|
1146
|
-
#
|
1147
|
-
# @see {https://developers.onelogin.com/api-docs/1/users/verify-factor Verify Factor documentation}
|
1148
|
-
def get_session_token_verified(device_id, state_token, otp_token=nil, allowed_origin='', do_not_notify=false)
|
1149
|
-
clean_error
|
1150
|
-
prepare_token
|
1151
|
-
|
1152
|
-
begin
|
1153
|
-
if device_id.nil? || device_id.to_s.empty?
|
1154
|
-
@error = '400'
|
1155
|
-
@error_description = "device_id is required"
|
1156
|
-
@error_attribute = "device_id"
|
1157
|
-
return
|
1158
|
-
end
|
1159
|
-
|
1160
|
-
url = url_for(GET_TOKEN_VERIFY_FACTOR)
|
1161
|
-
|
1162
|
-
data = {
|
1163
|
-
'device_id'=> device_id.to_s,
|
1164
|
-
'state_token'=> state_token,
|
1165
|
-
'do_not_notify'=> do_not_notify
|
1166
|
-
}
|
1167
|
-
|
1168
|
-
unless otp_token.nil? || otp_token.empty?
|
1169
|
-
data['otp_token'] = otp_token
|
1170
|
-
end
|
1171
|
-
|
1172
|
-
headers = authorized_headers
|
1173
|
-
if allowed_origin
|
1174
|
-
headers = headers.merge({ 'Custom-Allowed-Origin-Header-1' => allowed_origin })
|
1175
|
-
end
|
1176
|
-
|
1177
|
-
response = self.class.post(
|
1178
|
-
url,
|
1179
|
-
headers: headers,
|
1180
|
-
body: data.to_json
|
1181
|
-
)
|
1182
|
-
|
1183
|
-
if response.code == 200
|
1184
|
-
return handle_session_token_response(response)
|
1185
|
-
else
|
1186
|
-
@error = response.code.to_s
|
1187
|
-
@error_description = extract_error_message_from_response(response)
|
1188
|
-
end
|
1189
|
-
rescue Exception => e
|
1190
|
-
@error = '500'
|
1191
|
-
@error_description = e.message
|
1192
|
-
end
|
1193
|
-
|
1194
|
-
nil
|
1195
|
-
end
|
1196
|
-
|
1197
|
-
###############################
|
1198
|
-
# Onelogin Connectors Methods #
|
1199
|
-
###############################
|
1200
|
-
|
1201
|
-
# Gets a list of Connector resources.
|
1202
|
-
#
|
1203
|
-
# @param params [Hash] Parameters to filter the result of the list
|
1204
|
-
#
|
1205
|
-
# @return [Array] list of Connector objects
|
1206
|
-
#
|
1207
|
-
# @see {https://developers.onelogin.com/api-docs/1/connectors/list-connectors List Connectors documentation}
|
1208
|
-
def get_connectors(params = {})
|
1209
|
-
clean_error
|
1210
|
-
prepare_token
|
1211
|
-
|
1212
|
-
begin
|
1213
|
-
url = url_for(GET_CONNECTORS_URL)
|
1214
|
-
|
1215
|
-
connectors = []
|
1216
|
-
response = self.class.get(
|
1217
|
-
url,
|
1218
|
-
headers: authorized_headers,
|
1219
|
-
query: params
|
1220
|
-
)
|
1221
|
-
|
1222
|
-
if response.code == 200
|
1223
|
-
json_data = JSON.parse(response.body)
|
1224
|
-
if !json_data.empty?
|
1225
|
-
json_data.each do |data|
|
1226
|
-
pp data
|
1227
|
-
connectors << OneLogin::Api::Models::ConnectorBasic.new(data)
|
1228
|
-
end
|
1229
|
-
end
|
1230
|
-
return connectors
|
1231
|
-
else
|
1232
|
-
@error = extract_status_code_from_response(response)
|
1233
|
-
@error_description = extract_error_message_from_response(response)
|
1234
|
-
end
|
1235
|
-
rescue Exception => e
|
1236
|
-
@error = '500'
|
1237
|
-
@error_description = e.message
|
1238
|
-
end
|
1239
|
-
|
1240
|
-
nil
|
1241
|
-
end
|
1242
|
-
|
1243
|
-
#########################
|
1244
|
-
# Onelogin Apps Methods #
|
1245
|
-
#########################
|
1246
|
-
|
1247
|
-
# Gets a list of OneLoginAppV1 resources. (if no limit provided, by default get 50 elements)
|
1248
|
-
#
|
1249
|
-
# @param params [Hash] Parameters to filter the result of the list
|
1250
|
-
#
|
1251
|
-
# @return [Array] list of OneLoginAppV1 objects
|
1252
|
-
#
|
1253
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/get-apps Get Apps documentation}
|
1254
|
-
def get_apps_v1(params = {})
|
1255
|
-
clean_error
|
1256
|
-
prepare_token
|
1257
|
-
|
1258
|
-
begin
|
1259
|
-
options = {
|
1260
|
-
model: OneLogin::Api::Models::OneLoginAppV1,
|
1261
|
-
headers: authorized_headers,
|
1262
|
-
max_results: @max_results,
|
1263
|
-
params: params
|
1264
|
-
}
|
1265
|
-
|
1266
|
-
return Cursor.new(self, url_for(GET_APPS_URL_V1), options)
|
1267
|
-
|
1268
|
-
rescue Exception => e
|
1269
|
-
@error = '500'
|
1270
|
-
@error_description = e.message
|
1271
|
-
end
|
1272
|
-
|
1273
|
-
nil
|
1274
|
-
end
|
1275
|
-
|
1276
|
-
# Gets a list of OneLoginAppBasic resources.
|
1277
|
-
#
|
1278
|
-
# @param params [Hash] Parameters to filter the result of the list
|
1279
|
-
#
|
1280
|
-
# @return [Array] list of OneLoginAppBasic objects
|
1281
|
-
#
|
1282
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/list-apps Get Apps documentation}
|
1283
|
-
def get_apps(params = {})
|
1284
|
-
clean_error
|
1285
|
-
prepare_token
|
1286
|
-
|
1287
|
-
begin
|
1288
|
-
url = url_for(GET_APPS_URL)
|
1289
|
-
|
1290
|
-
apps = []
|
1291
|
-
response = self.class.get(
|
1292
|
-
url,
|
1293
|
-
headers: authorized_headers,
|
1294
|
-
query: params
|
1295
|
-
)
|
1296
|
-
|
1297
|
-
if response.code == 200
|
1298
|
-
json_data = JSON.parse(response.body)
|
1299
|
-
if !json_data.empty?
|
1300
|
-
json_data.each do |data|
|
1301
|
-
apps << OneLogin::Api::Models::OneLoginAppBasic.new(data)
|
1302
|
-
end
|
1303
|
-
end
|
1304
|
-
return apps
|
1305
|
-
else
|
1306
|
-
@error = extract_status_code_from_response(response)
|
1307
|
-
@error_description = extract_error_message_from_response(response)
|
1308
|
-
end
|
1309
|
-
rescue Exception => e
|
1310
|
-
@error = '500'
|
1311
|
-
@error_description = e.message
|
1312
|
-
end
|
1313
|
-
|
1314
|
-
nil
|
1315
|
-
end
|
1316
|
-
|
1317
|
-
# Creates an app
|
1318
|
-
#
|
1319
|
-
# @param app_params [Hash] App data (name, visible, policy_id, is_available, parameters, allow_assumed_signin,
|
1320
|
-
# configuration, notes, description, provisioning,
|
1321
|
-
# connector_id, auth_method, tab_id)
|
1322
|
-
#
|
1323
|
-
# @return [OneLoginApp] the created app
|
1324
|
-
#
|
1325
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/create-app Create App documentation}
|
1326
|
-
def create_app(app_params)
|
1327
|
-
clean_error
|
1328
|
-
prepare_token
|
1329
|
-
|
1330
|
-
begin
|
1331
|
-
url = url_for(CREATE_APP_URL)
|
1332
|
-
|
1333
|
-
unless app_params.has_key?('connector_id') || app_params['connector_id'].to_s.empty?
|
1334
|
-
@error = '400'
|
1335
|
-
@error_description = "connector_id is required"
|
1336
|
-
@error_attribute = "connector_id"
|
1337
|
-
return
|
1338
|
-
end
|
1339
|
-
|
1340
|
-
response = self.class.post(
|
1341
|
-
url,
|
1342
|
-
headers: authorized_headers,
|
1343
|
-
body: app_params.to_json
|
1344
|
-
)
|
1345
|
-
|
1346
|
-
if response.code == 201
|
1347
|
-
json_data = JSON.parse(response.body)
|
1348
|
-
if json_data && json_data.has_key?('id')
|
1349
|
-
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1350
|
-
end
|
1351
|
-
else
|
1352
|
-
@error = extract_status_code_from_response(response)
|
1353
|
-
@error_description = extract_error_message_from_response(response)
|
1354
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1355
|
-
end
|
1356
|
-
rescue Exception => e
|
1357
|
-
@error = '500'
|
1358
|
-
@error_description = e.message
|
1359
|
-
end
|
1360
|
-
|
1361
|
-
nil
|
1362
|
-
end
|
1363
|
-
|
1364
|
-
# Gets a OneLoginApp resource.
|
1365
|
-
#
|
1366
|
-
# @return [OneLoginApp] OneLoginApp object
|
1367
|
-
#
|
1368
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/get-app Get App documentation}
|
1369
|
-
def get_app(app_id)
|
1370
|
-
clean_error
|
1371
|
-
prepare_token
|
1372
|
-
|
1373
|
-
begin
|
1374
|
-
if app_id.nil? || app_id.to_s.empty?
|
1375
|
-
@error = '400'
|
1376
|
-
@error_description = "app_id is required"
|
1377
|
-
@error_attribute = "app_id"
|
1378
|
-
return
|
1379
|
-
end
|
1380
|
-
|
1381
|
-
url = url_for(GET_APP_URL, app_id)
|
1382
|
-
|
1383
|
-
response = self.class.get(
|
1384
|
-
url,
|
1385
|
-
headers: authorized_headers
|
1386
|
-
)
|
1387
|
-
|
1388
|
-
if response.code == 200
|
1389
|
-
json_data = JSON.parse(response.body)
|
1390
|
-
if json_data && json_data.has_key?('id')
|
1391
|
-
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1392
|
-
end
|
1393
|
-
else
|
1394
|
-
@error = extract_status_code_from_response(response)
|
1395
|
-
@error_description = extract_error_message_from_response(response)
|
1396
|
-
end
|
1397
|
-
rescue Exception => e
|
1398
|
-
@error = '500'
|
1399
|
-
@error_description = e.message
|
1400
|
-
end
|
1401
|
-
|
1402
|
-
nil
|
1403
|
-
end
|
1404
|
-
|
1405
|
-
# Updates an app
|
1406
|
-
#
|
1407
|
-
# @param app_id [Integer] Id of the app
|
1408
|
-
# @param app_params [Hash] App data (name, visible, policy_id, is_available, parameters, allow_assumed_signin,
|
1409
|
-
# configuration, notes, description, provisioning,
|
1410
|
-
# connector_id, auth_method, tab_id)
|
1411
|
-
#
|
1412
|
-
# @return [User] the modified user
|
1413
|
-
#
|
1414
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/update-app Update App by ID documentation}
|
1415
|
-
def update_app(app_id, app_params)
|
1416
|
-
clean_error
|
1417
|
-
prepare_token
|
1418
|
-
|
1419
|
-
begin
|
1420
|
-
if app_id.nil? || app_id.to_s.empty?
|
1421
|
-
@error = '400'
|
1422
|
-
@error_description = "app_id is required"
|
1423
|
-
@error_attribute = "app_id"
|
1424
|
-
return
|
1425
|
-
end
|
1426
|
-
|
1427
|
-
url = url_for(UPDATE_APP_URL, app_id)
|
1428
|
-
|
1429
|
-
response = self.class.put(
|
1430
|
-
url,
|
1431
|
-
headers: authorized_headers,
|
1432
|
-
body: app_params.to_json
|
1433
|
-
)
|
1434
|
-
|
1435
|
-
if response.code == 200
|
1436
|
-
json_data = JSON.parse(response.body)
|
1437
|
-
if json_data && json_data.has_key?('id')
|
1438
|
-
return OneLogin::Api::Models::OneLoginApp.new(json_data)
|
1439
|
-
end
|
1440
|
-
else
|
1441
|
-
@error = response.code.to_s
|
1442
|
-
@error_description = extract_error_message_from_response(response)
|
1443
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1444
|
-
end
|
1445
|
-
rescue Exception => e
|
1446
|
-
@error = '500'
|
1447
|
-
@error_description = e.message
|
1448
|
-
end
|
1449
|
-
|
1450
|
-
nil
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
# Deletes an app
|
1454
|
-
#
|
1455
|
-
# @param app_id [Integer] Id of the app to be removed
|
1456
|
-
#
|
1457
|
-
# @return [Boolean] if the action succeed
|
1458
|
-
#
|
1459
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/delete-app Delete App by ID documentation}
|
1460
|
-
def delete_app(app_id)
|
1461
|
-
clean_error
|
1462
|
-
prepare_token
|
1463
|
-
|
1464
|
-
begin
|
1465
|
-
if app_id.nil? || app_id.to_s.empty?
|
1466
|
-
@error = '400'
|
1467
|
-
@error_description = "app_id is required"
|
1468
|
-
@error_attribute = "app_id"
|
1469
|
-
return
|
1470
|
-
end
|
1471
|
-
|
1472
|
-
url = url_for(DELETE_APP_URL, app_id)
|
1473
|
-
|
1474
|
-
response = self.class.delete(
|
1475
|
-
url,
|
1476
|
-
headers: authorized_headers
|
1477
|
-
)
|
1478
|
-
|
1479
|
-
if response.code == 204
|
1480
|
-
return true
|
1481
|
-
else
|
1482
|
-
@error = response.code.to_s
|
1483
|
-
@error_description = extract_error_message_from_response(response)
|
1484
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1485
|
-
end
|
1486
|
-
rescue Exception => e
|
1487
|
-
@error = '500'
|
1488
|
-
@error_description = e.message
|
1489
|
-
end
|
1490
|
-
|
1491
|
-
false
|
1492
|
-
end
|
1493
|
-
|
1494
|
-
# Deletes an App Parameter
|
1495
|
-
#
|
1496
|
-
# @param app_id [Integer] Id of the app
|
1497
|
-
# @param parameter_id [Integer] Id of the parameter to be removed
|
1498
|
-
#
|
1499
|
-
# @return [Boolean] if the action succeed
|
1500
|
-
#
|
1501
|
-
# @see {https://developers.onelogin.com/api-docs/1/apps/delete-parameter Delete an App Parameter documentation}
|
1502
|
-
def delete_parameter_from_app(app_id, parameter_id)
|
1503
|
-
clean_error
|
1504
|
-
prepare_token
|
1505
|
-
|
1506
|
-
begin
|
1507
|
-
if app_id.nil? || app_id.to_s.empty?
|
1508
|
-
@error = '400'
|
1509
|
-
@error_description = "app_id is required"
|
1510
|
-
@error_attribute = "app_id"
|
1511
|
-
return
|
1512
|
-
end
|
1513
|
-
|
1514
|
-
if parameter_id.nil? || parameter_id.to_s.empty?
|
1515
|
-
@error = '400'
|
1516
|
-
@error_description = "parameter_id is required"
|
1517
|
-
@error_attribute = "parameter_id"
|
1518
|
-
return
|
1519
|
-
end
|
1520
|
-
|
1521
|
-
url = url_for(DELETE_APP_PARAMETER_URL, app_id, parameter_id)
|
1522
|
-
|
1523
|
-
response = self.class.delete(
|
1524
|
-
url,
|
1525
|
-
headers: authorized_headers
|
1526
|
-
)
|
1527
|
-
|
1528
|
-
if response.code == 204
|
1529
|
-
return true
|
1530
|
-
else
|
1531
|
-
@error = response.code.to_s
|
1532
|
-
@error_description = extract_error_message_from_response(response)
|
1533
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1534
|
-
end
|
1535
|
-
rescue Exception => e
|
1536
|
-
@error = '500'
|
1537
|
-
@error_description = e.message
|
1538
|
-
end
|
1539
|
-
|
1540
|
-
false
|
1541
|
-
end
|
1542
|
-
|
1543
|
-
################
|
1544
|
-
# Role Methods #
|
1545
|
-
################
|
1546
|
-
|
1547
|
-
# Gets a list of Role resources. (if no limit provided, by default get 50 elements)
|
1548
|
-
#
|
1549
|
-
# @param params [Hash] Parameters to filter the result of the list
|
1550
|
-
#
|
1551
|
-
# @return [Array] list of Role objects
|
1552
|
-
#
|
1553
|
-
# @see {https://developers.onelogin.com/api-docs/1/roles/get-roles Get Roles documentation}
|
1554
|
-
def get_roles(params = {})
|
1555
|
-
clean_error
|
1556
|
-
prepare_token
|
1557
|
-
|
1558
|
-
begin
|
1559
|
-
options = {
|
1560
|
-
model: OneLogin::Api::Models::Role,
|
1561
|
-
headers: authorized_headers,
|
1562
|
-
max_results: @max_results,
|
1563
|
-
params: params
|
1564
|
-
}
|
1565
|
-
|
1566
|
-
return Cursor.new(self, url_for(GET_ROLES_URL), options)
|
1567
|
-
|
1568
|
-
rescue Exception => e
|
1569
|
-
@error = '500'
|
1570
|
-
@error_description = e.message
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
nil
|
1574
|
-
end
|
1575
|
-
|
1576
|
-
# Gets Role by ID.
|
1577
|
-
#
|
1578
|
-
# @param role_id [Integer] Id of the Role
|
1579
|
-
#
|
1580
|
-
# @return [Role] the role identified by the id
|
1581
|
-
#
|
1582
|
-
# @see {https://developers.onelogin.com/api-docs/1/roles/get-role-by-id Get Role by ID documentation}
|
1583
|
-
def get_role(role_id)
|
1584
|
-
clean_error
|
1585
|
-
prepare_token
|
1586
|
-
|
1587
|
-
begin
|
1588
|
-
if role_id.nil? || role_id.to_s.empty?
|
1589
|
-
@error = '400'
|
1590
|
-
@error_description = "role_id is required"
|
1591
|
-
@error_attribute = "role_id"
|
1592
|
-
return
|
1593
|
-
end
|
1594
|
-
|
1595
|
-
url = url_for(GET_ROLE_URL, role_id)
|
1596
|
-
|
1597
|
-
response = self.class.get(
|
1598
|
-
url,
|
1599
|
-
headers: authorized_headers
|
1600
|
-
)
|
1601
|
-
|
1602
|
-
if response.code == 200
|
1603
|
-
json_data = JSON.parse(response.body)
|
1604
|
-
if json_data && json_data['data']
|
1605
|
-
return OneLogin::Api::Models::Role.new(json_data['data'][0])
|
1606
|
-
end
|
1607
|
-
else
|
1608
|
-
@error = response.code.to_s
|
1609
|
-
@error_description = extract_error_message_from_response(response)
|
1610
|
-
end
|
1611
|
-
rescue Exception => e
|
1612
|
-
@error = '500'
|
1613
|
-
@error_description = e.message
|
1614
|
-
end
|
1615
|
-
|
1616
|
-
nil
|
1617
|
-
end
|
1618
|
-
|
1619
|
-
#################
|
1620
|
-
# Event Methods #
|
1621
|
-
#################
|
1622
|
-
|
1623
|
-
# List of all OneLogin event types available to the Events API.
|
1624
|
-
#
|
1625
|
-
# @return [Array] the list of event type
|
1626
|
-
#
|
1627
|
-
# @see {https://developers.onelogin.com/api-docs/1/events/event-types Get Event Types documentation}
|
1628
|
-
def get_event_types
|
1629
|
-
clean_error
|
1630
|
-
prepare_token
|
1631
|
-
|
1632
|
-
begin
|
1633
|
-
options = {
|
1634
|
-
model: OneLogin::Api::Models::EventType,
|
1635
|
-
headers: authorized_headers,
|
1636
|
-
max_results: @max_results
|
1637
|
-
}
|
1638
|
-
|
1639
|
-
return Cursor.new(self, url_for(GET_EVENT_TYPES_URL), options)
|
1640
|
-
|
1641
|
-
rescue Exception => e
|
1642
|
-
@error = '500'
|
1643
|
-
@error_description = e.message
|
1644
|
-
end
|
1645
|
-
|
1646
|
-
nil
|
1647
|
-
end
|
1648
|
-
|
1649
|
-
# Gets a list of Event resources. (if no limit provided, by default get 50 elements)
|
1650
|
-
#
|
1651
|
-
# @param params [Hash] Parameters to filter the result of the list
|
1652
|
-
#
|
1653
|
-
# @return [Array] list of Event objects
|
1654
|
-
#
|
1655
|
-
# @see {https://developers.onelogin.com/api-docs/1/events/get-events Get Events documentation}
|
1656
|
-
def get_events(params={})
|
1657
|
-
clean_error
|
1658
|
-
prepare_token
|
1659
|
-
|
1660
|
-
begin
|
1661
|
-
options = {
|
1662
|
-
model: OneLogin::Api::Models::Event,
|
1663
|
-
headers: authorized_headers,
|
1664
|
-
max_results: @max_results,
|
1665
|
-
params: params
|
1666
|
-
}
|
1667
|
-
|
1668
|
-
return Cursor.new(self, url_for(GET_EVENTS_URL), options)
|
1669
|
-
|
1670
|
-
rescue Exception => e
|
1671
|
-
@error = '500'
|
1672
|
-
@error_description = e.message
|
1673
|
-
end
|
1674
|
-
|
1675
|
-
nil
|
1676
|
-
end
|
1677
|
-
|
1678
|
-
# Gets Event by ID.
|
1679
|
-
#
|
1680
|
-
# @param event_id [Integer] Id of the Event
|
1681
|
-
#
|
1682
|
-
# @return [Event] the event identified by the id
|
1683
|
-
#
|
1684
|
-
# @see {https://developers.onelogin.com/api-docs/1/events/get-event-by-id Get Event by ID documentation}
|
1685
|
-
def get_event(event_id)
|
1686
|
-
clean_error
|
1687
|
-
prepare_token
|
1688
|
-
|
1689
|
-
begin
|
1690
|
-
if event_id.nil? || event_id.to_s.empty?
|
1691
|
-
@error = '400'
|
1692
|
-
@error_description = "event_id is required"
|
1693
|
-
@error_attribute = "event_id"
|
1694
|
-
return
|
1695
|
-
end
|
1696
|
-
|
1697
|
-
url = url_for(GET_EVENT_URL, event_id)
|
1698
|
-
|
1699
|
-
response = self.class.get(
|
1700
|
-
url,
|
1701
|
-
headers: authorized_headers
|
1702
|
-
)
|
1703
|
-
|
1704
|
-
if response.code == 200
|
1705
|
-
json_data = JSON.parse(response.body)
|
1706
|
-
if json_data && json_data['data']
|
1707
|
-
return OneLogin::Api::Models::Event.new(json_data['data'][0])
|
1708
|
-
end
|
1709
|
-
else
|
1710
|
-
@error = response.code.to_s
|
1711
|
-
@error_description = extract_error_message_from_response(response)
|
1712
|
-
end
|
1713
|
-
rescue Exception => e
|
1714
|
-
@error = '500'
|
1715
|
-
@error_description = e.message
|
1716
|
-
end
|
1717
|
-
|
1718
|
-
nil
|
1719
|
-
end
|
1720
|
-
|
1721
|
-
# Create an event in the OneLogin event log.
|
1722
|
-
#
|
1723
|
-
# @param event_params [Hash] Event data (event_type_id, account_id, actor_system,
|
1724
|
-
# actor_user_id, actor_user_name, app_id,
|
1725
|
-
# assuming_acting_user_id, custom_message,
|
1726
|
-
# directory_sync_run_id, group_id, group_name,
|
1727
|
-
# ipaddr, otp_device_id, otp_device_name,
|
1728
|
-
# policy_id, policy_name, role_id, role_name,
|
1729
|
-
# user_id, user_name)
|
1730
|
-
#
|
1731
|
-
# @return [Boolean] the result of the operation
|
1732
|
-
#
|
1733
|
-
# @see {https://developers.onelogin.com/api-docs/1/events/create-event Create Event documentation}
|
1734
|
-
def create_event(event_params)
|
1735
|
-
clean_error
|
1736
|
-
prepare_token
|
1737
|
-
|
1738
|
-
begin
|
1739
|
-
url = url_for(CREATE_EVENT_URL)
|
1740
|
-
|
1741
|
-
response = self.class.post(
|
1742
|
-
url,
|
1743
|
-
headers: authorized_headers,
|
1744
|
-
body: event_params.to_json
|
1745
|
-
)
|
1746
|
-
|
1747
|
-
if response.code == 200
|
1748
|
-
return handle_operation_response(response)
|
1749
|
-
else
|
1750
|
-
@error = response.code.to_s
|
1751
|
-
@error_description = extract_error_message_from_response(response)
|
1752
|
-
@error_attribute = extract_error_attribute_from_response(response)
|
1753
|
-
end
|
1754
|
-
rescue Exception => e
|
1755
|
-
@error = '500'
|
1756
|
-
@error_description = e.message
|
1757
|
-
end
|
1758
|
-
|
1759
|
-
false
|
1760
|
-
end
|
1761
|
-
|
1762
|
-
#################
|
1763
|
-
# Group Methods #
|
1764
|
-
#################
|
1765
|
-
|
1766
|
-
# Gets a list of Group resources (element of groups limited with the limit parameter).
|
1767
|
-
#
|
1768
|
-
# @return [Array] the list of groups
|
1769
|
-
#
|
1770
|
-
# @see {https://developers.onelogin.com/api-docs/1/groups/get-groups Get Groups documentation}
|
1771
|
-
def get_groups(params = {})
|
1772
|
-
clean_error
|
1773
|
-
prepare_token
|
1774
|
-
|
1775
|
-
begin
|
1776
|
-
options = {
|
1777
|
-
model: OneLogin::Api::Models::Group,
|
1778
|
-
headers: authorized_headers,
|
1779
|
-
max_results: @max_results,
|
1780
|
-
params: params
|
1781
|
-
}
|
1782
|
-
|
1783
|
-
return Cursor.new(self, url_for(GET_GROUPS_URL), options)
|
1784
|
-
|
1785
|
-
rescue Exception => e
|
1786
|
-
@error = '500'
|
1787
|
-
@error_description = e.message
|
1788
|
-
end
|
1789
|
-
|
1790
|
-
nil
|
1791
|
-
end
|
1792
|
-
|
1793
|
-
# Gets Group by ID.
|
1794
|
-
#
|
1795
|
-
# @param group_id [Integer] Id of the Group
|
1796
|
-
#
|
1797
|
-
# @return [Group] the group identified by the id
|
1798
|
-
#
|
1799
|
-
# @see {https://developers.onelogin.com/api-docs/1/groups/get-group-by-id Get Group by ID documentation}
|
1800
|
-
def get_group(group_id)
|
1801
|
-
clean_error
|
1802
|
-
prepare_token
|
1803
|
-
|
1804
|
-
begin
|
1805
|
-
if group_id.nil? || group_id.to_s.empty?
|
1806
|
-
@error = '400'
|
1807
|
-
@error_description = "group_id is required"
|
1808
|
-
@error_attribute = "group_id"
|
1809
|
-
return
|
1810
|
-
end
|
1811
|
-
|
1812
|
-
url = url_for(GET_GROUP_URL, group_id)
|
1813
|
-
|
1814
|
-
response = self.class.get(
|
1815
|
-
url,
|
1816
|
-
headers: authorized_headers
|
1817
|
-
)
|
1818
|
-
|
1819
|
-
if response.code == 200
|
1820
|
-
json_data = JSON.parse(response.body)
|
1821
|
-
if json_data && json_data['data']
|
1822
|
-
return OneLogin::Api::Models::Group.new(json_data['data'][0])
|
1823
|
-
end
|
1824
|
-
else
|
1825
|
-
@error = response.code.to_s
|
1826
|
-
@error_description = extract_error_message_from_response(response)
|
1827
|
-
end
|
1828
|
-
rescue Exception => e
|
1829
|
-
@error = '500'
|
1830
|
-
@error_description = e.message
|
1831
|
-
end
|
1832
|
-
|
1833
|
-
nil
|
1834
|
-
end
|
1835
|
-
|
1836
|
-
##########################
|
1837
|
-
# SAML Assertion Methods #
|
1838
|
-
##########################
|
1839
|
-
|
1840
|
-
# Generates a SAML Assertion.
|
1841
|
-
#
|
1842
|
-
# @param username_or_email [String] username or email of the OneLogin user accessing the app
|
1843
|
-
# @param password [String] Password of the OneLogin user accessing the app
|
1844
|
-
# @param app_id [String] App ID of the app for which you want to generate a SAML token
|
1845
|
-
# @param subdomain [String] subdomain of the OneLogin account related to the user/app
|
1846
|
-
# @param ip_address [String] (Optional) whitelisted IP address that needs to be bypassed (some MFA scenarios)
|
1847
|
-
#
|
1848
|
-
# @return [SAMLEndpointResponse] object with an encoded SAMLResponse
|
1849
|
-
#
|
1850
|
-
# @see {https://developers.onelogin.com/api-docs/1/saml-assertions/generate-saml-assertion Generate SAML Assertion documentation}
|
1851
|
-
def get_saml_assertion(username_or_email, password, app_id, subdomain, ip_address=nil)
|
1852
|
-
clean_error
|
1853
|
-
prepare_token
|
1854
|
-
|
1855
|
-
begin
|
1856
|
-
url = url_for(GET_SAML_ASSERTION_URL)
|
1857
|
-
|
1858
|
-
data = {
|
1859
|
-
'username_or_email'=> username_or_email,
|
1860
|
-
'password'=> password,
|
1861
|
-
'app_id'=> app_id,
|
1862
|
-
'subdomain'=> subdomain,
|
1863
|
-
}
|
1864
|
-
|
1865
|
-
unless ip_address.nil? || ip_address.empty?
|
1866
|
-
data['ip_address'] = ip_address
|
1867
|
-
end
|
1868
|
-
|
1869
|
-
response = self.class.post(
|
1870
|
-
url,
|
1871
|
-
headers: authorized_headers,
|
1872
|
-
body: data.to_json
|
1873
|
-
)
|
1874
|
-
|
1875
|
-
if response.code == 200
|
1876
|
-
return handle_saml_endpoint_response(response)
|
1877
|
-
else
|
1878
|
-
@error = response.code.to_s
|
1879
|
-
@error_description = extract_error_message_from_response(response)
|
1880
|
-
end
|
1881
|
-
rescue Exception => e
|
1882
|
-
@error = '500'
|
1883
|
-
@error_description = e.message
|
1884
|
-
end
|
1885
|
-
|
1886
|
-
nil
|
1887
|
-
end
|
1888
|
-
|
1889
|
-
# Verify a one-time password (OTP) value provided for a second factor when multi-factor authentication (MFA) is required for SAML authentication.
|
1890
|
-
#
|
1891
|
-
# @param app_id [String] App ID of the app for which you want to generate a SAML token
|
1892
|
-
# @param devide_id [String] Provide the MFA device_id you are submitting for verification.
|
1893
|
-
# @param state_token [String] Provide the state_token associated with the MFA device_id you are submitting for verification.
|
1894
|
-
# @param otp_token [String] (Optional) Provide the OTP value for the MFA factor you are submitting for verification.
|
1895
|
-
# @param url_endpoint [String] (Optional) Specify an url where return the response.
|
1896
|
-
# @param do_not_notify [String] (Optional) When verifying MFA via Protect Push, set this to true to stop additional push notifications being sent to the OneLogin Protect device
|
1897
|
-
#
|
1898
|
-
# @return [SAMLEndpointResponse] object with an encoded SAMLResponse
|
1899
|
-
#
|
1900
|
-
# @see {https://developers.onelogin.com/api-docs/1/saml-assertions/verify-factor Verify Factor documentation}
|
1901
|
-
def get_saml_assertion_verifying(app_id, device_id, state_token, otp_token=nil, url_endpoint=nil, do_not_notify=false)
|
1902
|
-
clean_error
|
1903
|
-
prepare_token
|
1904
|
-
|
1905
|
-
begin
|
1906
|
-
if app_id.nil? || app_id.to_s.empty?
|
1907
|
-
@error = '400'
|
1908
|
-
@error_description = "app_id is required"
|
1909
|
-
@error_attribute = "app_id"
|
1910
|
-
return
|
1911
|
-
end
|
1912
|
-
|
1913
|
-
if device_id.nil? || device_id.to_s.empty?
|
1914
|
-
@error = '400'
|
1915
|
-
@error_description = "device_id is required"
|
1916
|
-
@error_attribute = "device_id"
|
1917
|
-
return
|
1918
|
-
end
|
1919
|
-
|
1920
|
-
if url_endpoint.nil? || url_endpoint.empty?
|
1921
|
-
url = url_for(GET_SAML_VERIFY_FACTOR)
|
1922
|
-
else
|
1923
|
-
url = url_endpoint
|
1924
|
-
end
|
1925
|
-
|
1926
|
-
data = {
|
1927
|
-
'app_id'=> app_id,
|
1928
|
-
'device_id'=> device_id.to_s,
|
1929
|
-
'state_token'=> state_token,
|
1930
|
-
'do_not_notify'=> do_not_notify
|
1931
|
-
}
|
1932
|
-
|
1933
|
-
unless otp_token.nil? || otp_token.empty?
|
1934
|
-
data['otp_token'] = otp_token
|
1935
|
-
end
|
1936
|
-
|
1937
|
-
response = self.class.post(
|
1938
|
-
url,
|
1939
|
-
headers: authorized_headers,
|
1940
|
-
body: data.to_json
|
1941
|
-
)
|
1942
|
-
|
1943
|
-
if response.code == 200
|
1944
|
-
return handle_saml_endpoint_response(response)
|
1945
|
-
else
|
1946
|
-
@error = response.code.to_s
|
1947
|
-
@error_description = extract_error_message_from_response(response)
|
1948
|
-
end
|
1949
|
-
rescue Exception => e
|
1950
|
-
@error = '500'
|
1951
|
-
@error_description = e.message
|
1952
|
-
end
|
1953
|
-
|
1954
|
-
nil
|
1955
|
-
end
|
1956
|
-
|
1957
|
-
#############################
|
1958
|
-
# Multi-factor Auth Methods #
|
1959
|
-
#############################
|
1960
|
-
|
1961
|
-
# Returns a list of authentication factors that are available for user enrollment via API.
|
1962
|
-
#
|
1963
|
-
# @param user_id [Integer] The id of the user.
|
1964
|
-
#
|
1965
|
-
# @return [Array] AuthFactor list
|
1966
|
-
#
|
1967
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/available-factors Get Available Authentication Factors documentation}
|
1968
|
-
def get_factors(user_id)
|
1969
|
-
clean_error
|
1970
|
-
prepare_token
|
1971
|
-
|
1972
|
-
begin
|
1973
|
-
if user_id.nil? || user_id.to_s.empty?
|
1974
|
-
@error = '400'
|
1975
|
-
@error_description = "user_id is required"
|
1976
|
-
@error_attribute = "user_id"
|
1977
|
-
return
|
1978
|
-
end
|
1979
|
-
|
1980
|
-
url = url_for(GET_FACTORS_URL, user_id)
|
1981
|
-
|
1982
|
-
response = self.class.get(
|
1983
|
-
url,
|
1984
|
-
:headers => authorized_headers
|
1985
|
-
)
|
1986
|
-
|
1987
|
-
factors = []
|
1988
|
-
if response.code == 200
|
1989
|
-
json_data = JSON.parse(response.body)
|
1990
|
-
if json_data and json_data['data'] and json_data['data']['auth_factors']
|
1991
|
-
json_data['data']['auth_factors'].each do |factor_data|
|
1992
|
-
factors << OneLogin::Api::Models::AuthFactor.new(factor_data)
|
1993
|
-
end
|
1994
|
-
end
|
1995
|
-
else
|
1996
|
-
@error = response.code.to_s
|
1997
|
-
@error_description = extract_error_message_from_response(response)
|
1998
|
-
end
|
1999
|
-
return factors
|
2000
|
-
rescue Exception => e
|
2001
|
-
@error = '500'
|
2002
|
-
@error_description = e.message
|
2003
|
-
end
|
2004
|
-
|
2005
|
-
nil
|
2006
|
-
end
|
2007
|
-
|
2008
|
-
# Enroll a user with a given authentication factor.
|
2009
|
-
#
|
2010
|
-
# @param user_id [Integer] The id of the user.
|
2011
|
-
# @param factor_id [Integer] The identifier of the factor to enroll the user with.
|
2012
|
-
# @param display_name [String] A name for the users device.
|
2013
|
-
# @param number [String] The phone number of the user in E.164 format.
|
2014
|
-
#
|
2015
|
-
# @return [OTPDevice] MFA device
|
2016
|
-
#
|
2017
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/enroll-factor Enroll an Authentication Factor documentation}
|
2018
|
-
def enroll_factor(user_id, factor_id, display_name, number)
|
2019
|
-
clean_error
|
2020
|
-
prepare_token
|
2021
|
-
|
2022
|
-
begin
|
2023
|
-
if user_id.nil? || user_id.to_s.empty?
|
2024
|
-
@error = '400'
|
2025
|
-
@error_description = "user_id is required"
|
2026
|
-
@error_attribute = "user_id"
|
2027
|
-
return
|
2028
|
-
end
|
2029
|
-
|
2030
|
-
if factor_id.nil? || factor_id.to_s.empty?
|
2031
|
-
@error = '400'
|
2032
|
-
@error_description = "factor_id is required"
|
2033
|
-
@error_attribute = "factor_id"
|
2034
|
-
return
|
2035
|
-
end
|
2036
|
-
|
2037
|
-
url = url_for(ENROLL_FACTOR_URL, user_id)
|
2038
|
-
|
2039
|
-
data = {
|
2040
|
-
'factor_id'=> factor_id.to_i,
|
2041
|
-
'display_name'=> display_name,
|
2042
|
-
'number'=> number
|
2043
|
-
}
|
2044
|
-
|
2045
|
-
response = self.class.post(
|
2046
|
-
url,
|
2047
|
-
:headers => authorized_headers,
|
2048
|
-
body: data.to_json
|
2049
|
-
)
|
2050
|
-
|
2051
|
-
if response.code == 200
|
2052
|
-
json_data = JSON.parse(response.body)
|
2053
|
-
if json_data and json_data['data']
|
2054
|
-
return OneLogin::Api::Models::OTPDevice.new(json_data['data'][0])
|
2055
|
-
end
|
2056
|
-
else
|
2057
|
-
@error = response.code.to_s
|
2058
|
-
@error_description = extract_error_message_from_response(response)
|
2059
|
-
end
|
2060
|
-
rescue Exception => e
|
2061
|
-
@error = '500'
|
2062
|
-
@error_description = e.message
|
2063
|
-
end
|
2064
|
-
|
2065
|
-
nil
|
2066
|
-
end
|
2067
|
-
|
2068
|
-
# Return a list of authentication factors registered to a particular user for multifactor authentication (MFA)
|
2069
|
-
#
|
2070
|
-
# @param user_id [Integer] The id of the user.
|
2071
|
-
#
|
2072
|
-
# @return [Array] OTPDevice List
|
2073
|
-
#
|
2074
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/enrolled-factors Get Enrolled Authentication Factors documentation}
|
2075
|
-
def get_enrolled_factors(user_id)
|
2076
|
-
clean_error
|
2077
|
-
prepare_token
|
2078
|
-
|
2079
|
-
begin
|
2080
|
-
if user_id.nil? || user_id.to_s.empty?
|
2081
|
-
@error = '400'
|
2082
|
-
@error_description = "user_id is required"
|
2083
|
-
@error_attribute = "user_id"
|
2084
|
-
return
|
2085
|
-
end
|
2086
|
-
|
2087
|
-
url = url_for(GET_ENROLLED_FACTORS_URL, user_id)
|
2088
|
-
|
2089
|
-
response = self.class.get(
|
2090
|
-
url,
|
2091
|
-
:headers => authorized_headers
|
2092
|
-
)
|
2093
|
-
|
2094
|
-
otp_devices = []
|
2095
|
-
if response.code == 200
|
2096
|
-
json_data = JSON.parse(response.body)
|
2097
|
-
if json_data and json_data['data'] and json_data['data']['otp_devices']
|
2098
|
-
json_data['data']['otp_devices'].each do |otp_device_data|
|
2099
|
-
otp_devices << OneLogin::Api::Models::OTPDevice.new(otp_device_data)
|
2100
|
-
end
|
2101
|
-
end
|
2102
|
-
else
|
2103
|
-
@error = response.code.to_s
|
2104
|
-
@error_description = extract_error_message_from_response(response)
|
2105
|
-
end
|
2106
|
-
return otp_devices
|
2107
|
-
rescue Exception => e
|
2108
|
-
@error = '500'
|
2109
|
-
@error_description = e.message
|
2110
|
-
end
|
2111
|
-
|
2112
|
-
nil
|
2113
|
-
end
|
2114
|
-
|
2115
|
-
# Triggers an SMS or Push notification containing a One-Time Password (OTP)
|
2116
|
-
# that can be used to authenticate a user with the Verify Factor call.
|
2117
|
-
#
|
2118
|
-
# @param user_id [Integer] The id of the user.
|
2119
|
-
# @param device_id [Integer] The id of the MFA device.
|
2120
|
-
#
|
2121
|
-
# @return [FactorEnrollmentResponse] Info with User Id, Device Id, and OTP Device
|
2122
|
-
#
|
2123
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/activate-factor Activate an Authentication Factor documentation}
|
2124
|
-
def activate_factor(user_id, device_id)
|
2125
|
-
clean_error
|
2126
|
-
prepare_token
|
2127
|
-
|
2128
|
-
begin
|
2129
|
-
if user_id.nil? || user_id.to_s.empty?
|
2130
|
-
@error = '400'
|
2131
|
-
@error_description = "user_id is required"
|
2132
|
-
@error_attribute = "user_id"
|
2133
|
-
return
|
2134
|
-
end
|
2135
|
-
|
2136
|
-
if device_id.nil? || device_id.to_s.empty?
|
2137
|
-
@error = '400'
|
2138
|
-
@error_description = "device_id is required"
|
2139
|
-
@error_attribute = "device_id"
|
2140
|
-
return
|
2141
|
-
end
|
2142
|
-
|
2143
|
-
url = url_for(ACTIVATE_FACTOR_URL, user_id, device_id)
|
2144
|
-
|
2145
|
-
response = self.class.post(
|
2146
|
-
url,
|
2147
|
-
headers: authorized_headers
|
2148
|
-
)
|
2149
|
-
|
2150
|
-
if response.code == 200
|
2151
|
-
json_data = JSON.parse(response.body)
|
2152
|
-
if json_data && json_data['data']
|
2153
|
-
return OneLogin::Api::Models::FactorEnrollmentResponse.new(json_data['data'][0])
|
2154
|
-
end
|
2155
|
-
else
|
2156
|
-
@error = response.code.to_s
|
2157
|
-
@error_description = extract_error_message_from_response(response)
|
2158
|
-
end
|
2159
|
-
rescue Exception => e
|
2160
|
-
@error = '500'
|
2161
|
-
@error_description = e.message
|
2162
|
-
end
|
2163
|
-
|
2164
|
-
nil
|
2165
|
-
end
|
2166
|
-
|
2167
|
-
# Authenticates a one-time password (OTP) code provided by a multifactor authentication (MFA) device.
|
2168
|
-
#
|
2169
|
-
# @param user_id [Integer] The id of the user.
|
2170
|
-
# @param device_id [Integer] The id of the MFA device.
|
2171
|
-
# @param otp_token [String] OTP code provided by the device or SMS message sent to user.
|
2172
|
-
# When a device like OneLogin Protect that supports Push has
|
2173
|
-
# been used you do not need to provide the otp_token.
|
2174
|
-
# @param state_token [String] The state_token is returned after a successful request
|
2175
|
-
# to Enroll a Factor or Activate a Factor.
|
2176
|
-
# MUST be provided if the needs_trigger attribute from
|
2177
|
-
# the proceeding calls is set to true.
|
2178
|
-
#
|
2179
|
-
# @return [Boolean] True if Factor is verified
|
2180
|
-
#
|
2181
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/verify-factor Verify an Authentication Factor documentation}
|
2182
|
-
def verify_factor(user_id, device_id, otp_token=nil, state_token=nil)
|
2183
|
-
clean_error
|
2184
|
-
prepare_token
|
2185
|
-
|
2186
|
-
begin
|
2187
|
-
if user_id.nil? || user_id.to_s.empty?
|
2188
|
-
@error = '400'
|
2189
|
-
@error_description = "user_id is required"
|
2190
|
-
@error_attribute = "user_id"
|
2191
|
-
return
|
2192
|
-
end
|
2193
|
-
|
2194
|
-
if device_id.nil? || device_id.to_s.empty?
|
2195
|
-
@error = '400'
|
2196
|
-
@error_description = "device_id is required"
|
2197
|
-
@error_attribute = "device_id"
|
2198
|
-
return
|
2199
|
-
end
|
2200
|
-
|
2201
|
-
|
2202
|
-
url = url_for(VERIFY_FACTOR_URL, user_id, device_id)
|
2203
|
-
|
2204
|
-
data = {
|
2205
|
-
'user_id'=> user_id,
|
2206
|
-
'device_id'=> device_id
|
2207
|
-
}
|
2208
|
-
|
2209
|
-
unless otp_token.nil? || otp_token.empty?
|
2210
|
-
data['otp_token'] = otp_token
|
2211
|
-
end
|
2212
|
-
|
2213
|
-
unless state_token.nil? || state_token.empty?
|
2214
|
-
data['state_token'] = state_token
|
2215
|
-
end
|
2216
|
-
|
2217
|
-
response = self.class.post(
|
2218
|
-
url,
|
2219
|
-
headers: authorized_headers,
|
2220
|
-
body: data.to_json
|
2221
|
-
)
|
2222
|
-
|
2223
|
-
if response.code == 200
|
2224
|
-
return handle_operation_response(response)
|
2225
|
-
else
|
2226
|
-
@error = response.code.to_s
|
2227
|
-
@error_description = extract_error_message_from_response(response)
|
2228
|
-
end
|
2229
|
-
rescue Exception => e
|
2230
|
-
@error = '500'
|
2231
|
-
@error_description = e.message
|
2232
|
-
end
|
2233
|
-
|
2234
|
-
false
|
2235
|
-
end
|
2236
|
-
|
2237
|
-
# Remove an enrolled factor from a user.
|
2238
|
-
#
|
2239
|
-
# @param user_id [Integer] The id of the user.
|
2240
|
-
# @param device_id [Integer] The device_id of the MFA device.
|
2241
|
-
#
|
2242
|
-
# @return [Boolean] The result of the action
|
2243
|
-
#
|
2244
|
-
# @see {https://developers.onelogin.com/api-docs/1/multi-factor-authentication/remove-factor Remove a Factor documentation}
|
2245
|
-
def remove_factor(user_id, device_id)
|
2246
|
-
clean_error
|
2247
|
-
prepare_token
|
2248
|
-
|
2249
|
-
begin
|
2250
|
-
|
2251
|
-
if user_id.nil? || user_id.to_s.empty?
|
2252
|
-
@error = '400'
|
2253
|
-
@error_description = "user_id is required"
|
2254
|
-
@error_attribute = "user_id"
|
2255
|
-
return
|
2256
|
-
end
|
2257
|
-
|
2258
|
-
if device_id.nil? || device_id.to_s.empty?
|
2259
|
-
@error = '400'
|
2260
|
-
@error_description = "device_id is required"
|
2261
|
-
@error_attribute = "device_id"
|
2262
|
-
return
|
2263
|
-
end
|
2264
|
-
|
2265
|
-
url = url_for(REMOVE_FACTOR_URL, user_id, device_id)
|
2266
|
-
|
2267
|
-
response = self.class.delete(
|
2268
|
-
url,
|
2269
|
-
:headers => authorized_headers
|
2270
|
-
)
|
2271
|
-
|
2272
|
-
if response.code == 200
|
2273
|
-
return true
|
2274
|
-
else
|
2275
|
-
@error = response.code.to_s
|
2276
|
-
@error_description = extract_error_message_from_response(response)
|
2277
|
-
return false
|
2278
|
-
end
|
2279
|
-
rescue Exception => e
|
2280
|
-
@error = '500'
|
2281
|
-
@error_description = e.message
|
2282
|
-
end
|
2283
|
-
|
2284
|
-
nil
|
2285
|
-
end
|
2286
|
-
|
2287
|
-
########################
|
2288
|
-
# Invite Links Methods #
|
2289
|
-
########################
|
2290
|
-
|
2291
|
-
# Generates an invite link for a user that you have already created in your OneLogin account.
|
2292
|
-
#
|
2293
|
-
# @param email [String] Set to the email address of the user that you want to generate an invite link for.
|
2294
|
-
#
|
2295
|
-
# @return [String] the invitation link
|
2296
|
-
#
|
2297
|
-
# @see {https://developers.onelogin.com/api-docs/1/invite-links/generate-invite-link Generate Invite Link documentation}
|
2298
|
-
def generate_invite_link(email)
|
2299
|
-
clean_error
|
2300
|
-
prepare_token
|
2301
|
-
|
2302
|
-
begin
|
2303
|
-
if email.nil? || email.to_s.empty?
|
2304
|
-
@error = '400'
|
2305
|
-
@error_description = "email is required"
|
2306
|
-
@error_attribute = "email"
|
2307
|
-
return
|
2308
|
-
end
|
2309
|
-
|
2310
|
-
url = url_for(GENERATE_INVITE_LINK_URL)
|
2311
|
-
|
2312
|
-
data = {
|
2313
|
-
'email'=> email
|
2314
|
-
}
|
2315
|
-
|
2316
|
-
response = self.class.post(
|
2317
|
-
url,
|
2318
|
-
headers: authorized_headers,
|
2319
|
-
body: data.to_json
|
2320
|
-
)
|
2321
|
-
|
2322
|
-
if response.code == 200
|
2323
|
-
json_data = JSON.parse(response.body)
|
2324
|
-
if json_data && json_data['data']
|
2325
|
-
return json_data['data'][0]
|
2326
|
-
end
|
2327
|
-
else
|
2328
|
-
@error = response.code.to_s
|
2329
|
-
@error_description = extract_error_message_from_response(response)
|
2330
|
-
end
|
2331
|
-
rescue Exception => e
|
2332
|
-
@error = '500'
|
2333
|
-
@error_description = e.message
|
2334
|
-
end
|
2335
|
-
|
2336
|
-
nil
|
2337
|
-
end
|
2338
|
-
|
2339
|
-
# Sends an invite link to a user that you have already created in your OneLogin account.
|
2340
|
-
#
|
2341
|
-
# @param email [String] Set to the email address of the user that you want to send an invite link for.
|
2342
|
-
# @param personal_email [String] (Optional) If you want to send the invite email to an email other than the
|
2343
|
-
# one provided in email, provide it here. The invite link will be
|
2344
|
-
# sent to this address instead.
|
2345
|
-
#
|
2346
|
-
# @return [String] the result of the operation
|
2347
|
-
#
|
2348
|
-
# @see {https://developers.onelogin.com/api-docs/1/invite-links/send-invite-link Send Invite Link documentation}
|
2349
|
-
def send_invite_link(email, personal_email=nil)
|
2350
|
-
clean_error
|
2351
|
-
prepare_token
|
2352
|
-
|
2353
|
-
begin
|
2354
|
-
url = url_for(SEND_INVITE_LINK_URL)
|
2355
|
-
|
2356
|
-
data = {
|
2357
|
-
'email'=> email
|
2358
|
-
}
|
2359
|
-
|
2360
|
-
unless personal_email.nil? || personal_email.to_s.empty?
|
2361
|
-
data['personal_email'] = personal_email
|
2362
|
-
end
|
2363
|
-
|
2364
|
-
response = self.class.post(
|
2365
|
-
url,
|
2366
|
-
headers: authorized_headers,
|
2367
|
-
body: data.to_json
|
2368
|
-
)
|
2369
|
-
|
2370
|
-
if response.code == 200
|
2371
|
-
return handle_operation_response(response)
|
2372
|
-
else
|
2373
|
-
@error = response.code.to_s
|
2374
|
-
@error_description = extract_error_message_from_response(response)
|
2375
|
-
end
|
2376
|
-
rescue Exception => e
|
2377
|
-
@error = '500'
|
2378
|
-
@error_description = e.message
|
2379
|
-
end
|
2380
|
-
|
2381
|
-
false
|
2382
|
-
end
|
2383
|
-
|
2384
|
-
# Lists apps accessible by a OneLogin user.
|
2385
|
-
#
|
2386
|
-
# @param token [String] Provide your embedding token.
|
2387
|
-
# @param email [String] Provide the email of the user for which you want to return a list of embeddable apps.
|
2388
|
-
#
|
2389
|
-
# @return [Array] the embed apps
|
2390
|
-
#
|
2391
|
-
# @see {https://developers.onelogin.com/api-docs/1/embed-apps/get-apps-to-embed-for-a-user Get Apps to Embed for a User documentation}
|
2392
|
-
def get_embed_apps(token, email)
|
2393
|
-
clean_error
|
2394
|
-
|
2395
|
-
begin
|
2396
|
-
response = self.class.get(
|
2397
|
-
EMBED_APP_URL,
|
2398
|
-
headers: {
|
2399
|
-
'User-Agent' => @user_agent
|
2400
|
-
},
|
2401
|
-
query: {
|
2402
|
-
token: token,
|
2403
|
-
email: email
|
2404
|
-
}
|
2405
|
-
)
|
2406
|
-
|
2407
|
-
if response.code == 200 && !(response.body.nil? || response.body.empty?)
|
2408
|
-
return retrieve_apps_from_xml(response.body)
|
2409
|
-
else
|
2410
|
-
@error = response.code.to_s
|
2411
|
-
unless response.body.nil? || response.body.empty?
|
2412
|
-
@error_description = response.body
|
2413
|
-
end
|
2414
|
-
end
|
2415
|
-
rescue Exception => e
|
2416
|
-
@error = '500'
|
2417
|
-
@error_description = e.message
|
2418
|
-
end
|
2419
|
-
|
2420
|
-
nil
|
2421
|
-
end
|
2422
|
-
|
2423
|
-
def retrieve_apps_from_xml(xml_content)
|
2424
|
-
doc = Nokogiri::XML(xml_content) do |config|
|
2425
|
-
config.options = NOKOGIRI_OPTIONS
|
2426
|
-
end
|
2427
|
-
|
2428
|
-
node_list = doc.xpath("/apps/app")
|
2429
|
-
attributes = ['id', 'icon', 'name', 'provisioned', 'extension_required', 'personal', 'login_id']
|
2430
|
-
apps = []
|
2431
|
-
node_list.each do |node|
|
2432
|
-
app_data = {}
|
2433
|
-
node.children.each do |children|
|
2434
|
-
if attributes.include? children.name
|
2435
|
-
app_data[children.name] = children.content
|
2436
|
-
end
|
2437
|
-
end
|
2438
|
-
apps << OneLogin::Api::Models::EmbedApp.new(app_data)
|
2439
|
-
end
|
2440
|
-
|
2441
|
-
apps
|
2442
|
-
end
|
2443
|
-
|
2444
|
-
#####################
|
2445
|
-
# Privilege Methods #
|
2446
|
-
#####################
|
2447
|
-
|
2448
|
-
# Gets a list of the Privileges created in an account.
|
2449
|
-
#
|
2450
|
-
# @return [Array] list of privilege objects
|
2451
|
-
#
|
2452
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/list-privileges List Privileges documentation}
|
2453
|
-
def get_privileges()
|
2454
|
-
clean_error
|
2455
|
-
prepare_token
|
2456
|
-
|
2457
|
-
begin
|
2458
|
-
|
2459
|
-
url = url_for(LIST_PRIVILEGES_URL)
|
2460
|
-
|
2461
|
-
privileges = []
|
2462
|
-
response = self.class.get(
|
2463
|
-
url,
|
2464
|
-
headers: authorized_headers
|
2465
|
-
)
|
2466
|
-
|
2467
|
-
if response.code == 200
|
2468
|
-
json_data = JSON.parse(response.body)
|
2469
|
-
if !json_data.empty?
|
2470
|
-
json_data.each do |data|
|
2471
|
-
privileges << OneLogin::Api::Models::Privilege.new(data)
|
2472
|
-
end
|
2473
|
-
end
|
2474
|
-
return privileges
|
2475
|
-
else
|
2476
|
-
@error = extract_status_code_from_response(response)
|
2477
|
-
@error_description = extract_error_message_from_response(response)
|
2478
|
-
end
|
2479
|
-
rescue Exception => e
|
2480
|
-
@error = '500'
|
2481
|
-
@error_description = e.message
|
2482
|
-
end
|
2483
|
-
|
2484
|
-
nil
|
2485
|
-
end
|
2486
|
-
|
2487
|
-
# Creates a Privilege
|
2488
|
-
#
|
2489
|
-
# @param name [string] The name of the privilege.
|
2490
|
-
# @param version [string] The version for the privilege schema. Set to 2018-05-18.
|
2491
|
-
# @param statements [Array] A list of statements. Statement object or a dict with the keys Effect, Action and Scope
|
2492
|
-
#
|
2493
|
-
# @return [Privilege] the created privilege
|
2494
|
-
#
|
2495
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/create-privilege Create Privilege documentation}
|
2496
|
-
def create_privilege(name, version, statements)
|
2497
|
-
clean_error
|
2498
|
-
prepare_token
|
2499
|
-
|
2500
|
-
begin
|
2501
|
-
url = url_for(CREATE_PRIVILEGE_URL)
|
2502
|
-
|
2503
|
-
statement_data = []
|
2504
|
-
for statement in statements
|
2505
|
-
if statement.instance_of?(OneLogin::Api::Models::Statement)
|
2506
|
-
statement_data << {
|
2507
|
-
'Effect' => statement.effect,
|
2508
|
-
'Action' => statement.actions,
|
2509
|
-
'Scope' => statement.scopes
|
2510
|
-
}
|
2511
|
-
elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope')
|
2512
|
-
statement_data << statement
|
2513
|
-
else
|
2514
|
-
@error = 400.to_s
|
2515
|
-
@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"
|
2516
|
-
return
|
2517
|
-
end
|
2518
|
-
end
|
2519
|
-
|
2520
|
-
privilege_data = {
|
2521
|
-
'name' => name,
|
2522
|
-
'privilege' => {
|
2523
|
-
'Version'=> version,
|
2524
|
-
'Statement' => statement_data
|
2525
|
-
}
|
2526
|
-
}
|
2527
|
-
|
2528
|
-
response = self.class.post(
|
2529
|
-
url,
|
2530
|
-
headers: authorized_headers,
|
2531
|
-
body: privilege_data.to_json
|
2532
|
-
)
|
2533
|
-
|
2534
|
-
if response.code == 201
|
2535
|
-
json_data = JSON.parse(response.body)
|
2536
|
-
if json_data && json_data.has_key?('id')
|
2537
|
-
return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements)
|
2538
|
-
end
|
2539
|
-
else
|
2540
|
-
@error = extract_status_code_from_response(response)
|
2541
|
-
@error_description = extract_error_message_from_response(response)
|
2542
|
-
end
|
2543
|
-
rescue Exception => e
|
2544
|
-
@error = '500'
|
2545
|
-
@error_description = e.message
|
2546
|
-
end
|
2547
|
-
|
2548
|
-
nil
|
2549
|
-
end
|
2550
|
-
|
2551
|
-
# Get a Privilege.
|
2552
|
-
#
|
2553
|
-
# @param privilege_id [string] Id of the privilege
|
2554
|
-
#
|
2555
|
-
# @return [Privilege] the privilege identified by the id
|
2556
|
-
#
|
2557
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/get-privilege Get Privilege documentation}
|
2558
|
-
def get_privilege(privilege_id)
|
2559
|
-
clean_error
|
2560
|
-
prepare_token
|
2561
|
-
|
2562
|
-
begin
|
2563
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2564
|
-
@error = '400'
|
2565
|
-
@error_description = "privilege_id is required"
|
2566
|
-
@error_attribute = "privilege_id"
|
2567
|
-
return
|
2568
|
-
end
|
2569
|
-
|
2570
|
-
url = url_for(GET_PRIVILEGE_URL, privilege_id)
|
2571
|
-
|
2572
|
-
response = self.class.get(
|
2573
|
-
url,
|
2574
|
-
headers: authorized_headers
|
2575
|
-
)
|
2576
|
-
|
2577
|
-
if response.code == 200
|
2578
|
-
json_data = JSON.parse(response.body)
|
2579
|
-
if json_data && json_data.has_key?('id')
|
2580
|
-
return OneLogin::Api::Models::Privilege.new(json_data)
|
2581
|
-
end
|
2582
|
-
else
|
2583
|
-
@error = extract_status_code_from_response(response)
|
2584
|
-
@error_description = extract_error_message_from_response(response)
|
2585
|
-
end
|
2586
|
-
rescue Exception => e
|
2587
|
-
@error = '500'
|
2588
|
-
@error_description = e.message
|
2589
|
-
end
|
2590
|
-
|
2591
|
-
nil
|
2592
|
-
end
|
2593
|
-
|
2594
|
-
# Updates a Privilege
|
2595
|
-
#
|
2596
|
-
# @param privilege_id [string] The id of the privilege to be updated.
|
2597
|
-
# @param name [string] The name of the privilege.
|
2598
|
-
# @param version [string] The version for the privilege schema. Set to 2018-05-18.
|
2599
|
-
# @param statements [Array] A list of statements. Statement object or a dict with the keys Effect, Action and Scope
|
2600
|
-
#
|
2601
|
-
#
|
2602
|
-
# @return [Privilege] the modified privilege
|
2603
|
-
#
|
2604
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/update-privilege Update Privilege documentation}
|
2605
|
-
def update_privilege(privilege_id, name, version, statements)
|
2606
|
-
clean_error
|
2607
|
-
prepare_token
|
2608
|
-
|
2609
|
-
begin
|
2610
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2611
|
-
@error = '400'
|
2612
|
-
@error_description = "privilege_id is required"
|
2613
|
-
@error_attribute = "privilege_id"
|
2614
|
-
return
|
2615
|
-
end
|
2616
|
-
|
2617
|
-
url = url_for(UPDATE_PRIVILEGE_URL, privilege_id)
|
2618
|
-
|
2619
|
-
statement_data = []
|
2620
|
-
for statement in statements
|
2621
|
-
if statement.instance_of?(OneLogin::Api::Models::Statement)
|
2622
|
-
statement_data << {
|
2623
|
-
'Effect' => statement.effect,
|
2624
|
-
'Action' => statement.actions,
|
2625
|
-
'Scope' => statement.scopes
|
2626
|
-
}
|
2627
|
-
elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope')
|
2628
|
-
statement_data << statement
|
2629
|
-
else
|
2630
|
-
@error = 400.to_s
|
2631
|
-
@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"
|
2632
|
-
return
|
2633
|
-
end
|
2634
|
-
end
|
2635
|
-
|
2636
|
-
privilege_data = {
|
2637
|
-
'name' => name,
|
2638
|
-
'privilege' => {
|
2639
|
-
'Version'=> version,
|
2640
|
-
'Statement' => statement_data
|
2641
|
-
}
|
2642
|
-
}
|
2643
|
-
|
2644
|
-
response = self.class.put(
|
2645
|
-
url,
|
2646
|
-
headers: authorized_headers,
|
2647
|
-
body: privilege_data.to_json
|
2648
|
-
)
|
2649
|
-
|
2650
|
-
if response.code == 200
|
2651
|
-
json_data = JSON.parse(response.body)
|
2652
|
-
if json_data && json_data.has_key?('id')
|
2653
|
-
return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements)
|
2654
|
-
end
|
2655
|
-
else
|
2656
|
-
@error = extract_status_code_from_response(response)
|
2657
|
-
@error_description = extract_error_message_from_response(response)
|
2658
|
-
end
|
2659
|
-
rescue Exception => e
|
2660
|
-
@error = '500'
|
2661
|
-
@error_description = e.message
|
2662
|
-
end
|
2663
|
-
|
2664
|
-
nil
|
2665
|
-
end
|
2666
|
-
|
2667
|
-
# Deletes a Privilege
|
2668
|
-
#
|
2669
|
-
# @param privilege_id [string] Id of the privilege to be removed.
|
2670
|
-
#
|
2671
|
-
# @return [Boolean] if the action succeed
|
2672
|
-
#
|
2673
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/delete-privilege Delete Privilege documentation}
|
2674
|
-
def delete_privilege(privilege_id)
|
2675
|
-
clean_error
|
2676
|
-
prepare_token
|
2677
|
-
|
2678
|
-
begin
|
2679
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2680
|
-
@error = '400'
|
2681
|
-
@error_description = "privilege_id is required"
|
2682
|
-
@error_attribute = "privilege_id"
|
2683
|
-
return
|
2684
|
-
end
|
2685
|
-
|
2686
|
-
url = url_for(DELETE_PRIVILEGE_URL, privilege_id)
|
2687
|
-
|
2688
|
-
response = self.class.delete(
|
2689
|
-
url,
|
2690
|
-
headers: authorized_headers
|
2691
|
-
)
|
2692
|
-
|
2693
|
-
if response.code == 204
|
2694
|
-
return handle_operation_response(response)
|
2695
|
-
else
|
2696
|
-
@error = extract_status_code_from_response(response)
|
2697
|
-
@error_description = extract_error_message_from_response(response)
|
2698
|
-
end
|
2699
|
-
rescue Exception => e
|
2700
|
-
@error = '500'
|
2701
|
-
@error_description = e.message
|
2702
|
-
end
|
2703
|
-
|
2704
|
-
false
|
2705
|
-
end
|
2706
|
-
|
2707
|
-
# Gets a list of the roles assigned to a privilege.
|
2708
|
-
#
|
2709
|
-
# @param privilege_id [string] Id of the privilege.
|
2710
|
-
#
|
2711
|
-
# @return [Array] list of Role Id
|
2712
|
-
#
|
2713
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/get-roles Get Assigned Roles documentation}
|
2714
|
-
def get_roles_assigned_to_privilege(privilege_id)
|
2715
|
-
clean_error
|
2716
|
-
prepare_token
|
2717
|
-
|
2718
|
-
begin
|
2719
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2720
|
-
@error = '400'
|
2721
|
-
@error_description = "privilege_id is required"
|
2722
|
-
@error_attribute = "privilege_id"
|
2723
|
-
return
|
2724
|
-
end
|
2725
|
-
|
2726
|
-
options = {
|
2727
|
-
headers: authorized_headers,
|
2728
|
-
max_results: @max_results,
|
2729
|
-
container: 'roles'
|
2730
|
-
}
|
2731
|
-
|
2732
|
-
return Cursor.new(self, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
|
2733
|
-
|
2734
|
-
rescue Exception => e
|
2735
|
-
@error = '500'
|
2736
|
-
@error_description = e.message
|
2737
|
-
end
|
2738
|
-
|
2739
|
-
nil
|
2740
|
-
end
|
2741
|
-
|
2742
|
-
# Assign one or more roles to a privilege.
|
2743
|
-
#
|
2744
|
-
# @param privilege_id [string] Id of the privilege.
|
2745
|
-
# @param role_ids [Array] Ids of the roles to be added.
|
2746
|
-
#
|
2747
|
-
# @return [Boolean] if the action succeed
|
2748
|
-
#
|
2749
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/assign-role Assign Roles documentation}
|
2750
|
-
def assign_roles_to_privilege(privilege_id, role_ids)
|
2751
|
-
clean_error
|
2752
|
-
prepare_token
|
2753
|
-
|
2754
|
-
begin
|
2755
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2756
|
-
@error = '400'
|
2757
|
-
@error_description = "privilege_id is required"
|
2758
|
-
@error_attribute = "privilege_id"
|
2759
|
-
return
|
2760
|
-
end
|
2761
|
-
|
2762
|
-
url = url_for(ASSIGN_ROLES_TO_PRIVILEGE_URL, privilege_id)
|
2763
|
-
|
2764
|
-
data = {
|
2765
|
-
'roles' => role_ids
|
2766
|
-
}
|
2767
|
-
|
2768
|
-
response = self.class.post(
|
2769
|
-
url,
|
2770
|
-
headers: authorized_headers,
|
2771
|
-
body: data.to_json
|
2772
|
-
)
|
2773
|
-
|
2774
|
-
if response.code == 201
|
2775
|
-
return handle_operation_response(response)
|
2776
|
-
else
|
2777
|
-
@error = extract_status_code_from_response(response)
|
2778
|
-
@error_description = extract_error_message_from_response(response)
|
2779
|
-
|
2780
|
-
end
|
2781
|
-
rescue Exception => e
|
2782
|
-
@error = '500'
|
2783
|
-
@error_description = e.message
|
2784
|
-
end
|
2785
|
-
|
2786
|
-
false
|
2787
|
-
end
|
2788
|
-
|
2789
|
-
# Removes one role from the privilege.
|
2790
|
-
#
|
2791
|
-
# @param privilege_id [string] Id of the privilege.
|
2792
|
-
# @param role_id [Integer] Id of the role to be removed.
|
2793
|
-
#
|
2794
|
-
# @return [Boolean] if the action succeed
|
2795
|
-
#
|
2796
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/remove-role Remove Role documentation}
|
2797
|
-
def remove_role_from_privilege(privilege_id, role_id)
|
2798
|
-
clean_error
|
2799
|
-
prepare_token
|
2800
|
-
|
2801
|
-
begin
|
2802
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2803
|
-
@error = '400'
|
2804
|
-
@error_description = "privilege_id is required"
|
2805
|
-
@error_attribute = "privilege_id"
|
2806
|
-
return
|
2807
|
-
end
|
2808
|
-
|
2809
|
-
url = url_for(REMOVE_ROLE_FROM_PRIVILEGE_URL, privilege_id, role_id)
|
2810
|
-
|
2811
|
-
response = self.class.delete(
|
2812
|
-
url,
|
2813
|
-
headers: authorized_headers
|
2814
|
-
)
|
2815
|
-
|
2816
|
-
if response.code == 204
|
2817
|
-
return true
|
2818
|
-
else
|
2819
|
-
@error = extract_status_code_from_response(response)
|
2820
|
-
@error_description = extract_error_message_from_response(response)
|
2821
|
-
end
|
2822
|
-
rescue Exception => e
|
2823
|
-
@error = '500'
|
2824
|
-
@error_description = e.message
|
2825
|
-
end
|
2826
|
-
|
2827
|
-
false
|
2828
|
-
end
|
2829
|
-
|
2830
|
-
# Gets a list of the users assigned to a privilege.
|
2831
|
-
#
|
2832
|
-
# @param privilege_id [string] Id of the privilege.
|
2833
|
-
#
|
2834
|
-
# @return [Array] list of User Id
|
2835
|
-
#
|
2836
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/get-users Get Assigned Users documentation}
|
2837
|
-
def get_users_assigned_to_privilege(privilege_id)
|
2838
|
-
clean_error
|
2839
|
-
prepare_token
|
2840
|
-
|
2841
|
-
begin
|
2842
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2843
|
-
@error = '400'
|
2844
|
-
@error_description = "privilege_id is required"
|
2845
|
-
@error_attribute = "privilege_id"
|
2846
|
-
return
|
2847
|
-
end
|
2848
|
-
|
2849
|
-
options = {
|
2850
|
-
headers: authorized_headers,
|
2851
|
-
max_results: @max_results,
|
2852
|
-
container: 'users'
|
2853
|
-
}
|
2854
|
-
|
2855
|
-
return Cursor.new(self, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
|
2856
|
-
|
2857
|
-
rescue Exception => e
|
2858
|
-
@error = '500'
|
2859
|
-
@error_description = e.message
|
2860
|
-
end
|
2861
|
-
|
2862
|
-
nil
|
2863
|
-
end
|
2864
|
-
|
2865
|
-
# Assign one or more users to a privilege.
|
2866
|
-
#
|
2867
|
-
# @param privilege_id [string] Id of the privilege.
|
2868
|
-
# @param user_ids [Array] Ids of the users to be added.
|
2869
|
-
#
|
2870
|
-
# @return [Boolean] if the action succeed
|
2871
|
-
#
|
2872
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/assign-users Assign Users documentation}
|
2873
|
-
def assign_users_to_privilege(privilege_id, user_ids)
|
2874
|
-
clean_error
|
2875
|
-
prepare_token
|
2876
|
-
|
2877
|
-
begin
|
2878
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2879
|
-
@error = '400'
|
2880
|
-
@error_description = "privilege_id is required"
|
2881
|
-
@error_attribute = "privilege_id"
|
2882
|
-
return
|
2883
|
-
end
|
2884
|
-
|
2885
|
-
url = url_for(ASSIGN_USERS_TO_PRIVILEGE_URL, privilege_id)
|
2886
|
-
|
2887
|
-
data = {
|
2888
|
-
'users' => user_ids
|
2889
|
-
}
|
2890
|
-
|
2891
|
-
response = self.class.post(
|
2892
|
-
url,
|
2893
|
-
headers: authorized_headers,
|
2894
|
-
body: data.to_json
|
2895
|
-
)
|
2896
|
-
|
2897
|
-
if response.code == 201
|
2898
|
-
return handle_operation_response(response)
|
2899
|
-
else
|
2900
|
-
@error = extract_status_code_from_response(response)
|
2901
|
-
@error_description = extract_error_message_from_response(response)
|
2902
|
-
end
|
2903
|
-
rescue Exception => e
|
2904
|
-
@error = '500'
|
2905
|
-
@error_description = e.message
|
2906
|
-
end
|
2907
|
-
|
2908
|
-
false
|
2909
|
-
end
|
2910
|
-
|
2911
|
-
# Removes one user from the privilege.
|
2912
|
-
#
|
2913
|
-
# @param privilege_id [string] Id of the privilege.
|
2914
|
-
# @param user_id [Integer] Id of the user to be removed.
|
2915
|
-
#
|
2916
|
-
# @return [Boolean] if the action succeed
|
2917
|
-
#
|
2918
|
-
# @see {https://developers.onelogin.com/api-docs/1/privileges/remove-user Remove User documentation}
|
2919
|
-
def remove_user_from_privilege(privilege_id, user_id)
|
2920
|
-
clean_error
|
2921
|
-
prepare_token
|
2922
|
-
|
2923
|
-
begin
|
2924
|
-
if privilege_id.nil? || privilege_id.to_s.empty?
|
2925
|
-
@error = '400'
|
2926
|
-
@error_description = "privilege_id is required"
|
2927
|
-
@error_attribute = "privilege_id"
|
2928
|
-
return
|
2929
|
-
end
|
2930
|
-
|
2931
|
-
url = url_for(REMOVE_USER_FROM_PRIVILEGE_URL, privilege_id, user_id)
|
2932
|
-
|
2933
|
-
response = self.class.delete(
|
2934
|
-
url,
|
2935
|
-
headers: authorized_headers
|
2936
|
-
)
|
2937
|
-
|
2938
|
-
if response.code == 204
|
2939
|
-
return true
|
2940
|
-
else
|
2941
|
-
@error = extract_status_code_from_response(response)
|
2942
|
-
@error_description = extract_error_message_from_response(response)
|
2943
|
-
end
|
2944
|
-
rescue Exception => e
|
2945
|
-
@error = '500'
|
2946
|
-
@error_description = e.message
|
2947
|
-
end
|
2948
|
-
|
2949
|
-
false
|
2950
|
-
end
|
2951
|
-
|
2952
|
-
end
|
2953
|
-
end
|
2954
|
-
end
|