Class WebAuth
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
|
public
|
|
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
|
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):
$givenKey = $_GET['oauth_token'];
$requestToken = RequestToken::deserialize($_SESSION['dropbox-request-token'])
if (!$requestToken->matchesKey($givenKey)) {
$webAuth = new dbx\WebAuth($config);
list($accessToken, $dropboxUserId) = $webAuth->finish($requestToken);
saveDropboxAccessTokenInYourDatabase($accessToken->serialize());
Parameters
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
|