/** * Build miscellaneous options for the request. * * @param \Cake\Http\Client\Request $request The request being sent. * @param array $options Array of options to use. * @return void */ protected function _buildOptions(Request $request, $options) { $this->_contextOptions['method'] = $request->method(); $this->_contextOptions['protocol_version'] = $request->version(); $this->_contextOptions['ignore_errors'] = true; if (isset($options['timeout'])) { $this->_contextOptions['timeout'] = $options['timeout']; } if (isset($options['redirect'])) { $this->_contextOptions['max_redirects'] = (int) $options['redirect']; } if (isset($options['proxy']['proxy'])) { $this->_contextOptions['proxy'] = $options['proxy']['proxy']; } }
/** * 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, $credentials) { $path = $request->getUri()->getPath(); $a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']); $a2 = md5($request->method() . ':' . $path); 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="******"'], ['\\\\', '\\"'], $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; }