steelpush
steelpush

Reputation: 119

Guzzle Authorisation header

The api I'm trying to access requests an authorisation header like this:

Authorization: INSERT_YOUR_TOKEN_HERE

Guzzle provides this:

Authorization: Basic <token>

When called with 'auth' => [null, <token>].

And the service returns the error, Token is wrong.

When we manually curl like this:

Authorization: <token>

The token is accepted. Setting the authorization header manually just results in guzzle stripping it out of the request entirely.

How do we prevent the word basic being added by guzzle? (We are using version 6.1).

Upvotes: 0

Views: 2660

Answers (2)

steelpush
steelpush

Reputation: 119

OK, so the answer to my problem if anyone has a similar issue is that I was passing my headers to the guzzle client incorrectly, causing it to use the defaults that are similar enough to the ones I need that I missed it. This meant manually setting the authorization header just did nothing rather than being stripped out.

Remember to create your arrays with the right number of dimensions people :)

Upvotes: 0

Ahmed Khan
Ahmed Khan

Reputation: 516

You need to define the header first and then need to attach it with request

$header = array('Authorization'=>'tokken');
$response = $this->client->get($url, array('headers' => $header));

Then your header will be send along with the request.

Upvotes: 3

Related Questions