/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Client/Auth
NameSizeModeActions
Basic.php25790644editdlrm
Digest.php49320644editdlrm
Oauth.php130660644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Client/Auth/Digest.php (4932B)
_client = $client; } /** * Add Authorization header to the request. * * @param \Cake\Http\Client\Request $request The request object. * @param array $credentials Authentication credentials. * @return \Cake\Http\Client\Request The updated request. * @see https://www.ietf.org/rfc/rfc2617.txt */ public function authentication(Request $request, array $credentials): Request { if (!isset($credentials['username'], $credentials['password'])) { return $request; } if (!isset($credentials['realm'])) { $credentials = $this->_getServerInfo($request, $credentials); } if (!isset($credentials['realm'])) { return $request; } $value = $this->_generateHeader($request, $credentials); return $request->withHeader('Authorization', $value); } /** * Retrieve information about the authentication * * Will get the realm and other tokens by performing * another request without authentication to get authentication * challenge. * * @param \Cake\Http\Client\Request $request The request object. * @param array $credentials Authentication credentials. * @return array modified credentials. */ protected function _getServerInfo(Request $request, array $credentials): array { $response = $this->_client->get( (string)$request->getUri(), [], ['auth' => ['type' => null]] ); if (!$response->getHeader('WWW-Authenticate')) { return []; } preg_match_all( '@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $response->getHeaderLine('WWW-Authenticate'), $matches, PREG_SET_ORDER ); foreach ($matches as $match) { $credentials[$match[1]] = $match[2]; } if (!empty($credentials['qop']) && empty($credentials['nc'])) { $credentials['nc'] = 1; } return $credentials; } /** * Generate the header Authorization * * @param \Cake\Http\Client\Request $request The request object. * @param array $credentials Authentication credentials. * @return string */ protected function _generateHeader(Request $request, array $credentials): string { $path = $request->getUri()->getPath(); $a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']); $a2 = md5($request->getMethod() . ':' . $path); $nc = ''; if (empty($credentials['qop'])) { $response = md5($a1 . ':' . $credentials['nonce'] . ':' . $a2); } else { $credentials['cnonce'] = uniqid(); $nc = sprintf('%08x', $credentials['nc']++); $response = md5( $a1 . ':' . $credentials['nonce'] . ':' . $nc . ':' . $credentials['cnonce'] . ':auth:' . $a2 ); } $authHeader = 'Digest '; $authHeader .= 'username="' . str_replace(['\\', '"'], ['\\\\', '\\"'], $credentials['username']) . '", '; $authHeader .= 'realm="' . $credentials['realm'] . '", '; $authHeader .= 'nonce="' . $credentials['nonce'] . '", '; $authHeader .= 'uri="' . $path . '", '; $authHeader .= 'response="' . $response . '"'; if (!empty($credentials['opaque'])) { $authHeader .= ', opaque="' . $credentials['opaque'] . '"'; } if (!empty($credentials['qop'])) { $authHeader .= ', qop="auth", nc=' . $nc . ', cnonce="' . $credentials['cnonce'] . '"'; } return $authHeader; } }