require 'lib/fireeagle.php'; /* Submitted Application IDs */ if (isset($_GET['app-consumer']) && isset($_GET['app-secret'])) { $fe = new FireEagle($_GET['app-consumer'], $_GET['app-secret']); $tok = $fe->getRequestToken(); if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { echo "ERROR! FireEagle::getRequestToken() returned an invalid response. Giving up."; exit; } $sess['app_consumer'] = $_GET['app-consumer']; $sess['app_secret'] = $_GET['app-secret']; $sess['auth_state'] = "start"; $sess['request_token'] = $token = $tok['oauth_token']; $sess['request_secret'] = $tok['oauth_token_secret']; setcookie('amadeus_request', base64_encode(serialize($sess))); header("Location: " . $fe->getAuthorizeURL($token) . '&oauth_callback=http://amadeus.benapps.net'); exit; } else { // We're Going to be rendering something: ?> <!DOCTYPE html> <title>Auth me, Amadeus!</title> <style type="text/css"> body { width: 30em; margin: 10px auto; } fieldset { border: 1px #5F7A99 solid; -webkit-border-radius: 10px;
if (!$access_key || !$access_secret) { $session = new midcom_services_session('org_routamc_positioning_fireeagle'); if (isset($_GET['f']) && $_GET['f'] == 'start') { // get a request token + secret from FE and redirect to the authorization page $fireeagle = new FireEagle($fireeagle_consumer_key, $fireeagle_consumer_secret); $request_token = $fireeagle->getRequestToken(); if (!isset($request_token['oauth_token']) || !is_string($request_token['oauth_token']) || !isset($request_token['oauth_token_secret']) || !is_string($request_token['oauth_token_secret'])) { throw new midcom_error("Failed to get FireEagle request token\n"); } // Save request token to session and redirect user $session->set('auth_state', 'start'); $session->set('request_token', $request_token['oauth_token']); $session->set('request_secret', $request_token['oauth_token_secret']); ?> <p><a href="<?php echo $fireeagle->getAuthorizeURL($request_token['oauth_token']); ?> " target="_blank">Authorize this application</a></p> <p><a href="?f=callback">And then click here</a></p> <?php midcom::get()->finish(); _midcom_stop_request(); } elseif (isset($_GET['f']) && $_GET['f'] == 'callback') { // the user has authorized us at FE, so now we can pick up our access token + secret if (!$session->exists('auth_state') || $session->get('auth_state') != 'start') { throw new midcom_error("Out of sequence."); } $fireeagle = new FireEagle($fireeagle_consumer_key, $fireeagle_consumer_secret, $session->get('request_token'), $session->get('request_secret')); $access_token = $fireeagle->getAccessToken(); if (!isset($access_token['oauth_token']) || !is_string($access_token['oauth_token']) || !isset($access_token['oauth_token_secret']) || !is_string($access_token['oauth_token_secret'])) { throw new midcom_error("Failed to get FireEagle access token\n");
function wpfe_wp_admin() { global $fe_key; global $fe_secret; $access_token = get_option('wpfe_access_token'); $access_secret = get_option('wpfe_access_secret'); ?> <div class="wrap"> <h2>FireEagle Configuration</h2> <?php if (!empty($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'token': $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['request_token'], $_SESSION['request_secret']); $tok = $fe->getAccessToken(); if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { error_log("Bad token from FireEagle::getAccessToken(): " . var_export($tok, TRUE)); echo "ERROR! FireEagle::getAccessToken() returned an invalid response. Giving up."; exit; } $_SESSION['auth_state'] = "done"; update_option('wpfe_access_token', $tok['oauth_token']); update_option('wpfe_access_secret', $tok['oauth_token_secret']); $access_token = get_option('wpfe_access_token'); $access_secret = get_option('wpfe_access_secret'); break; } } // check if we have tokens and be happy about it then if ($access_token != false && $access_secret != false) { $fe = new FireEagle($fe_key, $fe_secret, $access_token, $access_secret); ?> <h3>Authentication</h3> <p>Congratulations, your FireEagle account is sucesfully authorized with this Wordpress installation.</p> <p>If you want, you can <a href="#">revoke it</a> (to be implemented).</p> <h3>Location</h3> <p>FireEagle's best guess about your current location is: <b><?php wpfe_display_best_guess_name(); ?> </b>.</p> <p><b>Note:</b> plugin checkes FireEagle for updated location status every 15 minutes.</p> <?php } else { // otherwise start authentication process $fe = new FireEagle($fe_key, $fe_secret); $tok = $fe->getRequestToken(); if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { echo "ERROR! FireEagle::getRequestToken() returned an invalid response Giving up."; exit; } $_SESSION['auth_state'] = "start"; $_SESSION['request_token'] = $token = $tok['oauth_token']; $_SESSION['request_secret'] = $tok['oauth_token_secret']; ?> <div align="center"> <h3>Step 1:</h3> <form> <input type="button" value="Authenticate" onclick="window.open('<?php echo $fe->getAuthorizeURL($token); ?> ')" style="background: url( images/fade-butt.png ); border: 3px double #999; border-left-color: #ccc; border-top-color: #ccc; color: #333; padding: 0.25em; font-size: 1.5em;" /> </form> <h3>Step 2:</h3> <form method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?> "> <input type="hidden" name="action" value="token" /> <input type="submit" name="Submit" value="<?php _e('Finish »'); ?> " style="background: url( images/fade-butt.png ); border: 3px double #999; border-left-color: #ccc; border-top-color: #ccc; color: #333; padding: 0.25em; font-size: 1.5em;" /> </form> </div> <?php } ?> </div><?php }