onelogin 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -0
- data/examples/events-to-csv.rb +2 -2
- data/examples/rails-custom-login-page/app/assets/stylesheets/application.css +3 -3
- data/examples/rails-custom-login-page/app/controllers/sessions_controller.rb +26 -0
- data/examples/rails-custom-login-page/app/helpers/sessions_helper.rb +27 -0
- data/examples/rails-custom-login-page/app/views/dashboard/index.html.erb +41 -28
- data/examples/rails-custom-login-page/app/views/home/index.html.erb +136 -33
- data/examples/rails-custom-login-page/app/views/layouts/application.html.erb +1 -0
- data/examples/rails-custom-login-page/app/views/users/index.html.erb +7 -7
- data/examples/rails-custom-login-page/app/views/users/show.html.erb +6 -4
- data/examples/rails-custom-login-page/config/routes.rb +2 -0
- data/lib/onelogin/api/client.rb +455 -4
- data/lib/onelogin/api/cursor.rb +16 -5
- data/lib/onelogin/api/models.rb +2 -0
- data/lib/onelogin/api/models/privilege.rb +51 -0
- data/lib/onelogin/api/models/statement.rb +36 -0
- data/lib/onelogin/api/util/constants.rb +86 -0
- data/lib/onelogin/api/util/parser.rb +24 -10
- data/lib/onelogin/version.rb +1 -1
- metadata +5 -3
| @@ -6,6 +6,7 @@ | |
| 6 6 |  | 
| 7 7 | 
             
                <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
         | 
| 8 8 | 
             
                <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
         | 
| 9 | 
            +
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
         | 
| 9 10 | 
             
              </head>
         | 
| 10 11 |  | 
| 11 12 | 
             
              <body>
         | 
| @@ -2,21 +2,21 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            <h1>Users</h1>
         | 
| 4 4 |  | 
| 5 | 
            -
            <table class=" | 
| 5 | 
            +
            <table class="table">
         | 
| 6 6 | 
             
              <thead>
         | 
| 7 7 | 
             
                <tr>
         | 
| 8 | 
            -
                  <th>Name</th>
         | 
| 9 | 
            -
                  <th>Email</th>
         | 
| 10 | 
            -
                  <th>Phone</th>
         | 
| 11 | 
            -
                  <th>Custom Field</th>
         | 
| 12 | 
            -
                  <th colspan="2"></th>
         | 
| 8 | 
            +
                  <th scope="col">Name</th>
         | 
| 9 | 
            +
                  <th scope="col">Email</th>
         | 
| 10 | 
            +
                  <th scope="col">Phone</th>
         | 
| 11 | 
            +
                  <th scope="col">Custom Field</th>
         | 
| 12 | 
            +
                  <th  scope="col" colspan="2"></th>
         | 
| 13 13 | 
             
                </tr>
         | 
| 14 14 | 
             
              </thead>
         | 
| 15 15 |  | 
| 16 16 | 
             
              <tbody>
         | 
| 17 17 | 
             
                <% @users.each do |user| %>
         | 
| 18 18 | 
             
                  <tr>
         | 
| 19 | 
            -
                    <td><%= user.firstname %> <%= user.lastname %></td>
         | 
| 19 | 
            +
                    <td  scope="row"><%= user.firstname %> <%= user.lastname %></td>
         | 
| 20 20 | 
             
                    <td><%= user.email %></td>
         | 
| 21 21 | 
             
                    <td><%= user.phone %></td>
         | 
| 22 22 | 
             
                    <td><%= user.custom_attributes["custom_field"] if user.custom_attributes.is_a?(Hash) %></td>
         | 
| @@ -5,8 +5,10 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            <h2>Profile</h2>
         | 
| 7 7 |  | 
| 8 | 
            +
            <ul class="list-group">
         | 
| 8 9 | 
             
            <%@user.instance_values.symbolize_keys.each do |k, v|%>
         | 
| 9 | 
            -
              < | 
| 10 | 
            -
                < | 
| 11 | 
            -
              </ | 
| 12 | 
            -
            <%end%>
         | 
| 10 | 
            +
              <li class="list-group-item">
         | 
| 11 | 
            +
                <b><%= k%>:</b> <%= v%>
         | 
