2010-11-10 01:03:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Basic authentication
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs.http
|
2010-11-10 01:03:43 +00:00
|
|
|
* @since CakePHP(tm) v 2.0.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic authentication
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs.http
|
2010-11-10 01:03:43 +00:00
|
|
|
*/
|
2010-11-20 19:47:35 +00:00
|
|
|
class BasicAuthentication {
|
2010-11-10 01:03:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication
|
|
|
|
*
|
|
|
|
* @param HttpSocket $http
|
2010-12-03 02:46:11 +00:00
|
|
|
* @param array $authInfo
|
2010-11-10 01:03:43 +00:00
|
|
|
* @return void
|
2010-12-01 16:00:10 +00:00
|
|
|
* @see http://www.ietf.org/rfc/rfc2617.txt
|
2010-11-10 01:03:43 +00:00
|
|
|
*/
|
2010-12-03 02:46:11 +00:00
|
|
|
public static function authentication(HttpSocket $http, &$authInfo) {
|
|
|
|
if (isset($authInfo['user'], $authInfo['pass'])) {
|
|
|
|
$http->request['header']['Authorization'] = self::_generateHeader($authInfo['user'], $authInfo['pass']);
|
2010-11-10 01:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:00:10 +00:00
|
|
|
/**
|
|
|
|
* Proxy Authentication
|
|
|
|
*
|
|
|
|
* @param HttpSocket $http
|
2010-12-04 01:10:07 +00:00
|
|
|
* @param array $proxyInfo
|
2010-12-01 16:00:10 +00:00
|
|
|
* @return void
|
|
|
|
* @see http://www.ietf.org/rfc/rfc2617.txt
|
|
|
|
*/
|
2010-12-04 01:10:07 +00:00
|
|
|
public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) {
|
|
|
|
if (isset($proxyInfo['user'], $proxyInfo['pass'])) {
|
|
|
|
$http->request['header']['Proxy-Authorization'] = self::_generateHeader($proxyInfo['user'], $proxyInfo['pass']);
|
2010-12-01 16:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2010-11-10 01:03:43 +00:00
|
|
|
}
|