Welcome Guest, you are in: Login

Fulton Wiki

RSS RSS

Navigation





Search the wiki
»

PoweredBy

Instructions for connecting to RavenHQ

RSS
Modified on 2012/06/07 04:10 by Ben Fulton Categorized as Uncategorized
the way authentication works with ravenhq is a bit complex.

You access the server, which returns a 401 with the header "OAuth-Source" You then need to do a post to this url with the api key in the headers. You take the reply of the url and use is as the credentials.

this is following the oauth spec.

Here is the code in C#

var oauthSource = response.Headers["OAuth-Source"];
if (string.IsNullOrEmpty(oauthSource))
	return null;

var authRequest = WebRequest.Create(oauthSource);
SetHeader(authRequest.Headers, "Api-Key", ApiKey);

using (var authResponse = authRequest.GetResponse())
using (var stream = authResponse.GetResponseStreamWithHttpDecompression())
using (var reader = new StreamReader(stream))
{
	currentOauthToken = "Bearer " + reader.ReadToEnd();
	return (Action<HttpWebRequest>)(request => SetHeader(request.Headers, "Authorization", currentOauthToken));}}

It seems like this Ruby code should work.

require 'net/http'

uri = URI('http://1.ravenhq.com/databases/mydb')

res = Net::HTTP.get_response(uri)


puts res['OAuth-Source']


It didn't, so I used HttParty instead:

require 'httparty'

response = HTTParty.get('https://1.ravenhq.com/docs')
response = HTTParty.get(response.headers['oauth-source'], :headers => { "Api-Key" => ApiKey})
auth = "Bearer " + response.body
response = HTTParty.get('https://1.ravenhq.com/databases/benfulton-SourcedTriples/docs/?start=0&pageSize=10', :headers => { "Authorization" => auth })
puts response.body, response.code, response.message, response.headers.inspect

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.