Example #1
1
 private function auth_token($code)
 {
     $opts = $this->get_opts();
     $secret = empty($opts['secret']) ? '' : $opts['secret'];
     $client_id = empty($opts['clientid']) ? '' : $opts['clientid'];
     require_once UPDRAFTPLUS_DIR . '/includes/onedrive/onedrive.php';
     $callback = UpdraftPlus_Options::admin_page_url() . '?page=updraftplus&action=updraftmethod-onedrive-auth';
     $onedrive = new \Onedrive\Client(array('client_id' => $client_id, 'state' => (object) array('redirect_uri' => $callback)));
     $onedrive->obtainAccessToken($secret, $code);
     $token = $onedrive->getState();
     if (!empty($token->token->data->refresh_token)) {
         $opts['refresh_token'] = $token->token->data->refresh_token;
         UpdraftPlus_Options::update_updraft_option('updraft_onedrive', $opts);
         header('Location: ' . UpdraftPlus_Options::admin_page_url() . '?page=updraftplus&action=updraftmethod-onedrive-auth&state=success');
     } else {
         global $updraftplus;
         if (!empty($token->token->data->error)) {
             $updraftplus->log(sprintf(__('%s authorisation failed:', 'updraftplus'), 'OneDrive') . ' ' . $token->token->data->error_description, 'error');
         } else {
             $updraftplus->log(sprintf(__('%s authorisation failed:', 'updraftplus'), 'OneDrive') . ' ' . "OneDrive service error: " . serialize($token), 'error');
         }
     }
 }
Example #2
0
<?php

require_once __DIR__ . '/../../onedrive.php';
@session_start();
if (!array_key_exists('onedrive.client.state', $_SESSION)) {
    exit(0);
}
$state = $_SESSION['onedrive.client.state'];
$onedrive = new \Onedrive\Client(array('state' => $state));
$quota = $onedrive->fetchQuota();
@header('Content-Type: application/json', true);
// Warning: JSON_UNESCAPED_SLASHES is only available from PHP 5.4 onwards.
echo json_encode($quota, JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES);