Skip to content

Commit 122a2b0

Browse files
elia936Eleonora Adova
and
Eleonora Adova
authored
Fixes OAuth1 signature with special characters (#2126, #1945) (#2127)
* Fixes OAuth1 signature with special characters (#2126, #1945) * Adds test for parameters encoding --------- Co-authored-by: Eleonora Adova <[email protected]>
1 parent f3642c1 commit 122a2b0

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/RestSharp/Authenticators/OAuth/OAuthTools.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static string GetNonce() {
142142
internal static IEnumerable<string> SortParametersExcludingSignature(WebPairCollection parameters)
143143
=> parameters
144144
.Where(x => !x.Name.EqualsIgnoreCase("oauth_signature"))
145-
.Select(x => new WebPair(UrlEncodeStrict(x.Name), UrlEncodeStrict(x.Value)))
145+
.Select(x => new WebPair(UrlEncodeStrict(x.Name), UrlEncodeRelaxed(x.Value)))
146146
.OrderBy(x => x, WebPair.Comparer)
147147
.Select(x => x.GetQueryParameter(false));
148148

test/RestSharp.Tests.Integrated/OAuth1Tests.cs

+19-7
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,29 @@ public async Task Can_Authenticate_OAuth1_With_Querystring_Parameters() {
5151
actual.Should().BeEquivalentTo(expected);
5252
}
5353

54-
[Fact]
55-
public void Properly_Encodes_Parameter_Names() {
56-
var postData = new WebPairCollection {
57-
{ "name[first]", "Chuck" },
58-
{ "name[last]", "Testa" }
59-
};
54+
[Theory]
55+
[MemberData(nameof(EncodeParametersTestData))]
56+
public void Properly_Encodes_Parameter_Names(IList<(string, string)> parameters, string expected) {
57+
var postData = new WebPairCollection();
58+
postData.AddRange(parameters.Select(x => new WebPair(x.Item1, x.Item2)));
6059
var sortedParams = OAuthTools.SortParametersExcludingSignature(postData);
6160

62-
sortedParams.First().Should().Be("name%5Bfirst%5D=Chuck");
61+
sortedParams.First().Should().Be(expected);
6362
}
6463

64+
public static IEnumerable<object[]> EncodeParametersTestData =>
65+
new List<object[]>
66+
{
67+
new object[] {
68+
new List<(string, string)> { ("name[first]", "Chuck"), ("name[last]", "Testa") },
69+
"name%5Bfirst%5D=Chuck"
70+
},
71+
new object[] {
72+
new List<(string, string)> { ("country", "España") },
73+
"country=Espa%C3%B1a"
74+
}
75+
};
76+
6577
[Fact]
6678
public void Use_RFC_3986_Encoding_For_Auth_Signature_Base() {
6779
// reserved characters for 2396 and 3986

0 commit comments

Comments
 (0)