dacastro4 / laravel-gmail

Laravel wrapper for the Gmail API
MIT License
292 stars 134 forks source link

Save tokens in Database #207

Open andrewlindemulder opened 3 years ago

andrewlindemulder commented 3 years ago

Is it possible to save tokens to a database using Laravel's database drivers? If not, can this be a feature request?

christoph-werker commented 3 years ago

At the Moment i use LaravelGmail::setUserId($userId) but it's not that handy. I wish that I can store the refreshtoken to use it for my requests for different users in my system.

Here is my dirty workaround:

  1. Redirect to Gmail-OAuth:

    Route::get('/oauth/gmail', function () {
    return LaravelGmail::setUserId($userId)->redirect();
    });
  2. Create Token file

    Route::get('/oauth/gmail/callback', function () {
    LaravelGmail::setUserId($userId)->makeToken();
    return redirect()->to('/');
    });
  3. Tokenfile is now saved here /storage/app/gmail/tokens/gmail-json-$userId.json

  4. Add .json File to your Live-Enviroment

Please set $userId to a id of your choise...