public function doGet() { $cs = isset($_GET["cs"]) ? $_GET["cs"] : ""; $token = isset($_GET["oauth_token"]) ? $_GET["oauth_token"] : ""; $verifier = isset($_GET["oauth_verifier"]) ? $_GET["oauth_verifier"] : ""; if (strlen($cs) > 0) { $BBC = new BasicBlobCrypter(); $crypter = new BasicBlobCrypter(srand($BBC->MASTER_KEY_MIN_LEN)); $clientState = new OAuthCallbackState($crypter, $cs); $url = $clientState->getRealCallbackUrl(); $callbackUrl = "http://" . $_SERVER['HTTP_HOST'] . "/gadgets/oauthcallback"; if ($url = $callbackUrl) { unset($_GET['cs']); header('Location: ' . $callbackUrl . '?' . http_build_query($_GET)); exit; } } else { if (strlen($token) > 0 && strlen($cs) == 0) { $this->setCacheTime(3600); echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " . "\"http://www.w3.org/TR/html4/loose.dtd\">" . "<html>" . "<head>" . "<title>Close this window</title>" . "</head>" . "<body>" . "<script type=\"text/javascript\">" . "try {" . " window.opener.gadgets.io.oauthReceivedCallbackUrl_ = document.location.href;" . "} catch (e) {" . "}" . "window.close();" . "</script>" . "Close this window." . "</body>" . "</html>"; exit; } } header("HTTP/1.0 400 Bad Request", true); echo "<html><body><h1>" . "400 - Bad Request Error" . "</h1></body></html>"; die; }
/** * * @throws GadgetException */ private function fetchRequestToken(RemoteContentRequest $request) { try { $accessor = $this->accessorInfo->getAccessor(); //TODO The implementations of oauth differs from the one in JAVA. Fix the type OAuthMessage $url = $accessor->consumer->callback_url->requestTokenURL; $msgParams = array(); self::addIdentityParams($msgParams, $request->getToken()); $callbackState = new OAuthCallbackState($this->oauthCrypter); $callbackUrl = "http://" . getenv('HTTP_HOST') . "/gadgets/oauthcallback"; $callbackState->setRealCallbackUrl($callbackUrl); $cs = $callbackState->getEncryptedState(); $msgParams[self::$OAUTH_CALLBACK] = $callbackUrl . "?cs=" . urlencode($cs); $request = $this->newRequestMessageParams($url->url, $msgParams); $reply = $this->sendOAuthMessage($request); $reply->requireParameters(array(ShindigOAuth::$OAUTH_TOKEN, ShindigOAuth::$OAUTH_TOKEN_SECRET)); $accessor->requestToken = $reply->get_parameter(ShindigOAuth::$OAUTH_TOKEN); $accessor->tokenSecret = $reply->get_parameter(ShindigOAuth::$OAUTH_TOKEN_SECRET); } catch (Exception $e) { // It's unfortunate the OAuth libraries throw a generic Exception. throw new GadgetException($e); } }