private function getIdentityCache() { global $oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal; try { $util = new OAuthUtility($oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal); $this->identityCache = $util->getIdentity($this->oauthaccesstoken, $this->oauthaccesssecret); $this->oauthidentitycache = serialize($this->identityCache); $this->dbObject->prepare("UPDATE user SET oauthidentitycache = :identity WHERE id = :id;")->execute(array(":id" => $this->id, ":identity" => $this->oauthidentitycache)); } catch (UnexpectedValueException $ex) { $this->identityCache = null; $this->oauthidentitycache = null; $this->dbObject->prepare("UPDATE user SET oauthidentitycache = null WHERE id = :id;")->execute(array(":id" => $this->id)); SessionAlert::warning("OAuth error getting identity from MediaWiki: " . $ex->getMessage()); } }
BootstrapSkin::displayAccessDenied(); BootstrapSkin::displayInternalFooter(); die; } global $baseurl; $currentUser = User::getCurrent(); $currentUser->detachAccount(); header("Location: {$baseurl}/acc.php?action=logout"); } elseif ($action == "oauthattach") { $database = gGetDb(); $database->transactionally(function () use($database) { try { global $oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal; $user = User::getCurrent(); // Get a request token for OAuth $util = new OAuthUtility($oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal); $requestToken = $util->getRequestToken(); // save the request token for later $user->setOAuthRequestToken($requestToken->key); $user->setOAuthRequestSecret($requestToken->secret); $user->save(); $redirectUrl = $util->getAuthoriseUrl($requestToken); header("Location: {$redirectUrl}"); } catch (Exception $ex) { throw new TransactionException($ex->getMessage(), "Connection to Wikipedia failed.", "alert-error", 0, $ex); } }); } else { echo defaultpage(); BootstrapSkin::displayInternalFooter(); die;
// Initialize the session data. session_start(); // Get all the classes. require_once 'functions.php'; require_once 'includes/PdoDatabase.php'; require_once 'includes/SmartyInit.php'; // this needs to be high up, but below config, functions, and database $user = User::getByRequestToken($_GET['oauth_token'], gGetDb()); if ($user == false) { BootstrapSkin::displayInternalHeader(); BootstrapSkin::displayAlertBox("Could not find request token in local store.", "alert-error", "Error", true, false); BootstrapSkin::displayInternalFooter(); die; } global $oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal; $util = new OAuthUtility($oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal); try { $result = $util->callbackCompleted($user->getOAuthRequestToken(), $user->getOAuthRequestSecret(), $_GET['oauth_verifier']); } catch (Exception $exception) { BootstrapSkin::displayInternalHeader(); BootstrapSkin::displayAlertBox("OAuth Error: {$exception->getMessage()}", "alert-error", "OAuth Error", true, false); BootstrapSkin::displayInternalFooter(); die; } $user->setOAuthAccessToken($result->key); $user->setOAuthAccessSecret($result->secret); $user->setOnWikiName("##OAUTH##"); $user->save(); if ($user->getStatus() == "New") { header("Location: ../acc.php?action=registercomplete"); die;
define('AT_INCLUDE_PATH', '../../../../include/'); require_once AT_INCLUDE_PATH . 'vitals.inc.php'; } require_once 'OAuthUtility.class.php'; require_once "OAuth.php"; global $msg, $_config; // check whether the transformable url is accessible if (!OAuthUtility::isAccessible(AT_TILE_OAUTH_REGISTER_CONSUMER_URL)) { $msg->addError(array('TILE_AUTHENTICATION_FAIL', _AT('tile_not_accessible'))); header('Location: ' . AT_BASE_HREF . 'mods/_core/imscp/index.php'); exit; } // check whether the last access token has expired. If not, return it, otherwise, get a new access token. // skip this step when this script is called by oauth server callback if (isset($_SESSION['member_id'])) { $access_token_key = OAuthUtility::getUnexpiredAccessToken(); } if ($access_token_key == '') { // initialize basic variables $sig_method = new OAuthSignatureMethod_HMAC_SHA1(); // use HMAC signature method as default if (!isset($_GET['oauth_token'])) { // 1. register consumer $sql = "SELECT * FROM %soauth_client_servers WHERE oauth_server='%s'"; $row = queryDB($sql, array(TABLE_PREFIX, $_config['transformable_uri']), TRUE); if (count($row) == 0) { $register_consumer_url = AT_TILE_OAUTH_REGISTER_CONSUMER_URL . '?consumer=' . urlencode(AT_BASE_HREF) . '&expire=' . $_config['transformable_oauth_expire']; $oauth_server_response = file_get_contents($register_consumer_url); // handle OAUTH response on register consumer foreach (explode('&', $oauth_server_response) as $rtn) { $rtn_pair = explode('=', $rtn);
/** * Summary of reattachOAuthAccount * @param User $user * @throws TransactionException */ function reattachOAuthAccount(User $user) { global $oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal; try { // Get a request token for OAuth $util = new OAuthUtility($oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal); $requestToken = $util->getRequestToken(); // save the request token for later $user->setOAuthRequestToken($requestToken->key); $user->setOAuthRequestSecret($requestToken->secret); $user->save(); $redirectUrl = $util->getAuthoriseUrl($requestToken); header("Location: {$redirectUrl}"); die; } catch (Exception $ex) { throw new TransactionException($ex->getMessage(), "Connection to Wikipedia failed.", "alert-error", 0, $ex); } }