Skip to content

Commit 4929b9a

Browse files
committed
fix for #271 Invalid OAuth1 signature for GET request
1 parent 0afda7d commit 4929b9a

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

RestSharp.IntegrationTests/oAuth1Tests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,33 @@ public void Can_Retrieve_Member_Profile_Field_Field_Selector_From_LinkedIN()
261261
Assert.NotNull( response.Data.FirstName );
262262
Assert.NotNull( response.Data.LastName );
263263
}
264+
265+
[Fact( Skip = "Provide your own consumer key/secret before running" )]
266+
public void Can_Query_Vimeo()
267+
{
268+
const string consumerKey = "TODO_CONSUMER_KEY_HERE";
269+
const string consumerSecret = "TODO_CONSUMER_SECRET_HERE";
270+
271+
// arrange
272+
var client = new RestClient {
273+
BaseUrl = "http://vimeo.com/api/rest/v2",
274+
Authenticator = OAuth1Authenticator.ForRequestToken( consumerKey, consumerSecret )
275+
};
276+
var request = new RestRequest();
277+
request.AddParameter( "format", "json" );
278+
request.AddParameter( "method", "vimeo.videos.search" );
279+
request.AddParameter( "query", "weather" );
280+
request.AddParameter( "full_response", 1 );
281+
282+
// act
283+
var response = client.Execute( request );
284+
285+
// assert
286+
Assert.NotNull( response );
287+
Assert.Equal( HttpStatusCode.OK, response.StatusCode );
288+
Assert.NotNull( response.Content );
289+
Assert.False( response.Content.Contains( "\"stat\":\"fail\"" ) );
290+
Assert.True( response.Content.Contains( "\"stat\":\"ok\"" ) );
291+
}
264292
}
265293
}

RestSharp/Authenticators/OAuth1Authenticator.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace RestSharp.Authenticators
1717
{
18+
/// <seealso href="http://tools.ietf.org/html/rfc5849"/>
1819
public class OAuth1Authenticator : IAuthenticator
1920
{
2021
public virtual string Realm { get; set; }
@@ -156,13 +157,14 @@ private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflo
156157

157158
var parameters = new WebParameterCollection();
158159

159-
// for non-GET style requests make sure params are part of oauth signature
160-
if (request.Method != Method.GET && request.Method != Method.DELETE)
160+
// include all GET and POST parameters before generating the signature
161+
// according to the RFC 5849 - The OAuth 1.0 Protocol
162+
// http://tools.ietf.org/html/rfc5849#section-3.4.1
163+
// if this change causes trouble we need to introduce a flag indicating the specific OAuth implementation level,
164+
// or implement a seperate class for each OAuth version
165+
foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
161166
{
162-
foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
163-
{
164-
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
165-
}
167+
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
166168
}
167169

168170
switch (Type)

0 commit comments

Comments
 (0)