Impossible to define dynamic user token #179
Replies: 6 comments 1 reply
-
Have you found a solution? I need this also |
Beta Was this translation helpful? Give feedback.
-
I am also wondering how to do this |
Beta Was this translation helpful? Give feedback.
-
I need this too, unless this is out of this package scope I can PR solution @freekmurze @Gummibeer ? |
Beta Was this translation helpful? Give feedback.
-
I also need it urgently |
Beta Was this translation helpful? Give feedback.
-
You can easliy override Laravel config on a per user basis, here is how I do it: // First override Laravel default config for given user
Config::set('google-calendar', [
'auth_profiles' => [
'service_account' => [
'credentials_json' => storage_path('app/google-calendar/api-key-' . Auth::id() . '.json'),
]
],
'calendar_id' => Auth::user()->preference->google_calendar_id,
] + config('google-calendar'));
// Then interact with the API
$googleEvent = new GoogleEvent;
... |
Beta Was this translation helpful? Give feedback.
-
You may also extend the Event class to use the app container to get the GoogleCalendar instance instead of using GoogleCalendarFactory class Event extends \Spatie\GoogleCalendar\Event
{
protected static function getGoogleCalendar(string $calendarId = null): GoogleCalendar
{
return app(GoogleCalendar::class, ['calendarId' => $calendarId]);
}
} then in AppServiceProvider, overwrite the binder $this->app->bind(GoogleCalendar::class, function ($app, $params) {
$calendarId = $params['calendarId'];
$token = Socialite::driver('google')->user()->token;
$client = new \Google\Client();
$client->setAccessToken($token);
$service = new \Google_Service_Calendar($client);
return new GoogleCalendar($service, $calendarId);
}); |
Beta Was this translation helpful? Give feedback.
-
In GoogleCalendarFactory , method createOAuthClient
$client->setAccessToken(file_get_contents($authProfile['token_json']));
It's meens it's always the same $client who is use.
How to add the event to another user's google account ?
Beta Was this translation helpful? Give feedback.
All reactions