I am Implementing foreman rest api in ruby, where i need to authenticate every api, for which i am using basic auth, and it is working fine.
But i need authentication via consumer key & consumer secret
My code is
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.basic_auth("admin", "masked")
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
Do you mean the consumer info from a host registered with
subscription-manager?
Here’s the code that passes that info on to candlepin calls, if it helps.
ekohl
#3
If you mean just Foreman, then we have some helpers here that could serve as inspiration.
I’m sure apipie-bindings could also provide you with oauth but I don’t see a simple example.
No, actually i mean to say, i want call this API “https://192.168.21.2/api/hosts.json”
with consumer key and consumer secret in authorization header
But i did not see anything on internet regarding authentication of this rest API with key and secret,
equest.basic_auth(“admin”, “masked”)
No, actually i mean to say, i want call this API “https://192.168.21.2/api/hosts.json”
with consumer key and consumer secret in authorization header
But i did not see anything on internet regarding authentication of this rest API with key and secret,
Thank thomas for your reply,
But actually i need Authorization header with this API call, i don’t want do with basic ouath.