mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Support to proxy authentication in basic authentication.
This commit is contained in:
parent
64dcca61ef
commit
e1e8026392
2 changed files with 43 additions and 2 deletions
|
@ -31,12 +31,36 @@ class BasicAuthentication {
|
||||||
*
|
*
|
||||||
* @param HttpSocket $http
|
* @param HttpSocket $http
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @see http://www.ietf.org/rfc/rfc2617.txt
|
||||||
*/
|
*/
|
||||||
public static function authentication(HttpSocket $http) {
|
public static function authentication(HttpSocket $http) {
|
||||||
if (isset($http->request['auth']['user'], $http->request['auth']['pass'])) {
|
if (isset($http->request['auth']['user'], $http->request['auth']['pass'])) {
|
||||||
$http->request['header']['Authorization'] = 'Basic ' . base64_encode($http->request['auth']['user'] . ':' . $http->request['auth']['pass']);
|
$http->request['header']['Authorization'] = self::_generateHeader($http->request['auth']['user'], $http->request['auth']['pass']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy Authentication
|
||||||
|
*
|
||||||
|
* @param HttpSocket $http
|
||||||
|
* @return void
|
||||||
|
* @see http://www.ietf.org/rfc/rfc2617.txt
|
||||||
|
*/
|
||||||
|
public static function proxyAuthentication(HttpSocket $http) {
|
||||||
|
if (isset($http->request['proxy']['user'], $http->request['proxy']['pass'])) {
|
||||||
|
$http->request['header']['Proxy-Authorization'] = self::_generateHeader($http->request['proxy']['user'], $http->request['proxy']['pass']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate basic [proxy] authentication header
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function _generateHeader($user, $pass) {
|
||||||
|
return 'Basic ' . base64_encode($user . ':' . $pass);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,4 +46,21 @@ class BasicMethodTest extends CakeTestCase {
|
||||||
$this->assertEqual($http->request['header']['Authorization'], 'Basic bWFyazpzZWNyZXQ=');
|
$this->assertEqual($http->request['header']['Authorization'], 'Basic bWFyazpzZWNyZXQ=');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testProxyAuthentication method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testProxyAuthentication() {
|
||||||
|
$http = new HttpSocket();
|
||||||
|
$http->request['proxy'] = array(
|
||||||
|
'method' => 'Basic',
|
||||||
|
'user' => 'mark',
|
||||||
|
'pass' => 'secret'
|
||||||
|
);
|
||||||
|
|
||||||
|
BasicAuthentication::proxyAuthentication($http);
|
||||||
|
$this->assertEqual($http->request['header']['Proxy-Authorization'], 'Basic bWFyazpzZWNyZXQ=');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue