1 | <?php |
||
15 | class DigestAuthentication |
||
16 | { |
||
17 | use Utils\AuthenticationTrait; |
||
18 | |||
19 | const KEY = 'USERNAME'; |
||
20 | |||
21 | /** |
||
22 | * @var string|null The nonce value |
||
23 | */ |
||
24 | private $nonce; |
||
25 | |||
26 | /** |
||
27 | * Returns the username. |
||
28 | * |
||
29 | * @param ServerRequestInterface $request |
||
30 | * |
||
31 | * @return string|null |
||
32 | */ |
||
33 | public static function getUsername(ServerRequestInterface $request) |
||
37 | |||
38 | /** |
||
39 | * Set the nonce value. |
||
40 | * |
||
41 | * @param string $nonce |
||
42 | * |
||
43 | * @return self |
||
44 | */ |
||
45 | public function nonce($nonce) |
||
51 | |||
52 | /** |
||
53 | * Execute the middleware. |
||
54 | * |
||
55 | * @param ServerRequestInterface $request |
||
56 | * @param ResponseInterface $response |
||
57 | * @param callable $next |
||
58 | * |
||
59 | * @return ResponseInterface |
||
60 | */ |
||
61 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
74 | |||
75 | /** |
||
76 | * Login or check the user credentials. |
||
77 | * |
||
78 | * @param ServerRequestInterface $request |
||
79 | * @param string|null $username |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | private function login(ServerRequestInterface $request, &$username) |
||
102 | |||
103 | /** |
||
104 | * Validates the user authentication. |
||
105 | * |
||
106 | * @param array $authorization |
||
107 | * @param string $method |
||
108 | * @param string $password |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | private function checkAuthentication(array $authorization, $method, $password) |
||
121 | |||
122 | /** |
||
123 | * Parses the authorization header for a basic authentication. |
||
124 | * |
||
125 | * @param string $header |
||
126 | * |
||
127 | * @return false|array |
||
128 | */ |
||
129 | private static function parseAuthorizationHeader($header) |
||
149 | } |
||
150 |