Exception
6 years ago
WebAuthException
6 years ago
certs
6 years ago
AppInfo.php
6 years ago
AppInfoLoadException.php
6 years ago
ArrayEntryStore.php
6 years ago
AuthBase.php
6 years ago
AuthInfo.php
6 years ago
AuthInfoLoadException.php
6 years ago
Checker.php
6 years ago
Client.php
6 years ago
Curl.php
6 years ago
CurlStreamRelay.php
6 years ago
DeserializeException.php
6 years ago
DropboxMetadataHeaderCatcher.php
6 years ago
Exception.php
6 years ago
Host.php
6 years ago
HttpResponse.php
6 years ago
OAuth1AccessToken.php
6 years ago
OAuth1Upgrader.php
6 years ago
Path.php
6 years ago
RequestUtil.php
6 years ago
RootCertificates.php
6 years ago
SSLTester.php
6 years ago
Security.php
6 years ago
StreamReadException.php
6 years ago
Util.php
6 years ago
ValueStore.php
6 years ago
WebAuth.php
6 years ago
WebAuthBase.php
6 years ago
WebAuthNoRedirect.php
6 years ago
WriteMode.php
6 years ago
autoload.php
6 years ago
strict.php
6 years ago
WebAuthNoRedirect.php
83 lines
| 1 | <?php |
| 2 | namespace Dropbox; |
| 3 | |
| 4 | /** |
| 5 | * OAuth 2 code-based authorization for apps that can't provide a redirect URI, typically |
| 6 | * command-line example apps. |
| 7 | * |
| 8 | * Use {@link WebAuth::start()} and {@link WebAuth::getToken()} to guide your |
| 9 | * user through the process of giving your app access to their Dropbox account. At the end, you |
| 10 | * will have an {@link AccessToken}, which you can pass to {@link Client} and start making |
| 11 | * API calls. |
| 12 | * |
| 13 | * Example: |
| 14 | * |
| 15 | * <code> |
| 16 | * use \Dropbox as dbx; |
| 17 | * $appInfo = dbx\AppInfo::loadFromJsonFile(...); |
| 18 | * $clientIdentifier = "my-app/1.0"; |
| 19 | * $webAuth = new dbx\WebAuthNoRedirect($appInfo, $clientIdentifier, ...); |
| 20 | * |
| 21 | * $authorizeUrl = $webAuth->start(); |
| 22 | * |
| 23 | * print("1. Go to: $authorizeUrl\n"); |
| 24 | * print("2. Click "Allow" (you might have to log in first).\n"); |
| 25 | * print("3. Copy the authorization code.\n"); |
| 26 | * print("Enter the authorization code here: "); |
| 27 | * $code = \trim(\fgets(STDIN)); |
| 28 | * |
| 29 | * try { |
| 30 | * list($accessToken, $userId) = $webAuth->finish($code); |
| 31 | * } |
| 32 | * catch (dbx\Exception $ex) { |
| 33 | * print("Error communicating with Dropbox API: " . $ex->getMessage() . "\n"); |
| 34 | * } |
| 35 | * |
| 36 | * $client = dbx\Client($accessToken, $clientIdentifier, ...); |
| 37 | * </code> |
| 38 | */ |
| 39 | class WebAuthNoRedirect extends WebAuthBase |
| 40 | { |
| 41 | /** |
| 42 | * Returns the URL of the authorization page the user must visit. If the user approves |
| 43 | * your app, they will be shown the authorization code on the web page. They will need to |
| 44 | * copy/paste that code into your application so your app can pass it to |
| 45 | * {@link finish}. |
| 46 | * |
| 47 | * See <a href="https://www.dropbox.com/developers/core/docs#oa2-authorize">/oauth2/authorize</a>. |
| 48 | * |
| 49 | * @return string |
| 50 | * An authorization URL. Direct the user's browser to this URL. After the user decides |
| 51 | * whether to authorize your app or not, Dropbox will show the user an authorization code, |
| 52 | * which the user will need to give to your application (e.g. via copy/paste). |
| 53 | */ |
| 54 | function start() |
| 55 | { |
| 56 | return $this->_getAuthorizeUrl(null, null); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Call this after the user has visited the authorize URL returned by {@link start()}, |
| 61 | * approved your app, was presented with an authorization code by Dropbox, and has copy/paste'd |
| 62 | * that authorization code into your app. |
| 63 | * |
| 64 | * See <a href="https://www.dropbox.com/developers/core/docs#oa2-token">/oauth2/token</a>. |
| 65 | * |
| 66 | * @param string $code |
| 67 | * The authorization code provided to the user by Dropbox. |
| 68 | * |
| 69 | * @return array |
| 70 | * A <code>list(string $accessToken, string $userId)</code>, where |
| 71 | * <code>$accessToken</code> can be used to construct a {@link Client} and |
| 72 | * <code>$userId</code> is the user ID of the user's Dropbox account. |
| 73 | * |
| 74 | * @throws Exception |
| 75 | * Thrown if there's an error getting the access token from Dropbox. |
| 76 | */ |
| 77 | function finish($code) |
| 78 | { |
| 79 | Checker::argStringNonEmpty("code", $code); |
| 80 | return $this->_finish($code, null); |
| 81 | } |
| 82 | } |
| 83 |