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
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 
<?php
namespace Dropbox;

/**
 * The base class for the two auth options.
 */
class WebAuthBase extends AuthBase
{
    protected function _getAuthorizeUrl($redirectUri, $state, $forceReapprove = false)
    {
        if ($forceReapprove === false) {
            $forceReapprove = null;  // Don't include it in the URL if it's the default value.
        }
        return RequestUtil::buildUrlForGetOrPut(
            $this->userLocale,
            $this->appInfo->getHost()->getWeb(),
            "1/oauth2/authorize",
            array(
                "client_id" => $this->appInfo->getKey(),
                "response_type" => "code",
                "redirect_uri" => $redirectUri,
                "state" => $state,
                "force_reapprove" => $forceReapprove,
            ));
    }

    protected function _finish($code, $originalRedirectUri)
    {
        // This endpoint requires "Basic" auth.
        $clientCredentials = $this->appInfo->getKey().":".$this->appInfo->getSecret();
        $authHeaderValue = "Basic ".base64_encode($clientCredentials);

        $response = RequestUtil::doPostWithSpecificAuth(
            $this->clientIdentifier, $authHeaderValue, $this->userLocale,
            $this->appInfo->getHost()->getApi(),
            "1/oauth2/token",
            array(
                "grant_type" => "authorization_code",
                "code" => $code,
                "redirect_uri" => $originalRedirectUri,
            ));

        if ($response->statusCode !== 200) throw RequestUtil::unexpectedStatus($response);

        $parts = RequestUtil::parseResponseJson($response->body);

        if (!array_key_exists('token_type', $parts) || !is_string($parts['token_type'])) {
            throw new Exception_BadResponse("Missing \"token_type\" field.");
        }
        $tokenType = $parts['token_type'];
        if (!array_key_exists('access_token', $parts) || !is_string($parts['access_token'])) {
            throw new Exception_BadResponse("Missing \"access_token\" field.");
        }
        $accessToken = $parts['access_token'];
        if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
            throw new Exception_BadResponse("Missing \"uid\" string field.");
        }
        $userId = $parts['uid'];

        if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
            throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got  "
                                            .Util::q($tokenType));
        }

        return array($accessToken, $userId);
    }
}
Dropbox SDK for PHP API documentation generated by ApiGen