HTTP Basic: Access denied using Laravel HTTP Client

When using Laravels HTTP client with basic authentication to get a token, I keep getting a 401 - Unauthorized and I cant figure out why.

My code

$response = Http::withBasicAuth($username, $password)->post(
    'https://api.sandbox.freeagent.com/v2/token_endpoint',
    [
        'grant_type' => 'authorization_code',
        'code' => $code,
        'redirect_uri' => urlencode($redirect_uri),
    ]
);
  • code the response from Log in to your FreeAgent account
  • username is the value of OAuth identifier from the dashboard
  • password is the value of OAuth secrets from the dashboard
  • redirect_uri is my website

Any ideas?

Thanks in advance.

Quick update. It seems that you cant pass in parameters within . You have to post the full url with grant_type, code and redirect etc.

Hi there,

Let me know if you got this working as I can probably help as also using Laravel.

Kindest

Chris

Thanks but I managed to get everything working.

Alan