1: <?php
2: /**
3: * The Horde_Auth_Http_Remote class authenticates users against a remote
4: * HTTP-Auth endpoint.
5: *
6: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you did
9: * not receive this file, http://www.horde.org/licenses/lgpl21
10: *
11: * @author Duck <duck@obala.net>
12: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
14: * @package Auth
15: */
16: class Horde_Auth_Http_Remote extends Horde_Auth_Base
17: {
18: /**
19: * Constructor.
20: *
21: * @param array $params Configuration parameters:
22: * <pre>
23: * 'client' - (Horde_Http_Client) [REQUIRED] TODO
24: * 'url' - (string) [REQUIRED] TODO
25: * </pre>
26: *
27: * @throws InvalidArgumentException
28: */
29: public function __construct(array $params = array())
30: {
31: if (!isset($params['url']) || !isset($params['client'])) {
32: throw new InvalidArgumentException();
33: }
34:
35: parent::__construct($params);
36: }
37:
38: /**
39: * Find out if a set of login credentials are valid.
40: *
41: * @param string $userId The userId to check.
42: * @param array $credentials An array of login credentials.
43: *
44: * @throws Horde_Auth_Exception
45: */
46: protected function _authenticate($userId, $credentials)
47: {
48: $this->_params['client']->request->username = $userId;
49: $this->_params['client']->request->password = $credentials;
50: $this->_params['client']->request->authenticationScheme = Horde_Http::AUTH_BASIC;
51: $response = $this->__params['client']->get($this->_params['url']);
52: if ($response->code != 200) {
53: throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
54: }
55: }
56:
57: }
58: