Skip to content

Commit d95b473

Browse files
author
Michael Hallett
committed
Merge branch 'master' of https://github.com/restsharp/RestSharp into 608_Encoding
2 parents 659511f + 6d3ef35 commit d95b473

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ Backup/
4141
*.htm
4242
*.orig
4343
DownloadSigned/
44+
RestSharp.IntegrationTests/config.json

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Features
88

9-
* Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android, Compact Framework 3.5
9+
* Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android
1010
* Easy installation using [NuGet](http://nuget.org/packages/RestSharp) for most .NET flavors
1111
* Supports strong naming using [NuGet](http://nuget.org/packages/RestSharpSigned) for most .NET flavors
1212
* Automatic XML and JSON deserialization
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ConsumerKey": "",
3+
"ConsumerSecret": "",
4+
"AccessToken": "",
5+
"AccessSecret": ""
6+
}

RestSharp.IntegrationTests/oAuth1Tests.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using RestSharp.Contrib;
1010
using RestSharp.IntegrationTests.Models;
1111
using Xunit;
12+
using System.IO;
1213

1314
namespace RestSharp.IntegrationTests
1415
{
@@ -20,7 +21,7 @@ public void Can_Authenticate_With_OAuth()
2021
const string consumerKey = "";
2122
const string consumerSecret = "";
2223

23-
var baseUrl = new Uri("http://api.twitter.com");
24+
var baseUrl = new Uri("https://api.twitter.com");
2425
var client = new RestClient(baseUrl);
2526

2627
client.Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret);
@@ -85,6 +86,40 @@ public void Can_Authenticate_With_OAuth()
8586
//Assert.Equal(HttpStatusCode.OK, response.StatusCode);
8687
}
8788

89+
[Fact(Skip = "Provide your own consumer key/secret before running")]
90+
public void Can_Authenticate_Twitter()
91+
{
92+
// To pass this test, place a file config.json in the RestSharp.IntegrationTests folder
93+
// with the following content:
94+
//
95+
// {
96+
// "ConsumerKey": "",
97+
// "ConsumerSecret": "",
98+
// "AccessToken": "",
99+
// "AccessSecret": ""
100+
// }
101+
//
102+
// The tokens can be found on the "Keys and Access Tokens" tab on the application
103+
// management page for your app: https://apps.twitter.com/
104+
105+
Assert.True(File.Exists(@"..\..\config.json"));
106+
107+
var config = SimpleJson.DeserializeObject(File.ReadAllText(@"..\..\config.json")) as JsonObject;
108+
109+
var client = new RestClient("https://api.twitter.com/1.1");
110+
client.Authenticator = OAuth1Authenticator.ForProtectedResource(
111+
(string)config["ConsumerKey"], (string)config["ConsumerSecret"],
112+
(string)config["AccessToken"], (string)config["AccessSecret"]);
113+
114+
var request = new RestRequest("account/verify_credentials.json");
115+
request.AddParameter("include_entities", "true", ParameterType.QueryString);
116+
117+
var response = client.Execute(request);
118+
119+
Assert.NotNull(response);
120+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
121+
}
122+
88123
#region Netflix test classes
89124

90125
[XmlRoot("queue")]

RestSharp/Authenticators/OAuth1Authenticator.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflo
206206
// or implement a seperate class for each OAuth version
207207
if (!request.AlwaysMultipartFormData && !request.Files.Any())
208208
{
209-
foreach (var p in client.DefaultParameters.Where(p => p.Type == ParameterType.GetOrPost))
209+
foreach (var p in client.DefaultParameters.Where(p => p.Type == ParameterType.GetOrPost || p.Type == ParameterType.QueryString))
210210
{
211211
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
212212
}
213213

214-
foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
214+
foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost || p.Type == ParameterType.QueryString))
215215
{
216216
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
217217
}
@@ -220,12 +220,13 @@ private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflo
220220
{
221221
// if we are sending a multipart request, only the "oauth_" parameters should be included in the signature
222222
foreach (var p in client.DefaultParameters.Where(
223-
p => p.Type == ParameterType.GetOrPost && p.Name.StartsWith("oauth_")))
223+
p => (p.Type == ParameterType.GetOrPost || p.Type == ParameterType.QueryString) && p.Name.StartsWith("oauth_")))
224224
{
225225
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
226226
}
227227

228-
foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost && p.Name.StartsWith("oauth_")))
228+
foreach (var p in request.Parameters.Where(
229+
p => (p.Type == ParameterType.GetOrPost || p.Type == ParameterType.QueryString) && p.Name.StartsWith("oauth_")))
229230
{
230231
parameters.Add(new WebPair(p.Name, p.Value.ToString()));
231232
}

0 commit comments

Comments
 (0)