Overview

Classes

  • Dropbox\AccessToken
  • Dropbox\AccessType
  • Dropbox\AppInfo
  • Dropbox\AuthInfo
  • Dropbox\Client
  • Dropbox\Config
  • Dropbox\Path
  • Dropbox\RequestToken
  • Dropbox\Token
  • Dropbox\WebAuth
  • Dropbox\WriteMode

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_ProtocolError
  • Dropbox\Exception_RetryLater
  • Dropbox\Exception_ServerError
  • Overview
  • Class
  • Tree

Class WebAuth

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 a Dropbox\AccessToken, which you can pass to Dropbox\Client and start making API calls.

This class is stateless so it can be shared/reused.

Final
Namespace: Dropbox
Located at Dropbox/WebAuth.php
Methods summary
public Dropbox\Config
# getConfig( )

The config used when making requests to the Dropbox server.

The config used when making requests to the Dropbox server.

Returns

Dropbox\Config
public
# __construct( Dropbox\Config $config )

Constructor.

Constructor.

Parameters

$config
Dropbox\Config
$config See Dropbox\WebAuth::getConfig()
public array
# start( string $callbackUrl )

Tells Dropbox that you want to start authorization and returns the information necessary to continue authorization. This corresponds to step 1 of the three-step OAuth web flow.

Tells Dropbox that you want to start authorization and returns the information necessary to continue authorization. This corresponds to step 1 of the three-step OAuth web flow.

After this function returns, direct your user to the returned $authorizeUrl, which gives them a chance to grant your application access to their Dropbox account. This corresponds to step 2 of the three-step OAuth web flow.

If they choose to grant access, they will be redirected to the URL you provide for $callbackUrl, after which you should call Dropbox\WebAuth::finish() to get an access token.

use \Dropbox as dbx;
$config = new dbx\Config(...);
$webAuth = new dbx\WebAuth($config);
$callbackUrl = "https://example.org/dropbox-auth-finish";
list($requestToken, $authorizeUrl) = $webAuth->start($callbackUrl);
$_SESSION['dropbox-request-token'] = $requestToken->serialize();
header("Location: $authorizeUrl");

Parameters

$callbackUrl
string
$callbackUrl The URL that the Dropbox servers will redirect the user to after the user finishes authorizing your app. If this is null, the user will not be redirected.

Returns

array
A list(RequestToken $requestToken, string $authorizeUrl). Redirect the user's browser to $authorizeUrl. When they're done authorizing, call Dropbox\WebAuth::finish() with $requestToken.

Throws

Dropbox\Exception
public array
# finish( Dropbox\RequestToken $requestToken )

Call this after the user has visited the authorize URL (returned by Dropbox\WebAuth::start()) and approved your app. This corresponds to step 3 of the three-step OAuth web flow.

Call this after the user has visited the authorize URL (returned by Dropbox\WebAuth::start()) and approved your app. This corresponds to step 3 of the three-step OAuth web flow.

Example (see start() for first part):

// In the request handler for "/dropbox-auth-finish"
$givenKey = $_GET['oauth_token'];
$requestToken = RequestToken::deserialize($_SESSION['dropbox-request-token'])
if (!$requestToken->matchesKey($givenKey)) {
    // Do not continue.  You could show an error or redirect back to
    // the beginning of the authorization process.

$webAuth = new dbx\WebAuth($config);
list($accessToken, $dropboxUserId) = $webAuth->finish($requestToken);
saveDropboxAccessTokenInYourDatabase($accessToken->serialize());

Parameters

$requestToken
Dropbox\RequestToken
$requestToken The RequestToken returned by Dropbox\WebAuth::start().

Returns

array
A list(RequestToken $requestToken, string $dropboxUserId). Use $requestToken to construct a Dropbox\Client object and start making API calls. $dropboxUserId is the user ID of the user's Dropbox account and is for your own reference.

Throws

Dropbox\Exception
Dropbox SDK for PHP API documentation generated by ApiGen 2.8.0