Proxying Oahu API calls

If you want to access Oahu’s API from the client side, e.g. when providing data for a Flash site, you need to proxy it to your host and add the Consumer ID and Secret values there, so it can’t be accessed by the User.


Here is an example of a simple proxy in PHP


/* PUT data comes in on the stdin stream */
$fp = fopen( "php://input", "r" );

while( !feof( $fp ) ){
    $data .= fread( $fp, 8192 );

$opts = array('http' =>
        'method'  => 'GET',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $data

$context  = stream_context_create($opts);
$url = $_GET['url'];

if ( !$url || substr(urldecode($url),0,19)!="" ) {
  // Passed url not specified.
  $contents = 'ERROR: This proxy can only be used to access Oahu\'s API';  
} else {
    $contents = file_get_contents(urldecode($url."&consumer_id=".$consumer_id."&consumer_secret=".$consumer_secret), false, $context);
echo $contents;