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

Incorrect signature for x-www-form-urlencoded POST requests with httpx OAuth1 client #517

Open
shc261392 opened this issue Dec 17, 2022 · 0 comments
Assignees
Labels

Comments

@shc261392
Copy link

Describe the bug

When using the exactly same credentials and API call signatures, the requests client could access protected resources from OAuth protected API, while the signature of requests made by httpx client is rejected.

This only happens for POST requests which sends non-binary data (Content-Type will be x-www-form-urlencoded).

Error Stacks

Error are raised at server side and is service-specific (depends on how API services respond to invalid OAuth signatures) so there's no error stack.

To Reproduce

from authlib.integrations.requests_client import OAuth1Session
from authlib.integrations.httpx_client import OAuth1Client


CLIENT_ID = '<client_id>'
CLIENT_SECRET = '<client_secret>'
TOKEN = '<token>'
TOKEN_SECRET = '<token_secret>'
ENDPOINT = '<protected_resource_api_endpoint>'
REQUEST_BODY = {'foo': 'bar'}

requests_client = OAuth1Session(CLIENT_ID, CLIENT_SECRET, token=TOKEN, token_secret=TOKEN_SECRET)
httpx_client = OAuth1Client(CLIENT_ID, CLIENT_SECRET, token=TOKEN, token_secret=TOKEN_SECRET)


r = requests_client.post(ENDPOINT, data=REQUEST_BODY)
print('REQUEST ', r.json(), '\n')

r = httpx_client.post(ENDPOINT, data=REQUEST_BODY)
print('HTTPX ', r.json())

Reproducing the issue with the above script requires access to OAuth1.0 protected API resources.
In the above example, the requests client could access the protected resource without a problem, while the httpx client is rejected by an incorrect signature error.

Expected behavior

Both requests client and httpx client should have access to the protected resource when authenticated with access token.

Environment:

  • OS: Ubuntu 22.04
  • Python Version: 3.10.6
  • Authlib Version: 1.2.0
  • httpx version: 0.23.1

Additional context

I've tried to fix the issue and the fix seems working on my end, though I've only tested httpx OAuth1 client. Not sure whether it will break another clients or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants