Question

This is a call to a Usergrid-stack web app to create a new application:

curl -H "Authorization: Bearer <auth_token>" \
     -H "Content-Type: application/json" \
     -X POST -d '{ "name":"myapp" }' \
     http://<node ip>:8080/management/orgs/<org_name>/apps

Here's my Ruby code:

uri = URI.parse("http://#{server.ipv4_address}:8080/management/orgs/#{form.org_name}/apps")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri, {'Authorization' => 'Bearer #{form.auth_token}', 'Content-Type' => 'application/json'})
request.set_form({"name" => form.app_name})
command.output.puts uri.request_uri
response = http.request(request)

Currently I'm getting this response from the server:

{\"error\":\"auth_unverified_oath\",\"timestamp\":1383613556291,\"duration\":0,\"exception\":\"org.usergrid.rest.exceptions.SecurityException\",\"error_description\":\"Unable to authenticate OAuth credentials\"}"
Was it helpful?

Solution

In this line--

request = Net::HTTP::Post.new(uri.request_uri, {'Authorization' => 'Bearer #{form.auth_token}', 'Content-Type' => 'application/json'})

Try changing that authorization string to "Bearer #{form.auth_token}"--with double quotes. String interpolation only works with double-quoted strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top