2010-11-10 01:03:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Basic authentication
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-11-10 01:03:43 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-11-10 01:03:43 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-11-10 01:03:43 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Network.Http
|
2010-11-10 01:03:43 +00:00
|
|
|
* @since CakePHP(tm) v 2.0.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-11-10 01:03:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic authentication
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Network.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
|
|
|
|
*
|
2014-05-31 21:36:05 +00:00
|
|
|
* @param HttpSocket $http Http socket instance.
|
|
|
|
* @param array &$authInfo Authentication info.
|
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'])) {
|
2015-07-21 08:22:53 +00:00
|
|
|
$http->request['header']['Authorization'] = static::_generateHeader($authInfo['user'], $authInfo['pass']);
|
2010-11-10 01:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:00:10 +00:00
|
|
|
/**
|
|
|
|
* Proxy Authentication
|
|
|
|
*
|
2014-05-31 21:36:05 +00:00
|
|
|
* @param HttpSocket $http Http socket instance.
|
|
|
|
* @param array &$proxyInfo Proxy info.
|
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'])) {
|
2015-07-21 08:22:53 +00:00
|
|
|
$http->request['header']['Proxy-Authorization'] = static::_generateHeader($proxyInfo['user'], $proxyInfo['pass']);
|
2010-12-01 16:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate basic [proxy] authentication header
|
|
|
|
*
|
2014-05-31 21:36:05 +00:00
|
|
|
* @param string $user Username.
|
|
|
|
* @param string $pass Password.
|
2010-12-01 16:00:10 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected static function _generateHeader($user, $pass) {
|
|
|
|
return 'Basic ' . base64_encode($user . ':' . $pass);
|
|
|
|
}
|
|
|
|
|
2010-11-10 01:03:43 +00:00
|
|
|
}
|