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')) {
23 (sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
24 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
26 return $this->_tryNextUser();
28 $web = new HttpClient("www.facebook.com", 80);
29 if (DEBUG & _DEBUG_LOGIN) $web->setDebug(true);
30 // collect cookies from http://www.facebook.com/login.php
31 $web->persist_cookies = true;
32 $web->cookie_host = 'www.facebook.com';
33 $firstlogin = $web->get("/login.php");
35 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
36 trigger_error(sprintf(_("Facebook connect failed with %d %s"),
37 $web->status, $web->errormsg),
40 // Switch from http to https://login.facebook.com/login.php
42 $web->host = 'login.facebook.com';
43 if (!($retval = $web->post("/login.php", array('user'=>$userid, 'pass'=>$password)))) {
44 if (DEBUG & (_DEBUG_LOGIN | _DEBUG_VERBOSE))
45 trigger_error(sprintf(_("Facebook login failed with %d %s"),
46 $web->status, $web->errormsg),
49 $this->_authmethod = 'Facebook';
50 if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this)."::checkPass => $retval",
53 $this->_level = WIKIAUTH_USER;
55 $this->_level = WIKIAUTH_ANON;
60 // TODO: msearch facebook for the username
61 function userExists() {
62 if (!loadPhpExtension('openssl')) {
64 (sprintf(_("The PECL %s extension cannot be loaded."), "openssl")
65 . sprintf(_(" %s AUTH ignored."), 'Facebook'),
67 return $this->_tryNextUser();
69 if (DEBUG & _DEBUG_LOGIN)
70 trigger_error(get_class($this)."::userExists => true (dummy)", E_USER_WARNING);
79 // c-hanging-comment-ender-p: nil
80 // indent-tabs-mode: nil