HTTP basic auth question

Hi, I am working on a project to attempt to begin using Smartfile API in ruby. I want to get started so I can model it out and release an open source gem client. I'm having trouble currently figuring out the basic auth to get calls going.

Here is what net:http library is explaining is the correct way to use basic auth. I'm not sure what I'm doing wrong, possibly putting my api key and password in the wrong places? Do I need a username that is my "web" username in the request as well, or just the key and password?

Basic Authentication 

Basic authentication is performed according to [RFC2617](www.ietf.org/rfc/rfc2617.txt)

uri = URI('http://example.com/index.html?key=value')

req = Net::HTTP::Get.new(uri)
req.basic_auth 'user', 'pass'

res = Net::HTTP.start(uri.hostname, uri.port) {|http|
  http.request(req)
}
puts res.body

What exactly is my "user" and "pass" that I should use in the above code sample?

req.basic_auth 'myapikey', 'myapipass'

Above is what I've tried  and I'm getting this response:   <Net::HTTPNotAcceptable 406 NOT ACCEPTABLE readbody=true>

 

Thanks for your help!

-Ryan

3replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • I actually just solved the auth part of the problem now. http://curl.it helped me to get the pieces in place in my headers. Now I've got a different problem.. The response was a 200 OK, but the response body is supposed to be JSON, and I'm getting this  (ASCII?) instead-- any thoughts? I am passing Accept and Content-Type headers set to "application/json"

    "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03]\x90\xCDJC1\x10\x85_\xA5\xCCZ\x12[\xFA\x03]\xE9+\x14\\\x89\x94x\xEF\xD4\x0E\xE4\xCF\xC9\xA4ZJ\xDF\xDDInE\xE9.\xE7\xCBd\xCE9\xB9@-\xC8\xB0\x9D]\xFA!\xBA\x80*\xE0\x1D1\xCB\x00\x0F38\x10\x17\xD9\xFF\xF2\xDD\xD9\xC5F\xBD\xFB\a\e\xB8\x1F\xA8\xEC\x9B<\x8A\xE4\xB2\xB5\xD6\xE5lJp,\a\xF2h\x86\x14\x94\x90]\xD8\xE6i'3\xDB\xDD$\xEF\xDD tj\xCB\x84+*\xFB\xACI\x9C\xCAX\xBDWy\x7F\xCD\xC9w\xE7\xE71P\xA4\"\xEC$q\xDB\x85\xDF\x99TP\x8A\x7F\x8F?8\xD5\\T\xBF\xC2\x8BZ\x17xS\x98\xBEb\xFF\x82\xDB\xCC1MUz \f\x8Ez\x13\xD6bOS\xD2\x96\x1F\xAE-\xCA82\x96\xB6\x0E6s\xB3\\\x9B\xCD\xA3\x99/Vp\xFD\x01%\x1A\xE7KV\x01\x00\x00"
    
    Reply Like
  • Answering my own question again, apparently the library I'm using for defaults the encoding to ASCII. (http://stackoverflow.com/questions/1207335/how-to-convert-a-nethttp-response-to-a-certain-encoding-in-ruby-1-9-1)I might just need to get a better HTTP library. No assistance needed I guess. I may be back later with more questions!

    Reply Like
  • There was an issue last week with "application/json". The fix will be deployed in the next push to production. See http://smartfile.forumbee.com/t/37ss4 for more information.

    You are correct that JSON should be the default response type.

    Reply Like
Like Follow
  • 5 yrs agoLast active
  • 3Replies
  • 1029Views
  • 2 Following