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"; }