Skip to content

Commit 5fb3173

Browse files
authored
fix: set default headers in authenticate (#50)
1 parent a1dc531 commit 5fb3173

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/BEditaClient.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function authenticate(string $username, string $password): ?array
2929
$headers = $this->getDefaultHeaders();
3030
if (!empty($headers['X-Api-Key'])) {
3131
unset($headers['Authorization']);
32+
$this->setDefaultHeaders($headers);
3233
}
3334

3435
return $this->post('/auth', json_encode(compact('username', 'password') + ['grant_type' => 'password']), ['Content-Type' => 'application/json']);

src/BaseClient.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function getDefaultHeaders(): array
125125
return $this->defaultHeaders;
126126
}
127127

128+
/**
129+
* Set default headers in use on every request
130+
*
131+
* @param array $headers Default headers
132+
* @return void
133+
*/
134+
public function setDefaultHeaders(array $headers): void
135+
{
136+
$this->defaultHeaders = $headers;
137+
}
138+
128139
/**
129140
* Get API base URL used tokens
130141
*

tests/TestCase/BEditaClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function testConstruct(): void
122122
*
123123
* @return void
124124
* @covers ::authenticate()
125+
* @covers ::setDefaultHeaders()
125126
*/
126127
public function testAuthenticate(): void
127128
{

0 commit comments

Comments
 (0)