So I'm trying to authenticate with the v2 API via oauth2. I have a code
, so I'm POST
ing to https://stackexchange.com/oauth/access_token
and ideally get an access_token
back.
Instead I get an invalid_request
error saying client_id not provided
- below is my minimal reproduction case:
def oauth_explicit_two(client_id, client_secret, code, redirect_uri):
params = {'client_id': client_id, 'client_secret': client_secret,
'code': code, 'redirect_uri': redirect_uri}
connection = httplib.HTTPSConnection('stackexchange.com', strict=True)
connection.request('POST', '/oauth/access_token', urllib.urlencode(params))
#Used the below to route via CharlesProxy and dump request body
#connection = httplib.HTTPConnection('localhost:8888') # Via CharlesProxy
#connection.request('POST', 'https://stackexchange.com/oauth/access_token', urllib.urlencode(params))
response = connection.getresponse()
return response.read()
This is being called like so:
$ cat example.py
from stackpy import *
print oauth_explicit_two(274, 'elided', 'elided', 'http://stackcompare.com/')
And from this:
$ python example.py
{"error":{"type":"invalid_request","message":"client_id not provided"}}
From Charles, I've verified the POST
body, in which client_id
most definitely seems to appear:
client_secret=elided&code=elided&client_id=274&redirect_uri=http%3A%2F%2Fstackcompare.com%2F
So I'm currently at a bit of a loss, as I can't see how I'm not providing the client_id
...
client_id
to the very front of the POST body; if the error message changes/goes-away that'd be indicative of an encoding error somewhere.client_id=274
as the sole content of thePOST
body I get the same response. I almost wouldn't believe I was sending it, if I didn't have Charles showing me it in the request body... However I get an (expected) missing-app-secret error if I do this withcurl
- something must not be right my end... (Time for more Charles-debugging!)