Skip to content

Commit 24eedf5

Browse files
committed
hotfix
1 parent 8840937 commit 24eedf5

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

config/dropbox.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
return [
44

5+
'useLoggedUserId' => true,
6+
57
/*
68
* set the client id
79
*/

src/Dropbox.php

+32-34
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function connect()
6767
if (!request()->has('code')) {
6868

6969
$url = self::$authorizeUrl . '?' . http_build_query([
70-
'response_type' => 'code',
71-
'client_id' => config('dropbox.clientId'),
72-
'redirect_uri' => config('dropbox.redirectUri'),
73-
'scope' => config('dropbox.scopes'),
74-
'token_access_type' => config('dropbox.accessType')
75-
]);
70+
'response_type' => 'code',
71+
'client_id' => config('dropbox.clientId'),
72+
'redirect_uri' => config('dropbox.redirectUri'),
73+
'scope' => config('dropbox.scopes'),
74+
'token_access_type' => config('dropbox.accessType'),
75+
]);
7676

7777
return redirect()->away($url);
7878
} elseif (request()->has('code')) {
@@ -81,11 +81,11 @@ public function connect()
8181
try {
8282

8383
$params = [
84-
'grant_type' => 'authorization_code',
85-
'code' => request('code'),
86-
'redirect_uri' => config('dropbox.redirectUri'),
87-
'client_id' => config('dropbox.clientId'),
88-
'client_secret' => config('dropbox.clientSecret')
84+
'grant_type' => 'authorization_code',
85+
'code' => request('code'),
86+
'redirect_uri' => config('dropbox.redirectUri'),
87+
'client_id' => config('dropbox.clientId'),
88+
'client_secret' => config('dropbox.clientSecret'),
8989
];
9090

9191
$token = $this->dopost(self::$tokenUrl, $params);
@@ -124,10 +124,10 @@ public function disconnect($redirectPath = '/')
124124
$id = auth()->id();
125125

126126
$client = new Client;
127-
$response = $client->post(self::$baseUrl.'auth/token/revoke', [
127+
$response = $client->post(self::$baseUrl . 'auth/token/revoke', [
128128
'headers' => [
129-
'Authorization' => 'Bearer ' . $this->getAccessToken()
130-
]
129+
'Authorization' => 'Bearer ' . $this->getAccessToken(),
130+
],
131131
]);
132132

133133
//delete token from db
@@ -136,7 +136,7 @@ public function disconnect($redirectPath = '/')
136136
$token->delete();
137137
}
138138

139-
header('Location: ' .url($redirectPath));
139+
header('Location: ' . url($redirectPath));
140140
exit();
141141
}
142142

@@ -154,14 +154,14 @@ public function getAccessToken($returnNullNoAccessToken = null)
154154
}
155155

156156
//use id if passed otherwise use logged in user
157-
$id = auth()->id();
157+
$id = auth()->id();
158158
$token = DropboxToken::where('user_id', $id)->first();
159159

160160
// Check if tokens exist otherwise run the oauth request
161161
if (!isset($token->access_token)) {
162162

163163
//don't redirect simply return null when no token found with this option
164-
if ($returnNullNoAccessToken == true) {
164+
if ($returnNullNoAccessToken == true || app()->runningInConsole()) {
165165
return null;
166166
}
167167

@@ -175,15 +175,15 @@ public function getAccessToken($returnNullNoAccessToken = null)
175175
if ($token->expires_in->lessThan(Carbon::now()->addMinutes(5))) {
176176
// Token is expired (or very close to it) so let's refresh
177177
$params = [
178-
'grant_type' => 'refresh_token',
178+
'grant_type' => 'refresh_token',
179179
'refresh_token' => $token->refresh_token,
180-
'client_id' => config('dropbox.clientId'),
181-
'client_secret' => config('dropbox.clientSecret')
180+
'client_id' => config('dropbox.clientId'),
181+
'client_secret' => config('dropbox.clientSecret'),
182182
];
183183

184-
$tokenResponse = $this->dopost(self::$tokenUrl, $params);
184+
$tokenResponse = $this->dopost(self::$tokenUrl, $params);
185185
$token->access_token = $tokenResponse['access_token'];
186-
$token->expires_in = now()->addseconds($tokenResponse['expires_in']);
186+
$token->expires_in = now()->addseconds($tokenResponse['expires_in']);
187187
$token->save();
188188

189189
return $token->access_token;
@@ -222,20 +222,20 @@ protected function storeToken($token)
222222
$id = auth()->id();
223223

224224
$data = [
225-
'user_id' => $id,
226-
'access_token' => $token['access_token'],
227-
'expires_in' => now()->addseconds($token['expires_in']),
228-
'token_type' => $token['token_type'],
229-
'uid' => $token['uid'],
230-
'account_id' => $token['account_id'],
231-
'scope' => $token['scope']
225+
'user_id' => config('dropbox.useLoggedUserId') ? $id : null,
226+
'access_token' => $token['access_token'],
227+
'expires_in' => now()->addseconds($token['expires_in']),
228+
'token_type' => $token['token_type'],
229+
'uid' => $token['uid'],
230+
'account_id' => $token['account_id'],
231+
'scope' => $token['scope'],
232232
];
233233

234234
if (isset($token['refresh_token'])) {
235235
$data['refresh_token'] = $token['refresh_token'];
236236
}
237237

238-
//cretate a new record or if the user id exists update record
238+
//create a new record or if the user id exists update record
239239
return DropboxToken::updateOrCreate(['user_id' => $id], $data);
240240
}
241241

@@ -253,7 +253,7 @@ protected function guzzle($type, $request, $data = [], $customHeaders = null, $u
253253
$client = new Client;
254254

255255
$headers = [
256-
'content-type' => 'application/json'
256+
'content-type' => 'application/json',
257257
];
258258

259259
if ($useToken == true) {
@@ -268,14 +268,12 @@ protected function guzzle($type, $request, $data = [], $customHeaders = null, $u
268268

269269
$response = $client->$type(self::$baseUrl . $request, [
270270
'headers' => $headers,
271-
'body' => json_encode($data)
271+
'body' => json_encode($data),
272272
]);
273273

274274
return json_decode($response->getBody()->getContents(), true);
275275
} catch (ClientException $e) {
276276
throw new Exception($e->getResponse()->getBody()->getContents());
277-
} catch (Exception $e) {
278-
throw new Exception($e->getMessage());
279277
}
280278
}
281279

0 commit comments

Comments
 (0)