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

Modifications of headers returned by Client.prepare_*_request affects future calls #873

Open
radekholy24 opened this issue Jan 31, 2024 · 0 comments

Comments

@radekholy24
Copy link

radekholy24 commented Jan 31, 2024

Describe the bug

If I modify the headers dictionary returned by a Client.prepare_*_request method, the future calls to any of these methods return the modified headers.

How to reproduce

>>> import oauthlib.oauth2
>>> client = oauthlib.oauth2.WebApplicationClient('my client id')
>>> _, headers, _ = client.prepare_authorization_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded'}
>>> headers['Content-Length'] = '0'
>>> _, headers, _ = client.prepare_authorization_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '0'}
>>> _, headers, _ = client.prepare_token_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '0'}
>>> _, headers, _ = client.prepare_refresh_token_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '0'}

Expected behavior

Either:

>>> import oauthlib.oauth2
>>> client = oauthlib.oauth2.WebApplicationClient('my client id')
>>> _, headers, _ = client.prepare_authorization_request('https://example.com')
>>> headers['Content-Length'] = '0'
>>> _, headers, _ = client.prepare_authorization_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded'}
>>> _, headers, _ = client.prepare_token_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded'}
>>> _, headers, _ = client.prepare_refresh_token_request('https://example.com')
>>> headers
{'Content-Type': 'application/x-www-form-urlencoded'}

or

>>> import oauthlib.oauth2
>>> client = oauthlib.oauth2.WebApplicationClient('my client id')
>>> _, headers, _ = client.prepare_authorization_request('https://example.com')
>>> try:
...     headers['Content-Length'] = '0'
... except Exception:
...     print('an exception occurred')
... 
an exception occurred

or

this unusual feature being documented

Additional context

Please provide any further context here.

  • Are you using OAuth1, OAuth2 or OIDC? OAuth2
  • Are you writing client or server side code? client
  • If client, what provider are you connecting to? a custom one
  • Are you using a downstream library, such as requests-oauthlib, django-oauth-toolkit, ...? no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant