Skip to content

Commit d136195

Browse files
authored
Merge pull request #21 from acgonzales/main
Allow to set access token on Google client
2 parents 85487cc + cba06f4 commit d136195

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ FILESYSTEM_CLOUD=google
2121
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
2222
GOOGLE_DRIVE_CLIENT_SECRET=xxx
2323
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
24+
GOOGLE_DRIVE_ACCESS_TOKEN=xxx
2425
GOOGLE_DRIVE_FOLDER=
2526
```
2627
config filesystem.php
@@ -30,6 +31,7 @@ config filesystem.php
3031
'driver' => 'google',
3132
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
3233
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
34+
'accessToken' => env('GOOGLE_DRIVE_ACCESS_TOKEN'), // optional
3335
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
3436
'folder' => env('GOOGLE_DRIVE_FOLDER'),
3537
]
@@ -47,6 +49,22 @@ example :
4749
```
4850
refrensi code opration [sample code](https://github.com/ivanvermeyen/laravel-google-drive-demo/blob/master/routes/web.php)
4951

52+
Usage with `accessToken`. Could be useful if you want to use your user's token e.g upload a file in their own Drive.
53+
54+
```php
55+
// Build an on-demand disk
56+
$disk = Storage::build([
57+
'driver' => 'google',
58+
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
59+
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
60+
'accessToken' => auth()->user()->google_access_token, // Get from authenticated user
61+
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
62+
'folder' => env('GOOGLE_DRIVE_FOLDER'),
63+
]);
64+
65+
$disk->put($filename, File::get($filepath));
66+
```
67+
5068
<br>
5169
or use helper from this package
5270
<br>

src/LaravelGoogleDriveStorageServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function bootingPackage()
4040
$client->setClientSecret($config['clientSecret']);
4141
$client->refreshToken($config['refreshToken']);
4242

43+
if (isset($config['accessToken'])) {
44+
$client->setAccessToken($config['accessToken']);
45+
}
46+
4347
$service = new \Google\Service\Drive($client);
4448
$adapter = new \Masbug\Flysystem\GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
4549
$driver = new \League\Flysystem\Filesystem($adapter);

0 commit comments

Comments
 (0)