Skip to content

Encode oauth_token. Fixes #1495 #1498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}\""));
}
}
}
}