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 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
Extended by Dropbox\WebAuthBase
Extended by Dropbox\WebAuthNoRedirect
Namespace: Dropbox
Located at Dropbox/WebAuthNoRedirect.php
Methods summary
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 Dropbox\WebAuthNoRedirect::finish().

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 Dropbox\WebAuthNoRedirect::finish().

See /oauth2/authorize.

Returns

string

An authorization URL. Direct the user's browser to this URL. After the user decides whether to authorize your app or not, Dropbox will show the user an authorization code, which the user will need to give to your application (e.g. via copy/paste).

public array
# finish( string $code )

Call this after the user has visited the authorize URL returned by Dropbox\WebAuthNoRedirect::start(), approved your app, was presented with an authorization code by Dropbox, and has copy/paste'd that authorization code into your app.

Call this after the user has visited the authorize URL returned by Dropbox\WebAuthNoRedirect::start(), approved your app, was presented with an authorization code by Dropbox, and has copy/paste'd that authorization code into your app.

See /oauth2/token.

Parameters

$code
The authorization code provided to the user by Dropbox.

Returns

array

A list(string $accessToken, string $userId), where $accessToken can be used to construct a Dropbox\Client and $userId is the user ID of the user's Dropbox account.

Throws

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