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