| 12 | 
            +
              </li>
         | 
| 13 | 
            +
            <%end%>
         | 
| 14 | 
            +
            </ul>
         | 
| @@ -4,6 +4,8 @@ Rails.application.routes.draw do | |
| 4 4 | 
             
              post 'login', to: 'sessions#new', as: 'new_session'
         | 
| 5 5 | 
             
              get 'logout', to: 'sessions#destroy', as: 'destroy_session'
         | 
| 6 6 | 
             
              post 'verify_mfa', to: 'sessions#verify', as: 'verify_mfa'
         | 
| 7 | 
            +
              post 'forgot_password', to: 'sessions#forgot_password', as: 'forgot_password'
         | 
| 8 | 
            +
              post 'reset_password', to: 'sessions#reset_password', as: 'reset_password'
         | 
| 7 9 |  | 
| 8 10 | 
             
              get 'dashboard', to: 'dashboard#index'
         | 
| 9 11 |  | 
    
        data/lib/onelogin/api/client.rb
    CHANGED
    
    | @@ -80,8 +80,12 @@ module OneLogin | |
| 80 80 | 
             
                    result = false
         | 
| 81 81 | 
             
                    begin
         | 
| 82 82 | 
             
                      content = JSON.parse(response.body)
         | 
| 83 | 
            -
                      if content | 
| 84 | 
            -
                         | 
| 83 | 
            +
                      if content
         | 
| 84 | 
            +
                        if content.has_key?('status') && content['status'].has_key?('type') && content['status']['type'] == "success"
         | 
| 85 | 
            +
                          result = true
         | 
| 86 | 
            +
                        elsif content.has_key?('success') && content['success']
         | 
| 87 | 
            +
                          result = true
         | 
| 88 | 
            +
                        end
         | 
| 85 89 | 
             
                      end
         | 
| 86 90 | 
             
                    rescue Exception => e
         | 
| 87 91 | 
             
                      result = false
         | 
| @@ -134,8 +138,9 @@ module OneLogin | |
| 134 138 | 
             
                  end
         | 
| 135 139 |  | 
| 136 140 | 
             
                  def authorized_headers(bearer = true)
         | 
| 141 | 
            +
                    # Removed the ":"
         | 
| 137 142 | 
             
                    authorization = if bearer
         | 
| 138 | 
            -
                      "bearer | 
| 143 | 
            +
                      "bearer #{@access_token}"
         | 
| 139 144 | 
             
                    else
         | 
| 140 145 | 
             
                      "client_id:#{@client_id},client_secret:#{@client_secret}"
         | 
| 141 146 | 
             
                    end
         | 
| @@ -904,7 +909,7 @@ module OneLogin | |
| 904 909 |  | 
| 905 910 | 
             
                  # Deletes an user
         | 
| 906 911 | 
             
                  #
         | 
| 907 | 
            -
                  # @param user_id [Integer] Id of the user to be  | 
| 912 | 
            +
                  # @param user_id [Integer] Id of the user to be removed
         | 
| 908 913 | 
             
                  #
         | 
| 909 914 | 
             
                  # @return [Boolean] if the action succeed
         | 
| 910 915 | 
             
                  #
         | 
| @@ -1826,6 +1831,452 @@ module OneLogin | |
| 1826 1831 | 
             
                    apps
         | 
| 1827 1832 | 
             
                  end
         | 
| 1828 1833 |  | 
| 1834 | 
            +
                  #####################
         | 
| 1835 | 
            +
                  # Privilege Methods #
         | 
| 1836 | 
            +
                  #####################
         | 
| 1837 | 
            +
             | 
| 1838 | 
            +
                  # Gets a list of the Privileges created in an account.
         | 
| 1839 | 
            +
                  #
         | 
| 1840 | 
            +
                  # @return [Array] list of privilege objects
         | 
| 1841 | 
            +
                  #
         | 
| 1842 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/list-privileges List Privileges documentation}
         | 
| 1843 | 
            +
                  def get_privileges()
         | 
| 1844 | 
            +
                    clean_error
         | 
| 1845 | 
            +
                    prepare_token
         | 
| 1846 | 
            +
             | 
| 1847 | 
            +
                    begin
         | 
| 1848 | 
            +
             | 
