4 * Copyright (C) 2009 Reini Urban
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * From http://developeronline.blogspot.com/2008/10/using-perl-against-facebook-part-i.html:
23 * GET 'http://www.facebook.com/login.php', and rest our virtual browser there to collect the cookies
24 * POST to 'https://login.facebook.com/login.php' with the proper parameters
27 // requires the openssl extension
28 require_once 'lib/HttpClient.php';
30 class _FacebookPassUser
34 * Preferences are handled in _PassUser
36 function checkPass($password)
38 $userid = $this->_userid;
39 if (!loadPhpExtension('openssl')) {
41 sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
42 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
44 return $this->_tryNextUser();
46 $web = new HttpClient("www.facebook.com", 80);
47 if (DEBUG & _DEBUG_LOGIN) $web->setDebug(true);
48 // collect cookies from http://www.facebook.com/login.php
49 $web->persist_cookies = true;
50 $web->cookie_host = 'www.facebook.com';
51 $firstlogin = $web->get("/login.php");
53 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
54 trigger_error(sprintf(_("Facebook connect failed with %d %s"),
55 $web->status, $web->errormsg),
58 // Switch from http to https://login.facebook.com/login.php
60 $web->host = 'login.facebook.com';
61 if (!($retval = $web->post("/login.php", array('user' => $userid, 'pass' => $password)))) {
62 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
63 trigger_error(sprintf(_("Facebook login failed with %d %s"),
64 $web->status, $web->errormsg),
67 $this->_authmethod = 'Facebook';
68 if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => $retval",
71 $this->_level = WIKIAUTH_USER;
73 $this->_level = WIKIAUTH_ANON;
78 // TODO: msearch facebook for the username
81 if (!loadPhpExtension('openssl')) {
83 sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
84 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
86 return $this->_tryNextUser();
88 if (DEBUG & _DEBUG_LOGIN)
89 trigger_error(get_class($this) . "::userExists => true (dummy)", E_USER_WARNING);
98 // c-hanging-comment-ender-p: nil
99 // indent-tabs-mode: nil