* Set configuration for client_id, client_secret and various OAuth endpoints
 */
require_once 'config.php';
/*
 * Check the configuration
 */
require_once 'check_config.php';
/*
 * Perform all authorization and authentication logic - exchanging auth
 * code for access token, retrieving user profile info, looking up
 * pre-existing refresh token in database, updating it (if applicable),
 * and more.
 */
require_once 'auth_handler.php';
$authHandler = new AuthHandler($requestType);
$authHandler->VerifyAuth();
/*
 * If an authorization 'code' is set, then we assume the user came from
 * Google Drive and check to see if the 'state' parameter exists, with
 * the mode and potially specified file IDs (on open) or a folder parentId
 * (on create).
 */
if (isset($_GET['code'])) {
    /*
     * State should always be defined
     */
    if (isset($_GET['state'])) {
        $state = json_decode(stripslashes($_GET['state']));
        $_SESSION['mode'] = $state->action;
        if (isset($state->ids)) {
            $_SESSION['fileIds'] = $state->ids;