| 1849 | 
            +
                      url = url_for(LIST_PRIVILEGES_URL)
         | 
| 1850 | 
            +
             | 
| 1851 | 
            +
                      privileges = []
         | 
| 1852 | 
            +
                      response = self.class.get(
         | 
| 1853 | 
            +
                        url,
         | 
| 1854 | 
            +
                        headers: authorized_headers
         | 
| 1855 | 
            +
                      )
         | 
| 1856 | 
            +
             | 
| 1857 | 
            +
                      if response.code == 200
         | 
| 1858 | 
            +
                        json_data = JSON.parse(response.body)
         | 
| 1859 | 
            +
                        if !json_data.empty?
         | 
| 1860 | 
            +
                          json_data.each do |data|
         | 
| 1861 | 
            +
                            privileges << OneLogin::Api::Models::Privilege.new(data)
         | 
| 1862 | 
            +
                          end
         | 
| 1863 | 
            +
                        end
         | 
| 1864 | 
            +
                        return privileges
         | 
| 1865 | 
            +
                      else
         | 
| 1866 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 1867 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 1868 | 
            +
                      end
         | 
| 1869 | 
            +
                    rescue Exception => e
         | 
| 1870 | 
            +
                      @error = '500'
         | 
| 1871 | 
            +
                      @error_description = e.message
         | 
| 1872 | 
            +
                    end
         | 
| 1873 | 
            +
             | 
| 1874 | 
            +
                    nil
         | 
| 1875 | 
            +
                  end
         | 
| 1876 | 
            +
             | 
| 1877 | 
            +
                  # Creates a Privilege
         | 
| 1878 | 
            +
                  #
         | 
| 1879 | 
            +
                  # @param name [string] The name of the privilege.
         | 
| 1880 | 
            +
                  # @param version [string] The version for the privilege schema. Set to 2018-05-18.
         | 
| 1881 | 
            +
                  # @param statements [Array] A list of statements. Statement object or a dict with the keys Effect, Action and Scope
         | 
| 1882 | 
            +
                  #
         | 
| 1883 | 
            +
                  # @return [Privilege] the created privilege
         | 
| 1884 | 
            +
                  #
         | 
| 1885 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/create-privilege Create Privilege documentation}
         | 
| 1886 | 
            +
                  def create_privilege(name, version, statements)
         | 
| 1887 | 
            +
                    clean_error
         | 
| 1888 | 
            +
                    prepare_token
         | 
| 1889 | 
            +
             | 
| 1890 | 
            +
                    begin
         | 
| 1891 | 
            +
                      url = url_for(CREATE_PRIVILEGE_URL)
         | 
| 1892 | 
            +
             | 
| 1893 | 
            +
                      statement_data = []
         | 
| 1894 | 
            +
                      for statement in statements
         | 
| 1895 | 
            +
                        if statement.instance_of?(OneLogin::Api::Models::Statement)
         | 
| 1896 | 
            +
                          statement_data << {
         | 
| 1897 | 
            +
                           'Effect' => statement.effect,
         | 
| 1898 | 
            +
                           'Action' => statement.actions,
         | 
| 1899 | 
            +
                           'Scope' => statement.scopes
         | 
| 1900 | 
            +
                          }
         | 
| 1901 | 
            +
                        elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope')
         | 
| 1902 | 
            +
                          statement_data << statement
         | 
| 1903 | 
            +
                        else
         | 
| 1904 | 
            +
                          @error = 400.to_s
         | 
| 1905 | 
            +
                          @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"
         | 
| 1906 | 
            +
                          return
         | 
| 1907 | 
            +
                        end
         | 
| 1908 | 
            +
                      end
         | 
| 1909 | 
            +
             | 
| 1910 | 
            +
                      privilege_data = {
         | 
| 1911 | 
            +
                        'name' => name,
         | 
| 1912 | 
            +
                        'privilege' => {
         | 
| 1913 | 
            +
                          'Version'=> version,
         | 
| 1914 | 
            +
                          'Statement' => statement_data
         | 
| 1915 | 
            +
                        }
         | 
| 1916 | 
            +
                      }
         | 
| 1917 | 
            +
             | 
