Skip to content

Can't send token request body as JSON #244

@RobWilco

Description

@RobWilco

Using a grant type of password, when I supply a header of Content-Type: application/json the body is still sent url-encoded instead of as JSON. From the debug logs:

Supplying headers {'Content-Type': 'application/json'} and
  data {'username': 'XXX', 'client_secret': 'XXX',
  'password': 'XXX', 'grant_type': 'password', 'client_id': 'XXX'}

Prepared fetch token request body grant_type=password&username=XXX&
  client_id=XXX&client_secret=XXX&password=XXX

See line 211 below. data=dict(urldecode(body)):

> /Library/Python/2.7/site-packages/requests_oauthlib/oauth2_session.py(210)fetch_token()
-> if method.upper() == 'POST':
(Pdb) l
205             headers = headers or {
206                 'Accept': 'application/json',
207                 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
208             }
209             self.token = {}
210  ->         if method.upper() == 'POST':
211                 r = self.post(token_url, data=dict(urldecode(body)),
212                     timeout=timeout, headers=headers, auth=auth,
213                     verify=verify)
214                 log.debug('Prepared fetch token request body %s', body)

Other platforms (e.g., ruby) seem to do the right thing. Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions