PHPackages                             websitinu/laravel-socialite-google-one-tap - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. websitinu/laravel-socialite-google-one-tap

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

websitinu/laravel-socialite-google-one-tap
==========================================

A very light package to install Google One Tap Login on your Laravel web application that you have already installed Socialite

2.5(7mo ago)42.0kMITPHPPHP ^8.2

Since May 17Pushed 3w ago1 watchersCompare

[ Source](https://github.com/Websitinu/laravel-socialite-google-one-tap)[ Packagist](https://packagist.org/packages/websitinu/laravel-socialite-google-one-tap)[ RSS](/packages/websitinu-laravel-socialite-google-one-tap/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (5)Versions (9)Used By (0)

[![Laravel Socialite Google One Tap](https://raw.githubusercontent.com/EhsanGhafoori/laravel-socialite-google-one-tap/main/img/laravel-socialite-google-one-tap.png)](https://github.com/EhsanGhafoori/laravel-socialite-google-one-tap)

A lightweight package to integrate Google One Tap with Laravel Socialite.
=========================================================================

[](#a-lightweight-package-to-integrate-google-one-tap-with-laravel-socialite)

[![Build Status](https://raw.githubusercontent.com/EhsanGhafoori/laravel-socialite-google-one-tap/main/img/test/badge.svg)](https://github.com/EhsanGhafoori/laravel-socialite-google-one-tap)[![Total Downloads](https://camo.githubusercontent.com/6e8df4d24bb5ab476995c227891c7a13eaafe04f185be9c0defc72b03a274d6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776562736974696e752f6c61726176656c2d736f6369616c6974652d676f6f676c652d6f6e652d746170)](https://packagist.org/packages/websitinu/laravel-socialite-google-one-tap)[![Latest Stable Version](https://camo.githubusercontent.com/90b696d4717fcedda61fea41cc020238856d8d13b5ec7fa543dedce313408873/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776562736974696e752f6c61726176656c2d736f6369616c6974652d676f6f676c652d6f6e652d746170)](https://packagist.org/packages/websitinu/laravel-socialite-google-one-tap)[![License](https://camo.githubusercontent.com/e65afbaf1e14eae8f6e9926812c7ce9c1e55ed1c35ddfc85c44061e15f38f21e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776562736974696e752f6c61726176656c2d736f6369616c6974652d676f6f676c652d6f6e652d746170)](https://packagist.org/packages/websitinu/laravel-socialite-google-one-tap)

Requirements
------------

[](#requirements)

- **PHP** 8.2+ (PHP 8.3+ required when using **Laravel 13**)
- **Laravel** 11, 12, or 13
- **Laravel Socialite** ^5.0

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

[](#installation)

To install this package, run the following composer command:

```
composer require websitinu/laravel-socialite-google-one-tap
```

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

[](#configuration)

### Step 1: Create a Google Project

[](#step-1-create-a-google-project)

1.Go to the [Google Cloud console](https://console.cloud.google.com/apis/credentials/consent).

2.If you haven't already, create a new project by clicking on Select a Project in the top header and then New Project. Follow the steps to create a project.

3.Once your project is created, you'll need to set up OAuth consent screen and OAuth 2.0 credentials.

### For Use Google One Tap

[](#for-use-google-one-tap)

1. **Set up Google OAuth credentials:**

    - In your **Google Cloud Console**, go to the **Credentials** tab on the left sidebar.
    - Click on **Create Credentials** and choose **OAuth Client ID**.

    1.1 **Configure the OAuth consent screen:**

    - Fill out the necessary fields like **App name**, **User support email**, etc.
    - For **Scopes**, you can keep the default or add specific scopes if needed.

    1.2 **Under Application type**, select **Web application**.

    1.3 **In the Authorized JavaScript origins**, add the URLs where your app will be hosted (e.g., `http://localhost` for local development).

### Authorized JavaScript origins exampls for local development

[](#authorized-javascript-origins-exampls-for-local-development)

For use with requests from a browser on local host

```
URIs 1
http://localhost:8000
URIs 2
http://localhost

```

### you can reaplace it just with your real domain .

[](#you-can-reaplace-it-just-with-your-real-domain-)

1.4 **In the Authorized redirect URIs**, add the URL that your app will redirect to after the user logs in. For example, `/google-one-tap` (this is set in your `.env` file).

### Authorized redirect URIs

[](#authorized-redirect-uris)

For use with requests from a web server

```
URIs 1
http://localhost:8000/auth/google/onetap
```

#### or you can reaplace with your own route address

[](#or-you-can-reaplace-with-your-own-route-address)

3. **Get the credentials:**After configuring OAuth credentials, you will receive a **Client ID** and **Client Secret**. Add these credentials to your `.env` file as follows:

    ```
    # .env
    GOOGLE_ONE_TAP_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID
    GOOGLE_ONE_TAP_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET
    GOOGLE_ONE_TAP_LOGIN_URI=http://localhost:8000/auth/google/onetap
    ```

### For Users Who Want to Use Google One Tap with Regular Google Login

[](#for-users-who-want-to-use-google-one-tap-with-regular-google-login)

If you want to integrate **Google One Tap** alongside the traditional **Google login**, you'll need to follow these additional steps:

1. **Set up Google OAuth credentials for regular Google login:**

    - In the same **Credentials** tab, create another **OAuth Client ID** for regular Google login:

    1.1 **Configure the OAuth consent screen:**

    - Fill out the necessary fields like **App name**, **User support email**, etc.
    - For **Scopes**, you can keep the default or add specific scopes if needed.

    1.2 **Under Application type**, select **Web application**.

    1.3 **In the Authorized JavaScript origins**, nothing to add and leave empty.

    1.4 **In the Authorized redirect URIs**, Follow the same steps as for Google One Tap but configure the **Authorized redirect URIs** differently. For Google login, this URI is typically something like `http://localhost:8000/auth/google/callback`

### Authorized redirect URIs

[](#authorized-redirect-uris-1)

For use with requests from a web server

```
URIs 1
http://localhost:8000/auth/google/callback
```

#### you can reaplace with your own route address

[](#you-can-reaplace-with-your-own-route-address)

3. **Add credentials to `.env` file:**In addition to the credentials for **Google One Tap**, add the credentials for the **regular Google login**:

```
# .env

# Google One Tap credentials
GOOGLE_ONE_TAP_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID_ONE_TAP
GOOGLE_ONE_TAP_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET_ONE_TAP
GOOGLE_ONE_TAP_LOGIN_URI=http://localhost:8000/auth/google/onetap

# Regular Google login credentials
GOOGLE_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET
GOOGLE_REDIRECT_URL=http://localhost:8000/auth/google/callback
```

```
# config/services.php

return [

    'laravel-google-one-tap' => [
        'client_id' => env('GOOGLE_ONE_TAP_CLIENT_ID'),
        'client_secret' => env('GOOGLE_ONE_TAP_CLIENT_SECRET'),
        'redirect' => env('GOOGLE_ONE_TAP_LOGIN_URI'),
    ],

    // other providers

   'google' => [
        'client_id' => env('GOOGLE_CLIENT_ID'),
        'client_secret' => env('GOOGLE_CLIENT_SECRET'),
        'redirect' => env('GOOGLE_REDIRECT_URL'),
    ],

    'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect' => env('GITHUB_REDIRECT_URI'),
    ],
];
```

### Add provider event listener

[](#add-provider-event-listener)

Configure the package's listener to listen for `SocialiteWasCalled` events. Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

### [\#](#for-example-in-laravel-11) For example in Laravel 11, 12, and 13

[](#-for-example-in-laravel-11-12-and-13)

In `app/providers/AppServiceProvider.php`.

```
namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use LaravelSocialite\GoogleOneTap\LaravelGoogleOneTapServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
            $event->extendSocialite('laravel-google-one-tap', LaravelGoogleOneTapServiceProvider::class);
        });
    }
}
```

### [\#](#for-example-in-laravel-10-or-below) For example in Laravel 10 or below

[](#-for-example-in-laravel-10-or-below)

In `app/providers/AppServiceProvider.php`.

```
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use LaravelSocialite\GoogleOneTap\GoogleOneTapSocialiteExtend;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        \SocialiteProviders\Manager\SocialiteWasCalled::class => [
            // other providers
            GoogleOneTapSocialiteExtend::class . '@handle',
        ],
    ];
}
```

Usage front-end
---------------

[](#usage-front-end)

Google One Tap requires a specific implementation both in the front-end as the back-end.

### Front-end

[](#front-end)

On any page where you wish to use Google One Tap, you need to add the following script to the header of your HTML templates.

```
@guest

@endguest
```

The Google One Tap prompt itself can be triggered using either JavaScript or HTML. The following code processes the response server-side in HTML. It doesn't matter where you place this code, and you can also append `data-client_id` and `data-login_uri` to any existing HTML element. For more settings and variations, such as a complete JavaScript implementation, check the [references](#references).

```
@guest

@endguest
```

Styling this element won't affect the appearance, as Google One Tap is transitioning to [FedCM](https://developer.chrome.com/en/docs/privacy-sandbox/fedcm/), meaning the prompt will be handled by the browser if it supports it.

To sign out, add a `g_id_signout` class to your sign-out button to prevent a redirection loop due to `data-auto_select` in the previous code.

```

  @csrf
  Sign out

```

Google One Tap has a cooldown period after a user dismisses the prompt. The more frequently a user closes the prompt, the longer it will take for the prompt to reappear. Therefore, include a sign-in button as a fallback to trigger the Google Sign-In prompt. Typically, you'll want to add this button on login and registration pages. The [Only](https://developers.google.com/identity/gsi/web/reference/html-reference#button-attribute-types) required field is `data-type`.

```

```

### Back-end

[](#back-end)

```
// routes/web.php

#if you want use only google one tap

use App\Controllers\GoogleOneTapController;
use Illuminate\Support\Facades\Route;

Route::post('auth/google/onetap', [GoogleOneTapController::class, 'handler'])
    ->middleware('guest')
    ->name('google-one-tap.handler');

----------------- or ------------------
#if you want use with any provider

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\AuthController;

Route::controller(AuthController::class)->prefix('auth')->group(function () {
    Route::get('{provider}', 'redirectToProvider')->name('provider.auth');
    Route::get('{provider}/callback', 'callbackToProvider');
    Route::post('google/onetap', 'googleOneTap')->middleware('guest')->name('google-one-tap.handler');
});
```

Google One Tap is built on top of OAuth, but it operates differently by using an authenticating JWT token instead of access and refresh tokens. The redirect() and refreshToken() methods will not be utilized in this context and will throw an Error as a reminder.

Your controller will not need to redirect the user, and instead of resolving the user, you can immediately resolve the token.

```
use Laravel\Socialite\Facades\Socialite;

return Socialite::driver('laravel-google-one-tap')->userFromToken($token);
```

This function will either return the decoded payload of the JWT token or throw an `Error` if the token provided is invalid.

#### Payload Structure

[](#payload-structure)

FieldTypeDescriptionidstringUnique identifier for the user from GooglenamestringFull name of the useremailstringUser’s email addressavatar?stringProfile picture of the user (if available)nick namestringUser’s family name (if provided)email\_verifiedbooleanIndicates whether Google has verified the email#### Handling the Payload

[](#handling-the-payload)

Once you retrieve the payload, which includes the user's `email`, you can determine the next steps in the authentication process. If the email is already in your database, proceed with logging the user in. Otherwise, you may need to register a new user using the provided details.

```
// GoogleOneTapController.php

use App\Models\User;
use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use LaravelSocialite\GoogleOneTap\InvalidIdToEx;

public function handler(Request $request)
{
    // Verify and validate JWT received from Google One Tap prompt
    try {
        $googleUser = Socialite::driver('laravel-google-one-tap')->userFromToken($request->input('credential'));
    } catch (InvalidIdToEx $exception) {
        return response()->json(['error' => $exception]);
    }

    // Log the user in if the email is associated with a user

    try {
        $googleUser = User::where('email', $googleUser['email'])->firstOrfail();
    } catch (\Exception $ex) {

        $user = User::create([
                'name' => $googleUser->getName(),
                'lastName' => $googleUser->getNickName(),
                'provider_name' => 'google-one-tap',
                'email' => $googleUser->getEmail(),
                'password' => Hash::make($googleUser->getId()),
                'email_verified_at' =>  $googleUser->user['email_verified'] ? now() : null,
                'profile_photo_path' => $googleUser->getAvatar()
        ]);

        Auth::login($user, $remember = true);
        return redirect()->route('home');
    }

    Auth::login($googleUser, $remember = true);
    // Send user to Home
    return redirect()->route('home');

}
```

OR if you want use with any provider
====================================

[](#or-if-you-want-use-with-any-provider)

```
// AuthController.php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User\User;
use App\Models\User\UserProviderProfile;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Laravel\Socialite\Facades\Socialite;

class AuthController extends Controller
{
    public function redirectToProvider($provider)
    {
        return Socialite::driver($provider)->redirect();
    }

    public function callbackToProvider($provider)
    {
        try {
            $socialiteUser = Socialite::driver($provider)->user();
        } catch (\Exception $ex) {
            Log::error("Social login error: " . $ex->getMessage());
            return redirect()->route('login')->with('error', 'An error occurred while logging in.');
        }

        // Check if the user already exists
        $user = User::where('email', $socialiteUser->getEmail())->first();

        if (!$user) {
            // Create a new user only if they don't exist
            $user = User::create([
                'name' => $socialiteUser->getName(),
                'provider_name' => $provider,
                'email' => $socialiteUser->getEmail(),
                'password' => Hash::make($socialiteUser->getId()), // Not used but required
                'email_verified_at' => now(),
                'profile_photo_path' => $socialiteUser->getAvatar(),
            ]);

        }

        // Log the user in without updating their data
        Auth::login($user, true);

        return redirect()->route('home');
    }

    public function googleOneTap(Request $request)
    {
        try {
            $googleUser = Socialite::driver('laravel-google-one-tap')->userFromToken($request->input('credential'));
        } catch (\Exception $exception) {
            Log::error("Google One Tap Login Failed: " . $exception->getMessage());
            return response()->json(['error' => 'Google authentication failed'], 400);
        }

        // Find existing user or create a new one
        $user = User::firstOrNew(['email' => $googleUser->getEmail()]);

        if (!$user->exists) {
            $user->name = $googleUser->getName();
            $user->provider_name = 'google';
            $user->password = Hash::make($googleUser->getId()); // Not used, but required
            $user->email_verified_at = now();
            $user->profile_photo_path = $googleUser->getAvatar();
            $user->save(); // Store user data before using user_id
        }

        // Ensure user_id exists
        if (!$user->id) {
            Log::error("Google One Tap Error: user_id is null for email: " . ($googleUser->getEmail() ?? 'unknown'));
            return response()->json(['error' => 'User not found or not created'], 400);
        }

        // Log in the user
        Auth::login($user, true);

        return redirect()->route('home');
    }

}
```

sample of buttons

```

        Continue with Google

        Continue with GitHub

```

References
----------

[](#references)

- [Google Identity Services Overview](https://developers.google.com/identity/gsi/web/guides/overview)
- [Google Identity HTML Reference](https://developers.google.com/identity/gsi/web/reference/html-reference)
- [Google Identity JavaScript Reference](https://developers.google.com/identity/gsi/web/reference/js-reference)
- [Google API PHP Client](https://github.com/googleapis/google-api-php-client)
- [Google API PHP Client Docs](https://googleapis.github.io/google-api-php-client/main/)
- [Laravel Socialite Documentation](https://laravel.com/docs/socialite)
- [Google OAuth 2.0 for Web](https://developers.google.com/identity/protocols/oauth2/web-server)

License
-------

[](#license)

This package is licensed under the MIT License (MIT). See the [LICENSE](LICENSE.md) for more details.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance81

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.8% 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 ~91 days

Recently: every ~61 days

Total

7

Last Release

225d ago

Major Versions

v1.1.0 → v2.12025-03-14

PHP version history (2 changes)1.0.0PHP ^8.0

v2.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/92622184124f52f78a99c52528a741b463be391e0cddb7524861f3cbe78c9814?d=identicon)[websitinu](/maintainers/websitinu)

---

Top Contributors

[![Websitinu](https://avatars.githubusercontent.com/u/170080127?v=4)](https://github.com/Websitinu "Websitinu (27 commits)")[![EhsanGhafoori](https://avatars.githubusercontent.com/u/118250253?v=4)](https://github.com/EhsanGhafoori "EhsanGhafoori (16 commits)")

---

Tags

laravelsocialiteGoogle One Tapwebsitinulogin with googlebox register google in top

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/websitinu-laravel-socialite-google-one-tap/health.svg)

```
[![Health](https://phpackages.com/badges/websitinu-laravel-socialite-google-one-tap/health.svg)](https://phpackages.com/packages/websitinu-laravel-socialite-google-one-tap)
```

###  Alternatives

[socialiteproviders/apple

Apple OAuth2 Provider for Laravel Socialite

599.1M13](/packages/socialiteproviders-apple)[socialiteproviders/microsoft

Microsoft OAuth2 Provider for Laravel Socialite

346.9M19](/packages/socialiteproviders-microsoft)[socialiteproviders/instagram

Instagram OAuth2 Provider for Laravel Socialite

401.9M5](/packages/socialiteproviders-instagram)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

24110.5k](/packages/kovah-laravel-socialite-oidc)

PHPackages © 2026

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