Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm writing a library in C# to help me develop a Windows application. The library uses the Ubuntu One API. I am able to authenticate and can even make requests to get the Quota (access to Account Admin API) and Volumes (so I know I have access to the Files API at least) Here's what I have as my Upload code:

    public static void UploadFile(string filename, string filepath)
    {
        FileStream file = File.OpenRead(filepath);
        byte[] bytes = new byte[file.Length];
        file.Read(bytes, 0, (int)file.Length);

        RestClient client = UbuntuOneClients.FilesClient();
        RestRequest request = UbuntuOneRequests.BaseRequest(Method.PUT);
        request.Resource = "/content/~/Ubuntu One/" + filename;
        request.AddHeader("Content-Length", bytes.Length.ToString());
        request.AddParameter("body", bytes, ParameterType.RequestBody);

        client.ExecuteAsync(request, webResponse => UploadComplete(webResponse));
    }

Every time I send the request I get an "Unauthorized" response from the server.

For now the "/content/~/Ubuntu One/" is hardcoded, but I checked and it is the location of my root volume. Is there anything that I'm missing?

UbuntuOneClients.FilesClient() starts the url with "https://files.one.ubuntu.com" UbuntuOneRequests.BaseRequest(Method.{}) is the same requests that I use to send my Quota and Volumes requests, basically just provides all of the parameters needed to authenticate.

EDIT:: Here's the BaseRequest() method:

    public static RestRequest BaseRequest(Method method)
    {
        RestRequest request = new RestRequest(method);
        request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
        request.AddParameter("realm", "");
        request.AddParameter("oauth_version", "1.0");
        request.AddParameter("oauth_nonce", Guid.NewGuid().ToString());
        request.AddParameter("oauth_timestamp", DateTime.Now.ToString());
        request.AddParameter("oauth_consumer_key", UbuntuOneRefreshInfo.UbuntuOneInfo.ConsumerKey);
        request.AddParameter("oauth_token", UbuntuOneRefreshInfo.UbuntuOneInfo.Token);
        request.AddParameter("oauth_signature_method", "PLAINTEXT");
        request.AddParameter("oauth_signature", UbuntuOneRefreshInfo.UbuntuOneInfo.Signature);
        //request.AddParameter("method", method.ToString());

        return request;
    }

and the FilesClient() method:

    public static RestClient FilesClient()
    {
        return (new RestClient("https://files.one.ubuntu.com"));
    }
share|improve this question
    
for reference, here's the BaseRequest() method –  Ethan Shafer Nov 22 '12 at 21:45
add comment

1 Answer

oauth_signature seems to be hardcoded in your case and this will not work. You need to calculate the signature based on all the OAuth parameters, query string and HTTP method.

You may want to look at OAuth code page for available implementations.

share|improve this answer
    
The 'UbuntuOneRefreshInfo.UbuntuOneInfo.Signature' property is the value of '"{MyConsumerSecret}" + %26 + "{MyTokenSecret}"' (based off of the API which reads 'oauth_signature="$consumer_secret%26$token_secret"') see link –  Ethan Shafer Nov 27 '12 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.