function prepare($args) { parent::prepare($args); // Check cookie for a valid access_token if (isset($_COOKIE['fb_access_token'])) { $this->accessToken = $_COOKIE['fb_access_token']; } if (empty($this->accessToken)) { $this->clientError(_m("Unable to authenticate you with Facebook.")); return false; } $graphUrl = 'https://graph.facebook.com/me?access_token=' . urlencode($this->accessToken); $this->fbuser = json_decode(file_get_contents($graphUrl)); if (!empty($this->fbuser)) { $this->fbuid = $this->fbuser->id; // OKAY, all is well... proceed to register return true; } else { // log badness list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, sprintf('Failed Facebook authentication attempt, proxy = %s, ip = %s.', $proxy, $ip), __FILE__); $this->clientError(_m('You must be logged into Facebook to register a local account using Facebook.')); } return false; }
function prepare($args) { parent::prepare($args); $this->facebook = new Facebook(array('appId' => common_config('facebook', 'appid'), 'secret' => common_config('facebook', 'secret'), 'cookie' => true)); // Check for a Facebook user session $session = $this->facebook->getSession(); $me = null; if ($session) { try { $this->fbuid = $this->facebook->getUser(); $this->fbuser = $this->facebook->api('/me'); } catch (FacebookApiException $e) { common_log(LOG_ERROR, $e, __FILE__); } } if (!empty($this->fbuser)) { // OKAY, all is well... proceed to register common_debug("Found a valid Facebook user.", __FILE__); } else { // This shouldn't happen in the regular course of things list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, sprintf('Failed Facebook authentication attempt, proxy = %s, ip = %s.', $proxy, $ip), __FILE__); $this->clientError(_m('You must be logged into Facebook to register a local account using Facebook.')); } return true; }
protected function doPreparation() { $this->limit = $this->int('limit'); if (empty($this->limit)) { $this->limit = DEFAULT_RSS_LIMIT; } if (common_config('site', 'private')) { if (!isset($_SERVER['PHP_AUTH_USER'])) { // This header makes basic auth go header('WWW-Authenticate: Basic realm="GNU social RSS"'); // If the user hits cancel -- bam! $this->show_basic_auth_error(); // the above calls 'exit' } else { $nickname = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (!common_check_user($nickname, $password)) { // basic authentication failed list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = {$nickname}, proxy = {$proxy}, ip = {$ip}."); $this->show_basic_auth_error(); // the above calls 'exit' } } } $this->doStreamPreparation(); $this->notices = $this->getNotices($this->limit); }
public function initialize() { // This probably needs some work. For example with IPv6 you can easily generate new IPs... $client_ip = common_client_ip(); $this->client_ip = $client_ip[0] ?: $client_ip[1]; // [0] is proxy, [1] should be the real IP }
function prepare($args) { parent::prepare($args); $this->fbuid = getFacebook()->get_loggedin_user(); if ($this->fbuid > 0) { $this->fb_fields = $this->getFacebookFields($this->fbuid, array('first_name', 'last_name', 'name')); } else { list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, 'Facebook Connect Plugin - ' . "Failed auth attempt, proxy = {$proxy}, ip = {$ip}."); $this->clientError(_m('You must be logged into Facebook to ' . 'use Facebook Connect.')); } return true; }
/** * Read arguments and initialize members * * @param array $args Arguments from $_REQUEST * @return boolean success */ function prepare($args) { parent::prepare($args); $this->limit = (int) $this->trimmed('limit'); if ($this->limit == 0) { $this->limit = DEFAULT_RSS_LIMIT; } if (common_config('site', 'private')) { if (!isset($_SERVER['PHP_AUTH_USER'])) { # This header makes basic auth go header('WWW-Authenticate: Basic realm="StatusNet RSS"'); # If the user hits cancel -- bam! $this->show_basic_auth_error(); return; } else { $nickname = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (!common_check_user($nickname, $password)) { # basic authentication failed list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = {$nickname}, proxy = {$proxy}, ip = {$ip}."); $this->show_basic_auth_error(); return; } } } return true; }
/** * Log an API authentication failure. Collect the proxy and IP * and log them * * @param string $logMsg additional log message */ function logAuthFailure($logMsg) { list($proxy, $ip) = common_client_ip(); $msg = sprintf('API auth failure (proxy = %1$s, ip = %2$s) - ', $proxy, $ip); common_log(LOG_WARNING, $msg . $logMsg); }
/** * Check for a user specified via HTTP basic auth. If there isn't * one, try to get one by outputting the basic auth header. * * @return boolean true or false */ function checkBasicAuthUser($required = true) { $this->basicAuthProcessHeader(); $realm = common_config('api', 'realm'); if (empty($realm)) { $realm = common_config('site', 'name') . ' API'; } if (empty($this->auth_user_nickname) && $required) { header('WWW-Authenticate: Basic realm="' . $realm . '"'); // show error if the user clicks 'cancel' $this->clientError("Could not authenticate you.", 401, $this->format); exit; } else { $user = common_check_user($this->auth_user_nickname, $this->auth_user_password); if (Event::handle('StartSetApiUser', array(&$user))) { if (!empty($user)) { $this->auth_user = $user; } Event::handle('EndSetApiUser', array($user)); } // By default, basic auth users have rw access $this->access = self::READ_WRITE; if (empty($this->auth_user) && ($required || isset($_SERVER['PHP_AUTH_USER']))) { // basic authentication failed list($proxy, $ip) = common_client_ip(); $msg = sprintf('Failed API auth attempt, nickname = %1$s, ' . 'proxy = %2$s, ip = %3$s', $this->auth_user_nickname, $proxy, $ip); common_log(LOG_WARNING, $msg); $this->clientError("Could not authenticate you.", 401, $this->format); exit; } } }
static function createAnonProfile() { // Get the anon user's IP, and turn it into a nickname list($proxy, $ip) = common_client_ip(); // IP + time + random number should help to avoid collisions $baseNickname = $ip . '-' . time() . '-' . common_good_rand(5); $profile = new Profile(); $profile->nickname = $baseNickname; $id = $profile->insert(); if (!$id) { // TRANS: Server exception. throw new ServerException(_m("Could not create anonymous user session.")); } // Stick the Profile ID into the nickname $orig = clone $profile; $profile->nickname = 'anon-' . $id . '-' . $baseNickname; $result = $profile->update($orig); if (!$result) { // TRANS: Server exception. throw new ServerException(_m("Could not create anonymous user session.")); } common_log(LOG_INFO, "AnonymousFavePlugin - created profile for anonymous user from IP: " . $ip . ', nickname = ' . $profile->nickname); return $profile; }