Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| BasicCredential | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/http-message. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @link https://github.com/php-fast-forward/http-message |
| 12 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 13 | * @license https://opensource.org/licenses/MIT MIT License |
| 14 | */ |
| 15 | |
| 16 | namespace FastForward\Http\Message\Header\Authorization; |
| 17 | |
| 18 | /** |
| 19 | * Class BasicCredential. |
| 20 | * |
| 21 | * Represents the parsed credential pair for HTTP Basic Authentication. |
| 22 | * This credential consists of a username and password encoded as |
| 23 | * `Base64(username:password)` in the `Authorization` header. |
| 24 | * |
| 25 | * Implementations handling this class MUST treat the password as a sensitive |
| 26 | * secret. It MUST NOT be logged, exposed, or transmitted insecurely. The |
| 27 | * username MAY be considered non-sensitive depending on application rules, |
| 28 | * but the password MUST always be protected. |
| 29 | * |
| 30 | * Instances of this class SHALL be returned by |
| 31 | * {@see FastForward\Http\Message\Header\Authorization::parse()} |
| 32 | * when the header contains a valid Basic Authentication value. |
| 33 | */ |
| 34 | final class BasicCredential implements AuthorizationCredential |
| 35 | { |
| 36 | /** |
| 37 | * Creates a new Basic Authentication credential. |
| 38 | * |
| 39 | * The username and password MUST be extracted exactly as decoded from the |
| 40 | * HTTP Authorization header. The password parameter is annotated with |
| 41 | * `#[\SensitiveParameter]` to ensure that stack traces, debugging tools, |
| 42 | * and error handlers do not accidentally reveal its value. |
| 43 | * |
| 44 | * @param string $username the username provided by the client |
| 45 | * @param string $password the plaintext password provided by the client |
| 46 | */ |
| 47 | public function __construct( |
| 48 | public readonly string $username, |
| 49 | #[\SensitiveParameter] |
| 50 | public readonly string $password, |
| 51 | ) {} |
| 52 | } |