| 1918 | 
            +
                      response = self.class.post(
         | 
| 1919 | 
            +
                        url,
         | 
| 1920 | 
            +
                        headers: authorized_headers,
         | 
| 1921 | 
            +
                        body: privilege_data.to_json
         | 
| 1922 | 
            +
                      )
         | 
| 1923 | 
            +
             | 
| 1924 | 
            +
                      if response.code == 201
         | 
| 1925 | 
            +
                        json_data = JSON.parse(response.body)
         | 
| 1926 | 
            +
                        if json_data && json_data.has_key?('id')
         | 
| 1927 | 
            +
                          return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements)
         | 
| 1928 | 
            +
                        end
         | 
| 1929 | 
            +
                      else
         | 
| 1930 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 1931 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 1932 | 
            +
                      end
         | 
| 1933 | 
            +
                    rescue Exception => e
         | 
| 1934 | 
            +
                      @error = '500'
         | 
| 1935 | 
            +
                      @error_description = e.message
         | 
| 1936 | 
            +
                    end
         | 
| 1937 | 
            +
             | 
| 1938 | 
            +
                    nil
         | 
| 1939 | 
            +
                  end
         | 
| 1940 | 
            +
             | 
| 1941 | 
            +
                  # Get a Privilege.
         | 
| 1942 | 
            +
                  #
         | 
| 1943 | 
            +
                  # @param privilege_id [string] Id of the privilege
         | 
| 1944 | 
            +
                  #
         | 
| 1945 | 
            +
                  # @return [Privilege] the privilege identified by the id
         | 
| 1946 | 
            +
                  #
         | 
| 1947 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/get-privilege Get Privilege documentation}
         | 
| 1948 | 
            +
                  def get_privilege(privilege_id)
         | 
| 1949 | 
            +
                    clean_error
         | 
| 1950 | 
            +
                    prepare_token
         | 
| 1951 | 
            +
             | 
| 1952 | 
            +
                    begin
         | 
| 1953 | 
            +
             | 
| 1954 | 
            +
                      url = url_for(GET_PRIVILEGE_URL, privilege_id)
         | 
| 1955 | 
            +
             | 
| 1956 | 
            +
                      response = self.class.get(
         | 
| 1957 | 
            +
                        url,
         | 
| 1958 | 
            +
                        headers: authorized_headers
         | 
| 1959 | 
            +
                      )
         | 
| 1960 | 
            +
             | 
| 1961 | 
            +
                      if response.code == 200
         | 
| 1962 | 
            +
                        json_data = JSON.parse(response.body)
         | 
| 1963 | 
            +
                        if json_data && json_data.has_key?('id')
         | 
| 1964 | 
            +
                          return OneLogin::Api::Models::Privilege.new(json_data)
         | 
| 1965 | 
            +
                        end
         | 
| 1966 | 
            +
                      else
         | 
| 1967 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 1968 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 1969 | 
            +
                      end
         | 
| 1970 | 
            +
                    rescue Exception => e
         | 
| 1971 | 
            +
                      @error = '500'
         | 
| 1972 | 
            +
                      @error_description = e.message
         | 
| 1973 | 
            +
                    end
         | 
| 1974 | 
            +
             | 
| 1975 | 
            +
                    nil
         | 
| 1976 | 
            +
                  end
         | 
| 1977 | 
            +
             | 
| 1978 | 
            +
                  # Updates a Privilege
         | 
| 1979 | 
            +
                  #
         | 
| 1980 | 
            +
                  # @param privilege_id [string] The id of the privilege to be updated.
         | 
| 1981 | 
            +
                  # @param name [string] The name of the privilege.
         | 
| 1982 | 
            +
                  # @param version [string] The version for the privilege schema. Set to 2018-05-18.
         | 
| 1983 | 
            +
                  # @param statements [Array] A list of statements. Statement object or a dict with the keys Effect, Action and Scope
         | 
| 1984 | 
            +
                  #
         | 
| 1985 | 
            +
                  #
         | 
| 1986 | 
            +
                  # @return [Privilege] the modified privilege
         | 
| 1987 | 
            +
                  #
         | 
| 1988 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/update-privilege Update Privilege documentation}
         | 
| 1989 | 
            +
                  def update_privilege(privilege_id, name, version, statements)
         | 
| 1990 | 
            +
                    clean_error
         | 
