Trying to get AccessToken results in "Basic Auth access denied" or "invalid_grant" error

I’m using this wrapper: https://github.com/thoughtco/Freeagent-PHP to
access the API.

I’ve read through the code and the API docs and cannot see anything
obviously wrong. I’ve checked this group for answers and a few other guides
(even check peoples implementations in .NET and C#) can’t find anything
which solves my problem.

(note: invalid_grant only seems to happen if I follow the older advice of
passing in the ID and Secret in the post data instead of using the
base64(id:secret) otherwise it’s always the Access Denied even if I setup a
fresh user or revoke the app. I know that once a token is generated I
should get the Access Denied but I’m 100% this error is occurring on my
first attempt)

I’m using a sandbox account so I changed the PHP wrappers URLs from
api.freeagent.com/v2/ to api.sandbox.freeagent.com/v2/ and I’ve setup a dev
account with an app and I’ve also tried regenerating the id and secret
again. Nothing seems to work/help.

One option is to use the PHP-OAuth2 library but I didn’t want to just give
up on this just yet. Anyone come across anything similar?

I’ve tried setting up the PHP-Oauth2 library and I now get the
“invalid_grant” error each time even with a new user.

array:3 [▼
“result” => array:1 [▼
“error” => “invalid_grant”
]
“code” => 400
“content_type” => “application/json; charset=utf-8”]

Not sure if it’s sandbox/dev issue as I’ve used this PHP-Oauth2 in a simple
PHP file before and I could authenticate with FreeAgent using a standard
trial account :confused: also not sure if there are changes to the API I haven’t
realised as the info/guides I’ve seen are all fairly old.On Thursday, March 19, 2015 at 3:15:38 PM UTC, n…@pcmmedia.eu wrote:

I’m using this wrapper: GitHub - thoughtco/Freeagent-PHP: A simple PHP wrapper for the FreeAgent API to
access the API.

I’ve read through the code and the API docs and cannot see anything
obviously wrong. I’ve checked this group for answers and a few other guides
(even check peoples implementations in .NET and C#) can’t find anything
which solves my problem.

(note: invalid_grant only seems to happen if I follow the older advice of
passing in the ID and Secret in the post data instead of using the
base64(id:secret) otherwise it’s always the Access Denied even if I setup a
fresh user or revoke the app. I know that once a token is generated I
should get the Access Denied but I’m 100% this error is occurring on my
first attempt)

I’m using a sandbox account so I changed the PHP wrappers URLs from
api.freeagent.com/v2/ to api.sandbox.freeagent.com/v2/ and I’ve setup a
dev account with an app and I’ve also tried regenerating the id and secret
again. Nothing seems to work/help.

One option is to use the PHP-OAuth2 library but I didn’t want to just give
up on this just yet. Anyone come across anything similar?

I’ve got this example PHP file which runs as a standalone thing and is a
basic example/test. If I setup a new user and go through the process using
this file I actually get a working token and a response from /projects.

If I go back, setup a fresh user and use similar code in my symfony project
I always get the invalid_grant error.

PHP working example: http://pastebin.com/SgQg1F0tOn Thursday, March 19, 2015 at 3:15:38 PM UTC, n…@pcmmedia.eu wrote:

I’m using this wrapper: GitHub - thoughtco/Freeagent-PHP: A simple PHP wrapper for the FreeAgent API to
access the API.

I’ve read through the code and the API docs and cannot see anything
obviously wrong. I’ve checked this group for answers and a few other guides
(even check peoples implementations in .NET and C#) can’t find anything
which solves my problem.

(note: invalid_grant only seems to happen if I follow the older advice of
passing in the ID and Secret in the post data instead of using the
base64(id:secret) otherwise it’s always the Access Denied even if I setup a
fresh user or revoke the app. I know that once a token is generated I
should get the Access Denied but I’m 100% this error is occurring on my
first attempt)

I’m using a sandbox account so I changed the PHP wrappers URLs from
api.freeagent.com/v2/ to api.sandbox.freeagent.com/v2/ and I’ve setup a
dev account with an app and I’ve also tried regenerating the id and secret
again. Nothing seems to work/help.

One option is to use the PHP-OAuth2 library but I didn’t want to just give
up on this just yet. Anyone come across anything similar?

I’ve solved the issue but I’m not 100% sure how.

I think the Oauth redirect URL i set in my App is important because If i
tried to get the api to redirect to another internal URL it seemed to cause
a problem.

I also made sure each time I tested I revoked the app
from https://{company-name}.sandbox.freeagent.com/settings/authorized_apps.
This way I know 100% if the errors are caused by the token being generated
previously or if it’s my code/library.

I was using this as a standalone PHP file to ensure I wasn’t making any
stupid mistake: Using the FreeAgent API with PHP and OAuth2 :: Outlandish

I also ran composer require “adoy/oauth2” to make sure that composer was
dealing with the import of the PHP Oauth2 library/namespace as I’m not 100%
on the rules of requiring and using a custom library within my symfony
project. Maybe this didn’t change anything but I felt better knowing it’s
being dealt with by composer.On Thursday, March 19, 2015 at 3:15:38 PM UTC, n…@pcmmedia.eu wrote:

I’m using this wrapper: GitHub - thoughtco/Freeagent-PHP: A simple PHP wrapper for the FreeAgent API to
access the API.

I’ve read through the code and the API docs and cannot see anything
obviously wrong. I’ve checked this group for answers and a few other guides
(even check peoples implementations in .NET and C#) can’t find anything
which solves my problem.

(note: invalid_grant only seems to happen if I follow the older advice of
passing in the ID and Secret in the post data instead of using the
base64(id:secret) otherwise it’s always the Access Denied even if I setup a
fresh user or revoke the app. I know that once a token is generated I
should get the Access Denied but I’m 100% this error is occurring on my
first attempt)

I’m using a sandbox account so I changed the PHP wrappers URLs from
api.freeagent.com/v2/ to api.sandbox.freeagent.com/v2/ and I’ve setup a
dev account with an app and I’ve also tried regenerating the id and secret
again. Nothing seems to work/help.

One option is to use the PHP-OAuth2 library but I didn’t want to just give
up on this just yet. Anyone come across anything similar?

I’ve output some of my variables to confirm I’m running the getAuthUrl in
the same way and I can confirm that the ID and Secret are correct, the
redirect URL is valid, the API URL is for the sandbox. I can also confirm
the server date/time is correct as I’ve seen this mentioned in a couple of
other posts.

Debug info: http://pastebin.com/KS2fu2qe (local url, id, secret and code
all invalidated just incase)On Thursday, March 19, 2015 at 3:15:38 PM UTC, n…@pcmmedia.eu wrote:

I’m using this wrapper: GitHub - thoughtco/Freeagent-PHP: A simple PHP wrapper for the FreeAgent API to
access the API.

I’ve read through the code and the API docs and cannot see anything
obviously wrong. I’ve checked this group for answers and a few other guides
(even check peoples implementations in .NET and C#) can’t find anything
which solves my problem.

(note: invalid_grant only seems to happen if I follow the older advice of
passing in the ID and Secret in the post data instead of using the
base64(id:secret) otherwise it’s always the Access Denied even if I setup a
fresh user or revoke the app. I know that once a token is generated I
should get the Access Denied but I’m 100% this error is occurring on my
first attempt)

I’m using a sandbox account so I changed the PHP wrappers URLs from
api.freeagent.com/v2/ to api.sandbox.freeagent.com/v2/ and I’ve setup a
dev account with an app and I’ve also tried regenerating the id and secret
again. Nothing seems to work/help.

One option is to use the PHP-OAuth2 library but I didn’t want to just give
up on this just yet. Anyone come across anything similar?