Skip to content

Commit 17358f0

Browse files
jakub-dibalapionl
authored andcommitted
Add HttpAuthorizationHeader for use in HTTP basic authorization
1 parent 9f42358 commit 17358f0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WrkFlow\ApiSdkBuilder\Headers;
6+
7+
use WrkFlow\ApiSdkBuilder\Interfaces\HeadersInterface;
8+
9+
class HttpAuthorizationHeader implements HeadersInterface
10+
{
11+
public function __construct(
12+
public readonly string $username,
13+
public readonly string $password,
14+
) {
15+
}
16+
17+
public function headers(): array
18+
{
19+
$key = base64_encode(
20+
sprintf(
21+
'%s:%s',
22+
$this->username,
23+
$this->password,
24+
),
25+
);
26+
27+
return [
28+
'Authorization' => sprintf('Basic %s', $key),
29+
];
30+
}
31+
}

0 commit comments

Comments
 (0)