Skip to content

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

@shc261392

Description

@shc261392

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clientConcerns a client implementation

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy