AUUTH O AUTH
<?php
include_once "library/OAuthStore.php";
include_once "library/OAuthRequester.php";
define("FREEDCAMP_CONSUMER_KEY", "1b5e530401b5781036b0dc95aaa6be03"); //
define("FREEDCAMP_CONSUMER_SECRET", "5a7d79f187625cf789c1448404b0026d"); //
define("FREEDCAMP_OAUTH_HOST", "https://freedcamp.com/api");
define("FREEDCAMP_REQUEST_TOKEN_URL", FREEDCAMP_OAUTH_HOST . "/request_token");
define("FREEDCAMP_AUTHORIZE_URL", FREEDCAMP_OAUTH_HOST . "/authorize");
define("FREEDCAMP_ACCESS_TOKEN_URL", FREEDCAMP_OAUTH_HOST . "/access_token");
$options = array(
'consumer_key' => FREEDCAMP_CONSUMER_KEY,
'consumer_secret' => FREEDCAMP_CONSUMER_SECRET,
'server_uri' => FREEDCAMP_OAUTH_HOST,
'request_token_uri' => FREEDCAMP_REQUEST_TOKEN_URL,
'authorize_uri' => FREEDCAMP_AUTHORIZE_URL,
'access_token_uri' => FREEDCAMP_ACCESS_TOKEN_URL
);
OAuthStore::instance("Session", $options);
try {
if (empty($_GET["oauth_token"])) {
if(!isset($_GET['redirect_url']) || !isset($_GET['consumer_key']) || FREEDCAMP_CONSUMER_KEY != $_GET['consumer_key']) {
echo 'Verification failed.';
exit();
} else {
$_SESSION['redirect_url'] = $_GET['redirect_url'];
}
$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$pageURL .= preg_replace('/\?.*/', '', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$getAuthTokenParams = array(
'oauth_callback' => $pageURL,
'oauth_consumer_key' => FREEDCAMP_CONSUMER_KEY
);
// get a request token
$tokenResultParams = OAuthRequester::requestRequestToken(FREEDCAMP_CONSUMER_KEY, 0, $getAuthTokenParams);
// redirect to the FREEDCAMP authorization page, they will redirect back
header("Location: " . FREEDCAMP_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token']);
}
else {
// STEP 2: Get an access token
$oauthToken = $_GET["oauth_token"];
// echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
$tokenResultParams = $_GET;
try {
OAuthRequester::requestAccessToken(FREEDCAMP_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET);
}
catch (OAuthException2 $e) {
echo 'There seems to have been a problem. Please try again later. If the issue persists email us at help@freedcamp.com';
//var_dump($e);
return;
}
// access_token
$access_token = current($_SESSION);
$redirect_url2 = $_SESSION['redirect_url'];
unset($_SESSION);
if (isset($access_token)) {
/*echo '<script>top.window.location= "'.$redirect_url2.'?token='.$access_token['token'].'&secret='.$access_token['token_secret'].'";</script>';*/
header('Location: '.$redirect_url2.'?token='.$access_token['token'].'&secret='.$access_token['token_secret']);
}
}
}
catch(OAuthException2 $e) {
echo 'There seems to have been a problem. Please try again later. If the issue persists email us at help@freedcamp.com';
echo "<p style='color:#666; font-size:11px; margin-top:10px; font-style:italic;'>OAuthException: " . $e->getMessage(). "</p>";
// var_dump($e);
}
?>