Invalid_grant with PHPoAuthLib


I’m using this library to handle the oAuth:

After authorisation, it redirects back to my application with the code in
the query string but I can’t exchange the code for access token. The error
is always “invalid_grant”.

My POST has the code, redirect_uri, and grant_type. I’ve including my
client id and client secret using Basic auth. I’ve also tried putting them
in the POST body, but nothing seems to work.

Is there any way of getting a (more) helpful error message or is there
anything else I’m missing?

Or can an “official” FreeAgent service
for this oAuth library implementation (which is the most popular PHP one on
packagist) be provided?

Many thanks for any assistance!