I always got unauthorized error while creating host create rest API in ruby

While creating access token via Ouath i always getting unauthorized error.
My code is

  @consumer=OAuth::Consumer.new "pctYkcA8Qnt8dkpTD3T6ndvPJpbnGFTk", "4Mxbg6whfHXNY4zMzP2VtSmWGc36nMEW",  {:site=>"http://192.168.21.2"}         
  @request_token = @consumer.get_request_token    

Api request code is

module ForemanConfigurator
  require "open-uri"    
  require 'uri'
  require 'net/http'
  require 'json'
  require 'oauth'
  # Example: Plugin's HostsController inherits from Foreman's HostsController
  class ConfiguratorsController < ApplicationController
    # change layout if needed
    # layout 'foreman_configurator/layouts/new_layout'

    def new_action
      # automatically renders view/foreman_configurator/hosts/new_action
    end
    
    def create_host    
        @consumer=OAuth::Consumer.new "pctYkcA8Qnt8dkpTD3T6ndvPJpbnGFTk", "4Mxbg6whfHXNY4zMzP2VtSmWGc36nMEW",  {:site=>"http://192.168.21.2"}         
        @request_token = @consumer.get_request_token                              
        uri = URI.parse("https://192.168.21.2/api/hosts.json")
        host_param = {host: {architecture_id: 1, build: "false", domain_id: 1, enabled: "true", environment_id: 1, hostgroup_id: 1, mac: "ec:b1:d7:50:40:e9", medium_id: 9,model_id: 1, name: "r8sysdpl010.localdomain", operatingsystem_id: 1, owner_id: 3, owner_type:"User", ptable_id: 120, puppet_status: "0"}}
        header = {'Content-Type' => 'application/json'}
        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        request = Net::HTTP::Post.new(uri.path, header)     
        request.body = host_param.to_json
        response = http.request(request)
        if response.code == "301"
          response =  Net::HTTP.get_response(URI.parse(response.header['location']))
        end
        @response = response.body
    end
  end
end

I want to set authorization header with consumer key and consumer secret.

Hi,
I think you get an unauthorized response because you generate @request_token, but you do not use it for your request. Maybe this example will help?

O.

In this example they have 4 values.

Initialisation based on string values:

consumer_key = ‘AVff2raXvhMUxFnif06g’
consumer_secret = ‘u0zg77R1bQqbzutAusJYmTxqeUpWVt7U2TjWlzbVZkA’
access_token = ‘R1bQqbzYm0zg77tAusJzbVZkAVt7U2T’
access_token_secret = ‘sVbVZkAt7U2TjWlJYmTxqR1bQqbzutAuWzeUpu0zg77’

But in my case i only have consumer key and consumer secret
what would be the initial value for access_token and access_token_secret