| 1991 | 
            +
                    prepare_token
         | 
| 1992 | 
            +
             | 
| 1993 | 
            +
                    begin
         | 
| 1994 | 
            +
                      url = url_for(UPDATE_PRIVILEGE_URL, privilege_id)
         | 
| 1995 | 
            +
             | 
| 1996 | 
            +
                     statement_data = []
         | 
| 1997 | 
            +
                      for statement in statements
         | 
| 1998 | 
            +
                        if statement.instance_of?(OneLogin::Api::Models::Statement)
         | 
| 1999 | 
            +
                          statement_data << {
         | 
| 2000 | 
            +
                           'Effect' => statement.effect,
         | 
| 2001 | 
            +
                           'Action' => statement.actions,
         | 
| 2002 | 
            +
                           'Scope' => statement.scopes
         | 
| 2003 | 
            +
                          }
         | 
| 2004 | 
            +
                        elsif statement.instance_of?(Hash) && statement.has_key?('Effect') && statement.has_key?('Action') && statement.has_key?('Scope')
         | 
| 2005 | 
            +
                          statement_data << statement
         | 
| 2006 | 
            +
                        else
         | 
| 2007 | 
            +
                          @error = 400.to_s
         | 
| 2008 | 
            +
                          @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"
         | 
| 2009 | 
            +
                          return
         | 
| 2010 | 
            +
                        end
         | 
| 2011 | 
            +
                      end
         | 
| 2012 | 
            +
             | 
| 2013 | 
            +
                      privilege_data = {
         | 
| 2014 | 
            +
                        'name' => name,
         | 
| 2015 | 
            +
                        'privilege' => {
         | 
| 2016 | 
            +
                          'Version'=> version,
         | 
| 2017 | 
            +
                          'Statement' => statement_data
         | 
| 2018 | 
            +
                        }
         | 
| 2019 | 
            +
                      }
         | 
| 2020 | 
            +
             | 
| 2021 | 
            +
                      response = self.class.put(
         | 
| 2022 | 
            +
                        url,
         | 
| 2023 | 
            +
                        headers: authorized_headers,
         | 
| 2024 | 
            +
                        body: privilege_data.to_json
         | 
| 2025 | 
            +
                      )
         | 
| 2026 | 
            +
             | 
| 2027 | 
            +
                      if response.code == 200
         | 
| 2028 | 
            +
                        json_data = JSON.parse(response.body)
         | 
| 2029 | 
            +
                        if json_data && json_data.has_key?('id')
         | 
| 2030 | 
            +
                          return OneLogin::Api::Models::Privilege.new(json_data['id'], name, version, statements)
         | 
| 2031 | 
            +
                        end
         | 
| 2032 | 
            +
                      else
         | 
| 2033 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2034 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2035 | 
            +
                      end
         | 
| 2036 | 
            +
                    rescue Exception => e
         | 
| 2037 | 
            +
                      @error = '500'
         | 
| 2038 | 
            +
                      @error_description = e.message
         | 
| 2039 | 
            +
                    end
         | 
| 2040 | 
            +
             | 
| 2041 | 
            +
                    nil
         | 
| 2042 | 
            +
                  end
         | 
| 2043 | 
            +
             | 
| 2044 | 
            +
                  # Deletes a Privilege
         | 
| 2045 | 
            +
                  #
         | 
| 2046 | 
            +
                  # @param privilege_id [string] Id of the privilege to be removed.
         | 
| 2047 | 
            +
                  #
         | 
| 2048 | 
            +
                  # @return [Boolean] if the action succeed
         | 
| 2049 | 
            +
                  #
         | 
| 2050 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/delete-privilege Delete Privilege documentation}
         | 
| 2051 | 
            +
                  def delete_privilege(privilege_id)
         | 
| 2052 | 
            +
                    clean_error
         | 
| 2053 | 
            +
                    prepare_token
         | 
| 2054 | 
            +
             | 
| 2055 | 
            +
                    begin
         | 
| 2056 | 
            +
                      url = url_for(DELETE_PRIVILEGE_URL, privilege_id)
         | 
| 2057 | 
            +
             | 
| 2058 | 
            +
                      response = self.class.delete(
         | 
| 2059 | 
            +
                        url,
         | 
| 2060 | 
            +
                        headers: authorized_headers
         | 
| 2061 | 
            +
                      )
         | 
| 2062 | 
            +
             | 
| 2063 | 
            +
                      if response.code == 204
         | 
| 2064 | 
            +
                        return handle_operation_response(response)
         | 
| 2065 | 
            +
                      else
         | 
| 2066 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2067 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2068 | 
            +
                      end
         | 
| 2069 | 
            +
                    rescue Exception => e
         | 
| 2070 | 
            +
                      @error = '500'
         | 
| 2071 | 
            +
                      @error_description = e.message
         | 
| 2072 | 
            +
                    end
         | 
| 2073 | 
            +
             | 
| 2074 | 
            +
                    false
         | 
| 2075 | 
            +
                  end
         | 
| 2076 | 
            +
             | 
| 2077 | 
            +
                  # Gets a list of the roles assigned to a privilege.
         | 
| 2078 | 
            +
                  #
         | 
| 2079 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2080 | 
            +
                  #
         | 
| 2081 | 
            +
                  # @return [Array] list of Role Id
         | 
| 2082 | 
            +
                  #
         | 
| 2083 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/get-roles Get Assigned Roles documentation}
         | 
| 2084 | 
            +
                  def get_roles_assigned_to_privilege(privilege_id)
         | 
| 2085 | 
            +
                    clean_error
         | 
| 2086 | 
            +
                    prepare_token
         | 
| 2087 | 
            +
             | 
| 2088 | 
            +
                    begin
         | 
| 2089 | 
            +
                      options = {
         | 
| 2090 | 
            +
                        headers: authorized_headers,
         | 
| 2091 | 
            +
                        max_results: @max_results,
         | 
| 2092 | 
            +
                        container: 'roles'
         | 
| 2093 | 
            +
                      }
         | 
| 2094 | 
            +
             | 
| 2095 | 
            +
                      return Cursor.new(self.class, url_for(GET_ROLES_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
         | 
| 2096 | 
            +
             | 
| 2097 | 
            +
                    rescue Exception => e
         | 
| 2098 | 
            +
                      @error = '500'
         | 
| 2099 | 
            +
                      @error_description = e.message
         | 
| 2100 | 
            +
                    end
         | 
| 2101 | 
            +
             | 
| 2102 | 
            +
                    nil
         | 
| 2103 | 
            +
                  end
         | 
| 2104 | 
            +
             | 
| 2105 | 
            +
                  # Assign one or more roles to a privilege.
         | 
| 2106 | 
            +
                  #
         | 
| 2107 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2108 | 
            +
                  # @param role_ids [Array] Ids of the roles to be added.
         | 
| 2109 | 
            +
                  #
         | 
| 2110 | 
            +
                  # @return [Boolean] if the action succeed
         | 
| 2111 | 
            +
                  #
         | 
| 2112 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/assign-role Assign Roles documentation}
         | 
| 2113 | 
            +
                  def assign_roles_to_privilege(privilege_id, role_ids)
         | 
| 2114 | 
            +
                    clean_error
         | 
| 2115 | 
            +
                    prepare_token
         | 
| 2116 | 
            +
             | 
| 2117 | 
            +
                    begin
         | 
| 2118 | 
            +
                      url = url_for(ASSIGN_ROLES_TO_PRIVILEGE_URL, privilege_id)
         | 
| 2119 | 
            +
             | 
| 2120 | 
            +
                      data = {
         | 
| 2121 | 
            +
                        'roles' => role_ids
         | 
| 2122 | 
            +
                      }
         | 
| 2123 | 
            +
             | 
| 2124 | 
            +
                      response = self.class.post(
         | 
| 2125 | 
            +
                        url,
         | 
| 2126 | 
            +
                        headers: authorized_headers,
         | 
| 2127 | 
            +
                        body: data.to_json
         | 
| 2128 | 
            +
                      )
         | 
| 2129 | 
            +
             | 
| 2130 | 
            +
                      if response.code == 201
         | 
| 2131 | 
            +
                        return handle_operation_response(response)
         | 
| 2132 | 
            +
                      else
         | 
| 2133 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2134 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2135 | 
            +
             | 
| 2136 | 
            +
                      end
         | 
| 2137 | 
            +
                    rescue Exception => e
         | 
| 2138 | 
            +
                      @error = '500'
         | 
| 2139 | 
            +
                      @error_description = e.message
         | 
| 2140 | 
            +
                    end
         | 
| 2141 | 
            +
             | 
| 2142 | 
            +
                    false
         | 
| 2143 | 
            +
                  end
         | 
| 2144 | 
            +
             | 
| 2145 | 
            +
                  # Removes one role from the privilege.
         | 
| 2146 | 
            +
                  #
         | 
| 2147 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2148 | 
            +
                  # @param role_id [Integer] Id of the role to be removed.
         | 
| 2149 | 
            +
                  #
         | 
| 2150 | 
            +
                  # @return [Boolean] if the action succeed
         | 
| 2151 | 
            +
                  #
         | 
| 2152 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/remove-role Remove Role documentation}
         | 
