OAuth error, code missing, but it is not!

Heya!

So, I’m probably missing something SUPER obvious but I can’t find what.

First off, since I’m a new user here I can’t post more than 2 links it tells me, so I’ve replaced all “https://” by just “://” in my examples below.

I’m using the patreon-php lib to let my users link their patreon accounts so that I can count pledges.
But I cant seem to make the OAuth work; following the docs I’m sending users to

://www.patreon.com/oauth2/authorize?response_type=code
(With my client id & redirect uri obviously)

When the redirect uri is called back from patreon it has the code GET parameter as needed. Then I simply do that, again as suggested in the docs:

$redirect_uri = “://foorbar.com/patreon/callback”;
$oauth_client = new Patreon\OAuth($pconf[‘client_id’], $pconf[‘client_secret’]);
$tokens = $oauth_client->get_tokens($_GET[‘code’], $redirect_uri);
print_r($tokens);

And there all hell breaks loose, the call to get_tokens returns an error saying:

Array
(
[error] => invalid_request
[error_description] => Missing code parameter.
)

Except this is very false; I’ve hacked OAuth::__update_token to print what post data is sent and clearly the code is set. This is the result of the http_build_query($params) in that function (obviously obfuscating the secret bits) that is then sent to ://api.patreon.com/oauth2/token

grant_type=authorization_code&code=OOqJ…&client_id=XXXXXXXXXXX&client_secret=YYYYYYYYYYYYY&redirect_uri=https%3A%2F%2Ffoobar.com%2Fpatreon%2Fcallback

Clearly code is being passed, I checked it is the same code that I’ve received in the callback GET parameter. I’m at a loss as to what I’m missing …

Help please! :slight_smile:
And thanks for any help you can provide

So for whomever this may help, I found the problem.
I’m using the code inside drupal 6, and somehow it seems to alter either how curl_setopt($ch, CURLOPT_POSTFIELDS, …) works or (more likely I suppose) how http_build_query works.
I’ve just changed the OAuth code to use CURLOPT_POSTFIELDS with an array and simply not use http_build_query at all and now it works just fine.