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