| 2153 | 
            +
                  def remove_role_from_privilege(privilege_id, role_id)
         | 
| 2154 | 
            +
                    clean_error
         | 
| 2155 | 
            +
                    prepare_token
         | 
| 2156 | 
            +
             | 
| 2157 | 
            +
                    begin
         | 
| 2158 | 
            +
                      url = url_for(REMOVE_ROLE_FROM_PRIVILEGE_URL, privilege_id, role_id)
         | 
| 2159 | 
            +
             | 
| 2160 | 
            +
                      response = self.class.delete(
         | 
| 2161 | 
            +
                        url,
         | 
| 2162 | 
            +
                        headers: authorized_headers
         | 
| 2163 | 
            +
                      )
         | 
| 2164 | 
            +
             | 
| 2165 | 
            +
                      if response.code == 204
         | 
| 2166 | 
            +
                        return true
         | 
| 2167 | 
            +
                      else
         | 
| 2168 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2169 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2170 | 
            +
                      end
         | 
| 2171 | 
            +
                    rescue Exception => e
         | 
| 2172 | 
            +
                      @error = '500'
         | 
| 2173 | 
            +
                      @error_description = e.message
         | 
| 2174 | 
            +
                    end
         | 
| 2175 | 
            +
             | 
| 2176 | 
            +
                    false
         | 
| 2177 | 
            +
                  end
         | 
| 2178 | 
            +
             | 
| 2179 | 
            +
                  # Gets a list of the users assigned to a privilege.
         | 
| 2180 | 
            +
                  #
         | 
| 2181 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2182 | 
            +
                  #
         | 
| 2183 | 
            +
                  # @return [Array] list of User Id
         | 
| 2184 | 
            +
                  #
         | 
| 2185 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/get-users Get Assigned Users documentation}
         | 
| 2186 | 
            +
                  def get_users_assigned_to_privilege(privilege_id)
         | 
| 2187 | 
            +
                    clean_error
         | 
| 2188 | 
            +
                    prepare_token
         | 
| 2189 | 
            +
             | 
| 2190 | 
            +
                    begin
         | 
| 2191 | 
            +
                      options = {
         | 
| 2192 | 
            +
                        headers: authorized_headers,
         | 
| 2193 | 
            +
                        max_results: @max_results,
         | 
| 2194 | 
            +
                        container: 'users'
         | 
| 2195 | 
            +
                      }
         | 
| 2196 | 
            +
             | 
| 2197 | 
            +
                      return Cursor.new(self.class, url_for(GET_USERS_ASSIGNED_TO_PRIVILEGE_URL, privilege_id), options)
         | 
| 2198 | 
            +
             | 
| 2199 | 
            +
                    rescue Exception => e
         | 
| 2200 | 
            +
                      @error = '500'
         | 
| 2201 | 
            +
                      @error_description = e.message
         | 
| 2202 | 
            +
                    end
         | 
| 2203 | 
            +
             | 
| 2204 | 
            +
                    nil
         | 
| 2205 | 
            +
                  end
         | 
| 2206 | 
            +
             | 
| 2207 | 
            +
                  # Assign one or more users to a privilege.
         | 
| 2208 | 
            +
                  #
         | 
| 2209 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2210 | 
            +
                  # @param user_ids [Array] Ids of the users to be added.
         | 
| 2211 | 
            +
                  #
         | 
