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.