3 /* Copyright (C) 2009 Reini Urban
4 * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
6 * From http://developeronline.blogspot.com/2008/10/using-perl-against-facebook-part-i.html:
7 * GET 'http://www.facebook.com/login.php', and rest our virtual browser there to collect the cookies
8 * POST to 'https://login.facebook.com/login.php' with the proper parameters
11 // requires the openssl extension
12 require_once("lib/HttpClient.php");
14 class _FacebookPassUser
17 * Preferences are handled in _PassUser
19 function checkPass($password) {
20 $userid = $this->_userid;
21 if (!loadPhpExtension('openssl')) {
22 trigger_error(_("The PECL openssl extension cannot be loaded. Facebook AUTH ignored."),
24 return $this->_tryNextUser();
26 $web = new HttpClient("www.facebook.com", 80);
27 if (DEBUG & _DEBUG_LOGIN) $web->setDebug(true);
28 // collect cookies from http://www.facebook.com/login.php
29 $web->persist_cookies = true;
30 $web->cookie_host = 'www.facebook.com';
31 $firstlogin = $web->get("/login.php");
33 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
34 trigger_error(sprintf(_("Facebook connect failed with %d %s"),
35 $web->status, $web->errormsg),
38 // Switch from http to https://login.facebook.com/login.php
40 $web->host = 'login.facebook.com';
41 if (!($retval = $web->post("/login.php", array('user'=>$userid, 'pass'=>$password)))) {
42 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
43 trigger_error(sprintf(_("Facebook login failed with %d %s"),
44 $web->status, $web->errormsg),
47 $this->_authmethod = 'Facebook';
48 if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval",
51 $this->_level = WIKIAUTH_USER;
53 $this->_level = WIKIAUTH_ANON;
58 // TODO: msearch facebook for the username
59 function userExists() {
60 if (!loadPhpExtension('openssl')) {
61 trigger_error(_("The PECL openssl extension cannot be loaded. Facebook AUTH ignored."),
63 return $this->_tryNextUser();
65 if (DEBUG & _DEBUG_LOGIN)
66 trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
75 // c-hanging-comment-ender-p: nil
76 // indent-tabs-mode: nil