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