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