ivanvermeyen / laravel-google-drive-demo

Laravel & Google Drive Storage - Demo project with Laravel 5.4
403 stars 155 forks source link

[ NOT AN ISSUE] How to use this demo with Service Account as credentials #47

Open acacha opened 5 years ago

acacha commented 5 years ago

Hello,

I want to share with you the modifications I've done to use service account (json file) to authenticat instead of using Oauth tokens:

At file app\Providers\GoogleDriveServiceProvider change :

$client = new \Google_Client();
$client->setClientId($config['clientId']);
 $client->setClientSecret($config['clientSecret']);
 $client->refreshToken($config['refreshToken'])

to

$credentials_file = storage_path('app/gsuite_service_accounts/scool-07eed0b50a6f.json');
$client = new Google_Client();
$client->setAuthConfig($credentials_file);
$client->addScope(Google_Service_Drive::DRIVE);
$client->setSubject('sergitur@iesebre.com');

Also don't forget to add permissions (scope: https://www.googleapis.com/auth/drive) to this client in your Google Suite domain to avoid permission errors enteirng at your Admin console at security section > Advanced >Manage API client access URL similar to:

https://admin.google.com/YOUR_DOMAIN/AdminHome?chromeless=1#OGX:ManageOauthClients

ivanvermeyen commented 5 years ago

Thanks! 👍

fagnerdireito commented 3 years ago

Thanks! 👍