@@ -67,12 +67,12 @@ public function connect()
67
67
if (!request ()->has ('code ' )) {
68
68
69
69
$ 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
+ ]);
76
76
77
77
return redirect ()->away ($ url );
78
78
} elseif (request ()->has ('code ' )) {
@@ -81,11 +81,11 @@ public function connect()
81
81
try {
82
82
83
83
$ 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 ' ),
89
89
];
90
90
91
91
$ token = $ this ->dopost (self ::$ tokenUrl , $ params );
@@ -124,10 +124,10 @@ public function disconnect($redirectPath = '/')
124
124
$ id = auth ()->id ();
125
125
126
126
$ client = new Client ;
127
- $ response = $ client ->post (self ::$ baseUrl. 'auth/token/revoke ' , [
127
+ $ response = $ client ->post (self ::$ baseUrl . 'auth/token/revoke ' , [
128
128
'headers ' => [
129
- 'Authorization ' => 'Bearer ' . $ this ->getAccessToken ()
130
- ]
129
+ 'Authorization ' => 'Bearer ' . $ this ->getAccessToken (),
130
+ ],
131
131
]);
132
132
133
133
//delete token from db
@@ -136,7 +136,7 @@ public function disconnect($redirectPath = '/')
136
136
$ token ->delete ();
137
137
}
138
138
139
- header ('Location: ' .url ($ redirectPath ));
139
+ header ('Location: ' . url ($ redirectPath ));
140
140
exit ();
141
141
}
142
142
@@ -154,14 +154,14 @@ public function getAccessToken($returnNullNoAccessToken = null)
154
154
}
155
155
156
156
//use id if passed otherwise use logged in user
157
- $ id = auth ()->id ();
157
+ $ id = auth ()->id ();
158
158
$ token = DropboxToken::where ('user_id ' , $ id )->first ();
159
159
160
160
// Check if tokens exist otherwise run the oauth request
161
161
if (!isset ($ token ->access_token )) {
162
162
163
163
//don't redirect simply return null when no token found with this option
164
- if ($ returnNullNoAccessToken == true ) {
164
+ if ($ returnNullNoAccessToken == true || app ()-> runningInConsole () ) {
165
165
return null ;
166
166
}
167
167
@@ -175,15 +175,15 @@ public function getAccessToken($returnNullNoAccessToken = null)
175
175
if ($ token ->expires_in ->lessThan (Carbon::now ()->addMinutes (5 ))) {
176
176
// Token is expired (or very close to it) so let's refresh
177
177
$ params = [
178
- 'grant_type ' => 'refresh_token ' ,
178
+ 'grant_type ' => 'refresh_token ' ,
179
179
'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 ' ),
182
182
];
183
183
184
- $ tokenResponse = $ this ->dopost (self ::$ tokenUrl , $ params );
184
+ $ tokenResponse = $ this ->dopost (self ::$ tokenUrl , $ params );
185
185
$ token ->access_token = $ tokenResponse ['access_token ' ];
186
- $ token ->expires_in = now ()->addseconds ($ tokenResponse ['expires_in ' ]);
186
+ $ token ->expires_in = now ()->addseconds ($ tokenResponse ['expires_in ' ]);
187
187
$ token ->save ();
188
188
189
189
return $ token ->access_token ;
@@ -222,20 +222,20 @@ protected function storeToken($token)
222
222
$ id = auth ()->id ();
223
223
224
224
$ 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 ' ],
232
232
];
233
233
234
234
if (isset ($ token ['refresh_token ' ])) {
235
235
$ data ['refresh_token ' ] = $ token ['refresh_token ' ];
236
236
}
237
237
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
239
239
return DropboxToken::updateOrCreate (['user_id ' => $ id ], $ data );
240
240
}
241
241
@@ -253,7 +253,7 @@ protected function guzzle($type, $request, $data = [], $customHeaders = null, $u
253
253
$ client = new Client ;
254
254
255
255
$ headers = [
256
- 'content-type ' => 'application/json '
256
+ 'content-type ' => 'application/json ' ,
257
257
];
258
258
259
259
if ($ useToken == true ) {
@@ -268,14 +268,12 @@ protected function guzzle($type, $request, $data = [], $customHeaders = null, $u
268
268
269
269
$ response = $ client ->$ type (self ::$ baseUrl . $ request , [
270
270
'headers ' => $ headers ,
271
- 'body ' => json_encode ($ data )
271
+ 'body ' => json_encode ($ data ),
272
272
]);
273
273
274
274
return json_decode ($ response ->getBody ()->getContents (), true );
275
275
} catch (ClientException $ e ) {
276
276
throw new Exception ($ e ->getResponse ()->getBody ()->getContents ());
277
- } catch (Exception $ e ) {
278
- throw new Exception ($ e ->getMessage ());
279
277
}
280
278
}
281
279
0 commit comments