| 2212 | 
            +
                  # @return [Boolean] if the action succeed
         | 
| 2213 | 
            +
                  #
         | 
| 2214 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/assign-users Assign Users documentation}
         | 
| 2215 | 
            +
                  def assign_users_to_privilege(privilege_id, user_ids)
         | 
| 2216 | 
            +
                    clean_error
         | 
| 2217 | 
            +
                    prepare_token
         | 
| 2218 | 
            +
             | 
| 2219 | 
            +
                    begin
         | 
| 2220 | 
            +
                      url = url_for(ASSIGN_USERS_TO_PRIVILEGE_URL, privilege_id)
         | 
| 2221 | 
            +
             | 
| 2222 | 
            +
                      data = {
         | 
| 2223 | 
            +
                        'users' => user_ids
         | 
| 2224 | 
            +
                      }
         | 
| 2225 | 
            +
             | 
| 2226 | 
            +
                      response = self.class.post(
         | 
| 2227 | 
            +
                        url,
         | 
| 2228 | 
            +
                        headers: authorized_headers,
         | 
| 2229 | 
            +
                        body: data.to_json
         | 
| 2230 | 
            +
                      )
         | 
| 2231 | 
            +
             | 
| 2232 | 
            +
                      if response.code == 201
         | 
| 2233 | 
            +
                        return handle_operation_response(response)
         | 
| 2234 | 
            +
                      else
         | 
| 2235 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2236 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2237 | 
            +
                      end
         | 
| 2238 | 
            +
                    rescue Exception => e
         | 
| 2239 | 
            +
                      @error = '500'
         | 
| 2240 | 
            +
                      @error_description = e.message
         | 
| 2241 | 
            +
                    end
         | 
| 2242 | 
            +
             | 
| 2243 | 
            +
                    false
         | 
| 2244 | 
            +
                  end
         | 
| 2245 | 
            +
             | 
| 2246 | 
            +
                  # Removes one user from the privilege.
         | 
| 2247 | 
            +
                  #
         | 
| 2248 | 
            +
                  # @param privilege_id [string] Id of the privilege.
         | 
| 2249 | 
            +
                  # @param user_id [Integer] Id of the user to be removed.
         | 
| 2250 | 
            +
                  #
         | 
| 2251 | 
            +
                  # @return [Boolean] if the action succeed
         | 
| 2252 | 
            +
                  #
         | 
| 2253 | 
            +
                  # @see {https://developers.onelogin.com/api-docs/1/privileges/remove-user Remove User documentation}
         | 
| 2254 | 
            +
                  def remove_user_from_privilege(privilege_id, user_id)
         | 
| 2255 | 
            +
                    clean_error
         | 
| 2256 | 
            +
                    prepare_token
         | 
| 2257 | 
            +
             | 
| 2258 | 
            +
                    begin
         | 
| 2259 | 
            +
                      url = url_for(REMOVE_USER_FROM_PRIVILEGE_URL, privilege_id, user_id)
         | 
| 2260 | 
            +
             | 
| 2261 | 
            +
                      response = self.class.delete(
         | 
| 2262 | 
            +
                        url,
         | 
| 2263 | 
            +
                        headers: authorized_headers
         | 
| 2264 | 
            +
                      )
         | 
| 2265 | 
            +
             | 
| 2266 | 
            +
                      if response.code == 204
         | 
| 2267 | 
            +
                        return true
         | 
| 2268 | 
            +
                      else
         | 
| 2269 | 
            +
                        @error = extract_status_code_from_response(response)
         | 
| 2270 | 
            +
                        @error_description = extract_error_message_from_response(response)
         | 
| 2271 | 
            +
                      end
         | 
| 2272 | 
            +
                    rescue Exception => e
         | 
| 2273 | 
            +
                      @error = '500'
         | 
| 2274 | 
            +
                      @error_description = e.message
         | 
| 2275 | 
            +
                    end
         | 
| 2276 | 
            +
             | 
| 2277 | 
            +
                    false
         | 
| 2278 | 
            +
                  end
         | 
| 2279 | 
            +
             | 
| 1829 2280 | 
             
                end
         | 
| 1830 2281 | 
             
              end
         | 
| 1831 2282 | 
             
            end
         |