function Auth() { list($accessToken, $userId, $urlState) = getWebAuth()->finish($_GET); assert($urlState === null); // Since we didn't pass anything in start() $_SESSION['accessToken'] = $accessToken; $start = 'http://localhost:8888/'; header("Location: {$start}"); return $accessToken; }
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ require_once './common.php'; require_once "./dropbox-sdk/Dropbox/autoload.php"; use Dropbox as dbx; try { $myarr = array("state" => $_GET["state"], "code" => $_GET["code"]); if (!isset($_SESSION['accessToken'])) { list($accessToken, $userId, $urlState) = getWebAuth()->finish($myarr); $_SESSION['accessToken'] = $accessToken; $_SESSION['userID'] = $userId; $_SESSION['urlState'] = $urlState; } else { $accessToken = $_SESSION['accessToken']; $userId = $_SESSION['userID']; $urlState = $_SESSION['urlState']; } assert($urlState === null); // Since we didn't pass anything in start() } catch (dbx\WebAuthException_BadRequest $ex) { error_log("/dropbox-auth-finish: bad request: " . $ex->getMessage()); // Respond with an HTTP 400 and display error page... } catch (dbx\WebAuthException_BadState $ex) { // Auth session expired. Restart the auth process. header('Location: /dropbox-auth-start'); } catch (dbx\WebAuthException_Csrf $ex) {
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/getWebAuth.php"; use Dropbox as dbx; //error_reporting(E_ALL); //ini_set('display_errors', 1); session_start(); $authorizeUrl = getWebAuth()->start(); header("Location: {$authorizeUrl}");
<?php // configuration require "../includes/config.php"; // if form was submitted use Dropbox as dbx; #dumps the access code and user id of user to mysql table if ($_SERVER["REQUEST_METHOD"] == "GET") { require_once "../lib/Dropbox/autoload.php"; function getWebAuth() { $appInfo = dbx\AppInfo::loadFromJsonFile("../lib/Dropbox/app-info.json"); $clientIdentifier = "my-app/1.0"; $redirectUri = "http://localhost/dump.php"; $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token'); return new dbx\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore, "en"); } #finishes authentication with access code and user id list($accessToken, $userId) = getWebAuth()->finish($_GET); #generates a client object which we can grab information with by calling getAccountInfo() $client = new dbx\Client($accessToken, "PHP"); $accountInfo = $client->getAccountInfo(); $email = $accountInfo['email']; #input acess information to mysql table. query("INSERT INTO dropbox_accounts (dropbox_email, dropbox_id, dropbox_accessToken, id) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE dropbox_accessToken = ?", $email, $userId, $accessToken, $_SESSION["id"], $accessToken); } render("temp_form.php", ["title" => "succcessss"]);
public function test_getWebAuth() { $this->assertNotEmpty(getWebAuth()); }