Skip to content

Commit

Permalink
Merge pull request #1498 from sharok/fix_oauth_encoding
Browse files Browse the repository at this point in the history
Encode oauth_token. Fixes #1495
  • Loading branch information
alexeyzimarev committed Sep 17, 2020
2 parents 2ebdbc2 + 68c0776 commit 4daaf69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -215,7 +215,7 @@ WebPairCollection GenerateAuthParameters(string timestamp, string nonce)
new WebPair("oauth_version", Version ?? "1.0")
};

if (!Token.IsEmpty()) authParameters.Add(new WebPair("oauth_token", Token));
if (!Token.IsEmpty()) authParameters.Add(new WebPair("oauth_token", Token, true));

if (!CallbackUrl.IsEmpty()) authParameters.Add(new WebPair("oauth_callback", CallbackUrl, true));

Expand Down
28 changes: 27 additions & 1 deletion test/RestSharp.Tests/OAuth1AuthenticatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,31 @@ public void Authenticate_ShouldAddSignatureToRequestAsSeparateParameters_OnUrlOr
)
);
}

[Test]
[TestCase(OAuthType.AccessToken, "Token", "Token")]
[TestCase(OAuthType.ProtectedResource, "Token", "Token")]
[TestCase(OAuthType.AccessToken, "SVyDD+RsFzSoZChk=", "SVyDD%2BRsFzSoZChk%3D")]
[TestCase(OAuthType.ProtectedResource, "SVyDD+RsFzSoZChk=", "SVyDD%2BRsFzSoZChk%3D")]
public void Authenticate_ShouldEncodeOAuthTokenParameter(OAuthType type,string value, string expected)
{
// Arrange
const string url = "https://no-query.string";

var client = new RestClient(url);
var request = new RestRequest();
_authenticator.Type = type;
_authenticator.Token = value;

// Act
_authenticator.Authenticate(client, request);

// Assert
var authParameter = request.Parameters.Single(x => x.Name == "Authorization");
var authHeader = (string) authParameter.Value;

Assert.IsNotNull(authHeader);
Assert.IsTrue(authHeader.Contains($"oauth_token=\"{expected}\""));
}
}
}
}

0 comments on commit 4daaf69

Please sign in to comment.