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
- Dropbox\WebAuthBase
- Dropbox\WebAuth
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. |
public
|
#
getCsrfTokenStore( )
A object that lets us save CSRF token string to the user's session. If you're using the
standard PHP |
public
|
#
__construct(
Constructor. |
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
|
public
array
|
#
finish( array $queryParams )
Call this after the user has visited the authorize URL ( |
getAppInfo(),
getClientIdentifier(),
getUserLocale()
|