Skip to content
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

OAuth1 signature is generated incorrectly when using non-ASCII symbols in request parameters #1945

Closed
julianpetriv opened this issue Oct 21, 2022 · 4 comments

Comments

@julianpetriv
Copy link

Describe the bug
If we use OAuth1 authentication (restClient.Authenticator = OAuth1Authenticator.ForProtectedResource(...)) and have some non-ASCII symbols in our request parameters (it failed when using '£') oauth_signature is generated not correctly.
I think this is because you skipped part of OAuth1 algorithm where we encode our params to UTF-8, it should be done before we URL-encode them. Here is the method that is doing URL-encode:

public static IEnumerable<string> SortParametersExcludingSignature(WebPairCollection parameters)

To Reproduce
Imagine we have a param:
products=[{"id":5,"price":"£55"}]
Currently we are just URL-encoding it using this line:

=> string.Join("", value.Select(x => Unreserved.Contains(x) ? x.ToString() : $"%{(byte)x:X2}"));

In the end we have something like this:
products%3D%5B%7B%22id%22%3A5%2C%22price%22%3A%22%A355%22%7D%5D

Expected behavior
Starting param:
products=[{"id":5,"price":"£55"}]
After UTF-8 encode (e.g. using this site https://cafewebmaster.com/online_tools/utf8_encode) we should have this:
products=[{"id":5,"price":"£55"}]
And only after that we need to URL-encode it:
products%3D%5B%7B%22id%22%3A5%2C%22price%22%3A%22%C2%A355%22%7D%5D
The difference is we have %C2%A3 instead of %A3.

Desktop:

  • OS: Windows 11
  • .NET Framework 4.6.1
  • Version 108.0.1

Additional context
There is a very useful site for OAuth1 that helped me to find a problem. This is a sandbox that shows the algorithm to generate signature step by step: http://lti.tools/oauth/

@elia936
Copy link
Contributor

elia936 commented Jan 4, 2023

I experience the same issue. Any update on it?

@alexeyzimarev
Copy link
Member

@elia936 it's an open source project, if you experience this issue please feel free to submit a pull request to fix it.

@stale
Copy link

stale bot commented May 22, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 22, 2023
@repo-ranger
Copy link

repo-ranger bot commented May 22, 2023

⚠️ This issue has been marked wontfix and will be closed in 3 days

@repo-ranger repo-ranger bot closed this as completed May 25, 2023
alexeyzimarev pushed a commit that referenced this issue Feb 7, 2024
* Fixes OAuth1 signature with special characters (#2126, #1945)

* Adds test for parameters encoding

---------

Co-authored-by: Eleonora Adova <eleonora.adova@riscogroup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants