PHPackages                             skn036/laravel-google-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. skn036/laravel-google-client

ActiveLibrary[API Development](/categories/api)

skn036/laravel-google-client
============================

Wrapper for Google API Client Library for Laravel

1.0.12(1y ago)31.1k3[1 PRs](https://github.com/skn-036/laravel-google-client/pulls)1MITPHPPHP ^8.2

Since Sep 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/skn-036/laravel-google-client)[ Packagist](https://packagist.org/packages/skn036/laravel-google-client)[ Docs](https://github.com/skn036/laravel-google-client)[ GitHub Sponsors]()[ RSS](/packages/skn036-laravel-google-client/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (12)Versions (10)Used By (1)

Wrapper Around Google Client For Laravel
========================================

[](#wrapper-around-google-client-for-laravel)

This package only handles the authentication layer, securely saving, retrieving and revoking tokens around [google api client](https://github.com/googleapis/google-api-php-client). So it could be a good choice as authentication layer while using any api service from google.

For some common api services from google please check:

Gmail Api: [skn036/laravel-gmail-api](https://github.com/skn-036/laravel-gmail-api)
Calendar Api: [skn036/laravel-google-calendar (coming soon)](#)

For extending your own api service please follow the guidelines [below](#extending-this-package-to-google-api-services).

Installation
------------

[](#installation)

First install the package via composer.

```
composer require skn036/laravel-google-client
```

Then publish the config file. It will publishes google.php file in the config directory.

```
php artisan vendor:publish --provider="Skn036\Google\GoogleClientServiceProvider"
```

Configuration
-------------

[](#configuration)

Please look into config/google.php for detailed information about the configuration. First you need to enable the required api services and generate credentials in your google developers account. Please [see here](https://console.cloud.google.com/apis/credentials/oauthclient) from detailed instructions. Available .env variables for configuration are:

```
GOOGLE_APPLICATION_NAME=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=
GOOGLE_SCOPES=
GOOGLE_PUB_SUB_TOPIC=
```

#### Authentication Modes:

[](#authentication-modes)

There are three authentication modes:

- Single account in whole application ( set `credentials_per_user` to `false` in config file ).
- Single account per user ( set `credentials_per_user` to `true` &amp; `multiple_accounts_per_user` to `false` in config file ).
- Multiple accounts per user ( set `credentials_per_user` to `true` &amp; `multiple_accounts_per_user` to `true` in config file ).

**Note:** You need to set the scopes on .env file which google services you intended to use.

Getting Started
---------------

[](#getting-started)

```
use Illuminate\Http\Request;
use Skn036\Google\GoogleClient;

// pass the google client to the view
Route::get('/google-dashboard', function (Request $request) {
    $googleClient = new GoogleClient();
    return view('google-dashboard', compact('googleClient'));
})->name('google-dashboard');

// redirect go google oauth2 login page
Route::post('/google-login', function (Request $request) {
    return (new GoogleClient())->redirectToAuthUrl();
})->name('google-login');

// logout from google account
Route::post('/google-logout', function (Request $request) {
    (new GoogleClient())->logout();
    return redirect()->route('google-dashboard');
})->name('google-logout');

// authenticate the account from google oauth2 login success
// this route must match the redirect uri in google console and .env file
Route::get('/google-auth-callback', function (Request $request) {
    (new GoogleClient())->authenticate();
    return redirect()->route('google-dashboard');
});
```

**google-dashboard.blade.php**:

```

    @if ($googleClient->isAuthenticated())

        @csrf
         {{ __("Logout") }}

    @else

        @csrf
         {{ __("Login with Google") }}

    @endif

    {{ $googleClient->isAuthenticated() ? "Authenticated user:" . $googleClient->email : 'Not
    authenticated' }}

```

SPA Authentication
------------------

[](#spa-authentication)

If you are using SPA frontend like `React` or `Vue` and entirely handle the Oauth redirect in the frontend, you should call the getAuthUrl method to get the google Oauth url.

```
$url = $googleClient->getAuthUrl();
return response()->json($url);
```

After successful login from google, it should add `code` route query param on redirect uri set on the google console. You need to pass this code the `authenticate` method or if you pass the code as route query, it will automatically capture on authentication request;

```
$token = $googleClient->authenticate($request->code);
```

Single Account Per User Mode:
-----------------------------

[](#single-account-per-user-mode)

By default, authenticated user is passed to `GoogleClient` instance using laravel's `auth()->id()`. If you want to pass a user manually to client instance:

```
$googleClient = new GoogleClient(1); // pass the user's id
```

Multiple Account Per User Mode:
-------------------------------

[](#multiple-account-per-user-mode)

When using multiple accounts, first account synced will be set as default account. If you want to change the default account, first get the available accounts:

```
$accounts = $googleClient->getSyncedAccounts();
```

It will give a array of synced accounts like:

```
[
    ['email' => 'john@gmail.com', 'profile' => ['givenName' => 'John', 'familyName' => 'Doe', ...] ],
    ['email' => 'foo@gmail.com', 'profile' => ['givenName' => 'Foo', 'familyName' => 'Bar', ...] ],
];
```

Then you call `setDefaultAccount` method to change the default account.

```
$googleClient = $googleClient->setDefaultAccount('foo@gmail.com');
```

Normally it will use the default account to interact with the services. If you want to use other account rather than the default, you should pass the email of the intended account as the second argument of the client constructor.

```
$googleClient = new GoogleClient(1, 'foo@gmail.com');
```

Extending This Package To Google Api Services
---------------------------------------------

[](#extending-this-package-to-google-api-services)

First you should make a api service class extending the GoogleClient class. Then bind it to the api services to interact with the api.

For example we will extend to the `Gmail api` service:

```
use Skn036\Google\GoogleClient;
use YourNamespace\Gmail\GmailMessage;

class Gmail extends GoogleClient
{
    public function __construct(
        string|int|null $userId = null,
        ?string $usingAccount = null,
        ?array $config = null
    ) {
        parent::__construct($userId, $usingAccount, $config);
    }

    // access the messages on gmail api
    public function messages()
    {
        return new GmailMessage($this);
    }
}
```

On the `GmailMessage.php`:

```
namespace YourNamespace\Gmail;

class GmailMessage
{
    protected $service;
    protected $client;
    protected $params = [];

    public function __construct(Gmail $gmail)
    {
        $this->client = $gmail;
        $this->service = new \Google_Service_Gmail($gmail); // initiate the gmail api service
    }

    public function list($params = [])
    {
        $params = array_merge($this->params, $params);

        return $this->service->users_messages->listUsersMessages('me', $params);
    }
}
```

Now you can get the gmail messages by

```
$mails = (new Gmail())->messages()->list();
```

Tree Shaking Unused Google Services
-----------------------------------

[](#tree-shaking-unused-google-services)

There are more than 200 api services shipped together on google api. For tree shaking the unnecessary services, please follow instructions on [google api client](https://github.com/googleapis/google-api-php-client).

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance40

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~2 days

Total

9

Last Release

499d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/81521738?v=4)[Muhammad Sajedul Karim Noman](/maintainers/skn-036)[@skn-036](https://github.com/skn-036)

---

Top Contributors

[![skn-036](https://avatars.githubusercontent.com/u/81521738?v=4)](https://github.com/skn-036 "skn-036 (44 commits)")

---

Tags

laravelMuhammad Sajedul Karimlaravel-google-client

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/skn036-laravel-google-client/health.svg)

```
[![Health](https://phpackages.com/badges/skn036-laravel-google-client/health.svg)](https://phpackages.com/packages/skn036-laravel-google-client)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

11337.8k1](/packages/neuron-core-neuron-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[lettermint/lettermint-laravel

Official Lettermint driver for Laravel

1190.2k1](/packages/lettermint-lettermint-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
