1: <?php
2: /**
3: * Basic authentication
4: *
5: * PHP 5
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * For full copyright and license information, please see the LICENSE.txt
12: * Redistributions of files must retain the above copyright notice.
13: *
14: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
15: * @link http://cakephp.org CakePHP(tm) Project
16: * @package Cake.Network.Http
17: * @since CakePHP(tm) v 2.0.0
18: * @license http://www.opensource.org/licenses/mit-license.php MIT License
19: */
20:
21: /**
22: * Basic authentication
23: *
24: * @package Cake.Network.Http
25: */
26: class BasicAuthentication {
27:
28: /**
29: * Authentication
30: *
31: * @param HttpSocket $http
32: * @param array $authInfo
33: * @return void
34: * @see http://www.ietf.org/rfc/rfc2617.txt
35: */
36: public static function authentication(HttpSocket $http, &$authInfo) {
37: if (isset($authInfo['user'], $authInfo['pass'])) {
38: $http->request['header']['Authorization'] = self::_generateHeader($authInfo['user'], $authInfo['pass']);
39: }
40: }
41:
42: /**
43: * Proxy Authentication
44: *
45: * @param HttpSocket $http
46: * @param array $proxyInfo
47: * @return void
48: * @see http://www.ietf.org/rfc/rfc2617.txt
49: */
50: public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) {
51: if (isset($proxyInfo['user'], $proxyInfo['pass'])) {
52: $http->request['header']['Proxy-Authorization'] = self::_generateHeader($proxyInfo['user'], $proxyInfo['pass']);
53: }
54: }
55:
56: /**
57: * Generate basic [proxy] authentication header
58: *
59: * @param string $user
60: * @param string $pass
61: * @return string
62: */
63: protected static function _generateHeader($user, $pass) {
64: return 'Basic ' . base64_encode($user . ':' . $pass);
65: }
66:
67: }
68: