Overview

Classes

  • Dropbox\AppInfo
  • Dropbox\ArrayEntryStore
  • Dropbox\AuthBase
  • Dropbox\AuthInfo
  • Dropbox\Client
  • Dropbox\OAuth1AccessToken
  • Dropbox\OAuth1Upgrader
  • Dropbox\Path
  • Dropbox\RootCertificates
  • Dropbox\Security
  • Dropbox\SSLTester
  • Dropbox\Util
  • Dropbox\WebAuth
  • Dropbox\WebAuthBase
  • Dropbox\WebAuthNoRedirect
  • Dropbox\WriteMode

Interfaces

  • Dropbox\ValueStore

Exceptions

  • Dropbox\AppInfoLoadException
  • Dropbox\AuthInfoLoadException
  • Dropbox\DeserializeException
  • Dropbox\Exception
  • Dropbox\Exception_BadRequest
  • Dropbox\Exception_BadResponse
  • Dropbox\Exception_BadResponseCode
  • Dropbox\Exception_InvalidAccessToken
  • Dropbox\Exception_NetworkIO
  • Dropbox\Exception_OverQuota
  • Dropbox\Exception_ProtocolError
  • Dropbox\Exception_RetryLater
  • Dropbox\Exception_ServerError
  • Dropbox\HostLoadException
  • Dropbox\StreamReadException
  • Dropbox\WebAuthException_BadRequest
  • Dropbox\WebAuthException_BadState
  • Dropbox\WebAuthException_Csrf
  • Dropbox\WebAuthException_NotApproved
  • Dropbox\WebAuthException_Provider
  • Overview
  • Class

Class WebAuth

OAuth 2 "authorization code" flow. (This SDK does not support the "token" flow.)

Use Dropbox\WebAuth::start() and Dropbox\WebAuth::finish() to guide your user through the process of giving your app access to their Dropbox account. At the end, you will have an access token, which you can pass to Dropbox\Client and start making API calls.

Example:

use \Dropbox as dbx;

function getWebAuth()
{
   $appInfo = dbx\AppInfo::loadFromJsonFile(...);
   $clientIdentifier = "my-app/1.0";
   $redirectUri = "https://example.org/dropbox-auth-finish";
   $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
   return new dbx\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore, ...);
}

// ----------------------------------------------------------
// In the URL handler for "/dropbox-auth-start"

$authorizeUrl = getWebAuth()->start();
header("Location: $authorizeUrl");

// ----------------------------------------------------------
// In the URL handler for "/dropbox-auth-finish"

try {
   list($accessToken, $userId, $urlState) = getWebAuth()->finish($_GET);
   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) {
   error_log("/dropbox-auth-finish: CSRF mismatch: " . $ex->getMessage());
   // Respond with HTTP 403 and display error page...
}
catch (dbx\WebAuthException_NotApproved $ex) {
   error_log("/dropbox-auth-finish: not approved: " . $ex->getMessage());
}
catch (dbx\WebAuthException_Provider $ex) {
   error_log("/dropbox-auth-finish: error redirect from Dropbox: " . $ex->getMessage());
}
catch (dbx\Exception $ex) {
   error_log("/dropbox-auth-finish: error communicating with Dropbox API: " . $ex->getMessage());
}

// We can now use $accessToken to make API requests.
$client = dbx\Client($accessToken, ...);
Dropbox\AuthBase
Extended by Dropbox\WebAuthBase
Extended by Dropbox\WebAuth
Namespace: Dropbox
Located at Dropbox/WebAuth.php
Methods summary
public string
# getRedirectUri( )

The URI that the Dropbox server will redirect the user to after the user finishes authorizing your app. This URI must be HTTPS-based and pre-registered with Dropbox, though "localhost"-based and "127.0.0.1"-based URIs are allowed without pre-registration and can be either HTTP or HTTPS.

The URI that the Dropbox server will redirect the user to after the user finishes authorizing your app. This URI must be HTTPS-based and pre-registered with Dropbox, though "localhost"-based and "127.0.0.1"-based URIs are allowed without pre-registration and can be either HTTP or HTTPS.

Returns

string
public Dropbox\ValueStore
# getCsrfTokenStore( )

A object that lets us save CSRF token string to the user's session. If you're using the standard PHP $_SESSION, you can pass in something like new ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token').

A object that lets us save CSRF token string to the user's session. If you're using the standard PHP $_SESSION, you can pass in something like new ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token').

If you're not using $_SESSION, you might have to create your own class that provides the same get()/set()/clear() methods as Dropbox\ArrayEntryStore.

Returns

Dropbox\ValueStore
public
# __construct( Dropbox\AppInfo $appInfo, string $clientIdentifier, null|string $redirectUri, null|Dropbox\ValueStore $csrfTokenStore, null|string $userLocale = null )

Constructor.

Constructor.

Parameters

$appInfo
See Dropbox\AuthBase::getAppInfo()
$clientIdentifier
See Dropbox\AuthBase::getClientIdentifier()
$redirectUri
See Dropbox\WebAuth::getRedirectUri()
$csrfTokenStore
See Dropbox\WebAuth::getCsrfTokenStore()
$userLocale
See Dropbox\AuthBase::getUserLocale()

Overrides

Dropbox\AuthBase::__construct()
public array
# start( string|null $urlState = null, boolean|null $forceReapprove = false )

Starts the OAuth 2 authorization process, which involves redirecting the user to the returned authorization URL (a URL on the Dropbox website). When the user then either approves or denies your app access, Dropbox will redirect them to the $redirectUri given to constructor, at which point you should call Dropbox\WebAuth::finish() to complete the authorization process.

Starts the OAuth 2 authorization process, which involves redirecting the user to the returned authorization URL (a URL on the Dropbox website). When the user then either approves or denies your app access, Dropbox will redirect them to the $redirectUri given to constructor, at which point you should call Dropbox\WebAuth::finish() to complete the authorization process.

This function will also save a CSRF token using the $csrfTokenStore given to the constructor. This CSRF token will be checked on Dropbox\WebAuth::finish() to prevent request forgery.

See /oauth2/authorize.

Parameters

$urlState

Any data you would like to keep in the URL through the authorization process. This exact state will be returned to you by Dropbox\WebAuth::finish().

$forceReapprove

If a user has already approved your app, Dropbox may skip the "approve" step and redirect immediately to your callback URL. Setting this to true tells Dropbox to never skip the "approve" step.

Returns

array
The URL to redirect the user to.

Throws

Dropbox\Exception
public array
# finish( array $queryParams )

Call this after the user has visited the authorize URL (Dropbox\WebAuth::start()), approved your app, and was redirected to your redirect URI.

Call this after the user has visited the authorize URL (Dropbox\WebAuth::start()), approved your app, and was redirected to your redirect URI.

See /oauth2/token.

Parameters

$queryParams
The query parameters on the GET request to your redirect URI.

Returns

array

A list(string $accessToken, string $userId, string $urlState), where $accessToken can be used to construct a Dropbox\Client, $userId is the user ID of the user's Dropbox account, and $urlState is the value you originally passed in to Dropbox\WebAuth::start().

Throws

Dropbox\Exception
Thrown if there's an error getting the access token from Dropbox.
Dropbox\WebAuthException_BadRequest
Dropbox\WebAuthException_BadState
Dropbox\WebAuthException_Csrf
Dropbox\WebAuthException_NotApproved
Dropbox\WebAuthException_Provider
Methods inherited from Dropbox\AuthBase
getAppInfo(), getClientIdentifier(), getUserLocale()
Dropbox SDK for PHP API documentation generated by ApiGen