<?php @session_start(); require_once "header.inc.php"; require_once "../src/functions.inc.php"; $token = skydrive_tokenstore::acquire_token(); if (!$token) { echo "<div>"; echo "<img src='statics/key-icon.png' width='32px' style='vertical-align: middle;'> "; echo "<span style='vertical-align: middle;'><a href='" . skydrive_auth::build_oauth_url() . "'>Login with SkyDrive</a></span>"; echo "</div>"; } else { $sd = new skydrive($token); try { $response = $sd->get_file_properties($_GET['fileid']); echo "<h3>" . $response['name'] . "</h3>"; echo "Size: " . round($response['size'] / 1024, 2) . "Kb<br>"; echo "Created: " . $response['created_time'] . "<br>"; echo "Pre-Signed URL: <a href='" . $response['source'] . "'>Copy Link</a><br>"; echo "Permalink: <a href='" . $response['link'] . "'>Copy Link</a><br><br>"; echo "<div><img src='statics/folder-icon.png' width='32px' style='vertical-align: middle;'> <span style='vertical-align: middle;'><a href='index.php?folderid=" . $response['parent_id'] . "'>Back to containing folder</a></span></div>"; } catch (Exception $e) { $errc = $e->getMessage(); echo "Error: "; switch (substr($errc, -3)) { case "403": echo "Unauthorised"; break; case "404": echo "Not found"; break;
public static function acquire_token() { $response = skydrive_tokenstore::get_tokens_from_store(); if (empty($response['access_token'])) { // No token at all, needs to go through login flow. Return false to indicate this. return false; exit; } else { if (time() > (int) $response['access_token_expires']) { // Token needs refreshing. Refresh it and then return the new one. $refreshed = skydrive_auth::refresh_oauth_token($response['refresh_token']); if (skydrive_tokenstore::save_tokens_to_store($refreshed)) { $newtokens = skydrive_tokenstore::get_tokens_from_store(); return $newtokens['access_token']; } exit; } else { return $response['access_token']; // Token currently valid. Return it. exit; } } }
<?php // callback.php // This is the page that Windows Live redirects to after a successful login. // The page needs to call "skydrive_auth::get_oauth_token" with the code returned in the querystring. // Then this example page calls "skydrive_tokenstore::save_tokens_to_store" to save the tokens to a file (although you can handle them how you want). require_once "../src/functions.inc.php"; $response = skydrive_auth::get_oauth_token($_GET['code']); if (skydrive_tokenstore::save_tokens_to_store($response)) { header("Location: index.php"); } else { echo "error"; }