<?php

/**
 * Example of usage Yandex\Disk package
 *
 * @author   Alexander Mitsura
 * @created  15.10.13 10:32
 */
$settings = (require_once '../../settings.php');
use Yandex\OAuth\OAuthClient;
$client = new OAuthClient($settings['global']['clientId']);
if (isset($_COOKIE['yaAccessToken'])) {
    $directory = $_POST['directory'];
    $client->setAccessToken($_COOKIE['yaAccessToken']);
    // XXX: how it should be (using user access token)
    //$diskClient = new \Yandex\Disk\DiskClient($client->getAccessToken());
    // XXX: how it is now (using magic access token)
    $diskClient = new \Yandex\Disk\DiskClient($client->getAccessToken());
    $diskClient->setServiceScheme(\Yandex\Disk\DiskClient::HTTPS_SCHEME);
    header('Content-type: application/json');
    $response = [];
    if ($diskClient->createDirectory($directory)) {
        $response['status'] = 'OK';
    }
    echo json_encode($response);
}
<?php

$settings = (require_once '../settings.php');
session_start();
//Set manual token to cookies
if (isset($_POST['token'])) {
    setcookie("yaAccessToken", $_POST['token'], null, '/');
}
if (isset($_REQUEST['back'])) {
    $_SESSION['back'] = $_REQUEST['back'];
}
use Yandex\OAuth\OAuthClient;
// Client secret is not required in this case
$client = new OAuthClient($settings['global']['clientId']);
$state = 'yandex-php-library';
if (isset($_REQUEST['type'])) {
    switch ($_REQUEST['type']) {
        case 'code':
            $client->authRedirect(true, OAuthClient::CODE_AUTH_TYPE, $state);
            break;
        case 'token':
            $client->authRedirect(true, OAuthClient::TOKEN_AUTH_TYPE, $state);
            break;
        default:
            // do nothing
            break;
    }
}
?>
<!doctype html>
<html lang="en-US">

<div class="container">
    <div class="col-md-8">
        <ol class="breadcrumb">
            <li><a href="/examples">Examples</a></li>
            <li><a href="/examples/OAuth">OAuth</a></li>
            <li class="active">callback</li>
        </ol>
        <p>
            <a href="index.php">&lt;Назад</a>
        </p>

        <?php 
use Yandex\OAuth\OAuthClient;
$client = new OAuthClient($settings['global']['clientId'], $settings['global']['clientSecret']);
if (isset($_COOKIE['yaAccessToken'])) {
    $client->setAccessToken($_COOKIE['yaAccessToken']);
    echo '<p>PHP: Access token from cookies is ' . htmlentities($client->getAccessToken()) . '</p>';
}
/**
 * There are two ways to get an access token from Yandex OAuth API.
 * First one is to get in browser after # symbol. It's handled above with JS and PHP.
 * Second one is to use an intermediate code. It's handled below with PHP.
 *
 * This file implements both cases because the only one callback url can be set for an application.
 *
 */
if (isset($_REQUEST['code'])) {
    try {
        $client->requestAccessToken($_REQUEST['code']);