1

I'm looking to set up a test against the Vimeo API and have been using some of the RestSharp tests to set me up. However, since these test were written Vimeo now requirs OAuth2 rather than OAuth1.

I'm having difficulty trying to find resources online advising how I might be able to set up OAuth2 for my test. Based on the below code could someone advise on how I'd need to refactor my code to be able to run the test successfully(NB-I'm aware that I'm using "OAuth1Authenticator", which is what was originally there)

public void Can_Query_Vimeo()
    {
        const string consumerKey = "?????";
        const string consumerSecret = "?????";

        // arrange
        var client = new RestClient
        {
            BaseUrl = new Uri("http://vimeo.com/api/rest/v2"),
            Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret)
        };
        var request = new RestRequest();

        request.AddParameter("format", "json");
        request.AddParameter("method", "vimeo.videos.search");
        request.AddParameter("query", "weather");
        request.AddParameter("full_response", 1);

        // act
        var response = client.Execute(request);

        // assert
        Assert.NotNull(response);
        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        Assert.NotNull(response.Content);
        Assert.False(response.Content.Contains("\"stat\":\"fail\""));
        Assert.True(response.Content.Contains("\"stat\":\"ok\""));
    }
0

You need to write a class that implements IAuthenticator.

public interface IAuthenticator
{
    void Authenticate(IRestClient client, IRestRequest request);
}

and inherits from OAuth2Authenticator.

What the Authenticate method should do is take the client and the request, and put an "Authorization" header on your request with your authorization token, however it needs to be done. The ones I've implemented have all been against Microsoft's Azure Active Directory, so I send them a multipart form-data request with the appropriate parameters. They send me back a token embedded in JSON, and then I put the appropriate token information on my request. I don't know exactly how to retrieve your token for Vimeo.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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