Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Session if not started previously on SessionPersistentDataStore #160

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ index.php
composer.lock
/.idea
.php_cs.cache
.DS_Store
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"guzzlehttp/guzzle": "~6.0",
"guzzlehttp/guzzle": ">=6.3",
"tightenco/collect": "^5.2"
},
"autoload": {
Expand Down
51 changes: 20 additions & 31 deletions src/Dropbox/Authentication/OAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class OAuth2Client
*
* @const string
*/
const BASE_URL = "https://dropbox.com";
const BASE_URL = 'https://dropbox.com';

/**
* Auth Token URL
*
* @const string
*/
const AUTH_TOKEN_URL = "https://api.dropboxapi.com/oauth2/token";
const AUTH_TOKEN_URL = 'https://api.dropboxapi.com/oauth2/token';

/**
* The Dropbox App
Expand Down Expand Up @@ -68,8 +68,7 @@ public function __construct(DropboxApp $app, DropboxClient $client, RandomString
*/
protected function buildUrl($endpoint = '', array $params = [])
{
$queryParams = http_build_query($params);
return static::BASE_URL . $endpoint . '?' . $queryParams;
return static::BASE_URL . $endpoint . '?' . http_build_query($params, '', '&');
}

/**
Expand Down Expand Up @@ -108,12 +107,12 @@ public function getClient()
*/
public function getAuthorizationUrl($redirectUri = null, $state = null, array $params = [])
{
//Request Parameters
// Request Parameters
$params = array_merge([
'client_id' => $this->getApp()->getClientId(),
'response_type' => 'code',
'state' => $state,
], $params);
], $params);

if (!is_null($redirectUri)) {
$params['redirect_uri'] = $redirectUri;
Expand All @@ -133,31 +132,23 @@ public function getAuthorizationUrl($redirectUri = null, $state = null, array $p
*/
public function getAccessToken($code, $redirectUri = null, $grant_type = 'authorization_code')
{
//Request Params
// Request Params
$params = [
'code' => $code,
'grant_type' => $grant_type,
'client_id' => $this->getApp()->getClientId(),
'client_secret' => $this->getApp()->getClientSecret(),
'redirect_uri' => $redirectUri
'code' => $code,
'grant_type' => $grant_type,
'client_id' => $this->getApp()->getClientId(),
'client_secret' => $this->getApp()->getClientSecret(),
'redirect_uri' => $redirectUri
];

$params = http_build_query($params);

$apiUrl = static::AUTH_TOKEN_URL;
$uri = $apiUrl . "?" . $params;

//Send Request through the DropboxClient
//Fetch the Response (DropboxRawResponse)
$response = $this->getClient()
->getHttpClient()
->send($uri, "POST", null);
$uri = static::AUTH_TOKEN_URL . '?' . http_build_query($params, '', '&');

//Fetch Response Body
$body = $response->getBody();
// Send Request through the DropboxClient
// Fetch the Response (DropboxRawResponse)
$body = $this->getClient()->getHttpClient()->send($uri, 'POST', null)->getBody();

//Decode the Response body to associative array
//and return
// Decode the Response body to associative array
// and return
return json_decode((string) $body, true);
}

Expand All @@ -168,18 +159,16 @@ public function getAccessToken($code, $redirectUri = null, $grant_type = 'author
*/
public function revokeAccessToken()
{
//Access Token
$accessToken = $this->getApp()->getAccessToken();
// Request
$request = new DropboxRequest('POST', '/auth/token/revoke', $this->getApp()->getAccessToken());

//Request
$request = new DropboxRequest("POST", "/auth/token/revoke", $accessToken);
// Do not validate the response
// since the /token/revoke endpoint
// doesn't return anything in the response.
// See: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke
$request->setParams(['validateResponse' => false]);

//Revoke Access Token
// Revoke Access Token
$this->getClient()->sendRequest($request);
}
}
Loading