Class WebAuthNoRedirect
OAuth 2 code-based authorization for apps that can't provide a redirect URI, typically command-line example apps.
Use Dropbox\WebAuthNoRedirect::start()
and getToken() to guide your
user through the process of giving your app access to their Dropbox account. At the end, you
will have an AccessToken, which you can pass to Dropbox\Client
and start making
API calls.
Example:
use \Dropbox as dbx; $appInfo = dbx\AppInfo::loadFromJsonFile(...); $clientIdentifier = "my-app/1.0"; $webAuth = new dbx\WebAuthNoRedirect($appInfo, $clientIdentifier, ...); $authorizeUrl = $webAuth->start(); print("1. Go to: $authorizeUrl\n"); print("2. Click "Allow" (you might have to log in first).\n"); print("3. Copy the authorization code.\n"); print("Enter the authorization code here: "); $code = \trim(\fgets(STDIN)); try { list($accessToken, $userId) = $webAuth->finish($code); } catch (dbx\Exception $ex) { print("Error communicating with Dropbox API: " . $ex->getMessage() . "\n"); } $client = dbx\Client($accessToken, $clientIdentifier, ...);
- Dropbox\AuthBase
- Dropbox\WebAuthBase
- Dropbox\WebAuthNoRedirect
public
string
|
#
start( )
Returns the URL of the authorization page the user must visit. If the user approves
your app, they will be shown the authorization code on the web page. They will need to
copy/paste that code into your application so your app can pass it to
|
public
array
|
#
finish( string $code )
Call this after the user has visited the authorize URL returned by |
__construct(),
getAppInfo(),
getClientIdentifier(),
getUserLocale()
|