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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
33 * Preferences are handled in _PassUser
35 function checkPass($password) {
36 $userid = $this->_userid;
37 if (!loadPhpExtension('openssl')) {
39 sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
40 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
42 return $this->_tryNextUser();
44 $web = new HttpClient("www.facebook.com", 80);
45 if (DEBUG & _DEBUG_LOGIN) $web->setDebug(true);
46 // collect cookies from http://www.facebook.com/login.php
47 $web->persist_cookies = true;
48 $web->cookie_host = 'www.facebook.com';
49 $firstlogin = $web->get("/login.php");
51 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
52 trigger_error(sprintf(_("Facebook connect failed with %d %s"),
53 $web->status, $web->errormsg),
56 // Switch from http to https://login.facebook.com/login.php
58 $web->host = 'login.facebook.com';
59 if (!($retval = $web->post("/login.php", array('user'=>$userid, 'pass'=>$password)))) {
60 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
61 trigger_error(sprintf(_("Facebook login failed with %d %s"),
62 $web->status, $web->errormsg),
65 $this->_authmethod = 'Facebook';
66 if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval",
69 $this->_level = WIKIAUTH_USER;
71 $this->_level = WIKIAUTH_ANON;
76 // TODO: msearch facebook for the username
77 function userExists() {
78 if (!loadPhpExtension('openssl')) {
80 sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
81 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
83 return $this->_tryNextUser();
85 if (DEBUG & _DEBUG_LOGIN)
86 trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
95 // c-hanging-comment-ender-p: nil
96 // indent-tabs-mode: nil