PHPackages                             learnwithfair/laravel-social-auth - 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. learnwithfair/laravel-social-auth

ActiveLibrary[API Development](/categories/api)

learnwithfair/laravel-social-auth
=================================

One-command Google and Apple social login for Laravel APIs (Android and iOS). Handles dynamic client ID resolution, Sanctum token issuance, and automatic user provisioning.

v1.0.1(today)01↑2900%MITPHPPHP ^8.1

Since Mar 24Pushed todayCompare

[ Source](https://github.com/learnwithfair/laravel-social-auth)[ Packagist](https://packagist.org/packages/learnwithfair/laravel-social-auth)[ Docs](https://github.com/learnwithfair/laravel-social-auth)[ RSS](/packages/learnwithfair-laravel-social-auth/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (8)Versions (3)Used By (0)

Laravel Social Auth
===================

[](#laravel-social-auth)

One-command Google and Apple social login for Laravel mobile APIs.

Supports Android and iOS with separate client IDs per platform, stateless token verification, automatic user provisioning, and Laravel Sanctum token issuance.

---

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

[](#requirements)

- PHP 8.1 or higher
- Laravel 10 or 11
- Laravel Sanctum 3 or 4
- Laravel Socialite 5

---

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

[](#installation)

**Step 1 — Install the package via Composer:**

```
composer require learnwithfair/laravel-social-auth
```

**Step 2 — Run the install command:**

```
php artisan social-auth:install
```

This single command:

- Publishes `config/social-auth.php`
- Publishes `app/Http/Controllers/Api/Auth/SocialAuthController.php`
- Publishes a migration to add the required columns to your `users` table
- Appends the necessary keys to your `.env` file

**Step 3 — Set your credentials in `.env`:**

```
CLIENT_ID_ANDROID=587819760808-xxxx.apps.googleusercontent.com
CLIENT_ID_IOS=587819760808-yyyy.apps.googleusercontent.com
CLIENT_SECRET=
REDIRECT_URI=
```

**Step 4 — Run the migration:**

```
php artisan migrate
```

**Step 5 — Register the SocialiteProviders event listener (Laravel 10 only).**

Laravel 11 and above: this step is not required. SocialiteProviders v5+ registers itself automatically.

Laravel 10 only: open `app/Providers/AppServiceProvider.php` and add the following inside the `boot` method:

```
use SocialiteProviders\Manager\SocialiteWasCalled;
use Illuminate\Support\Facades\Event;

public function boot(): void
{
    Event::listen(function (SocialiteWasCalled $event) {
        $event->extendSocialite('google', \SocialiteProviders\Google\Provider::class);
        $event->extendSocialite('apple',  \SocialiteProviders\Apple\Provider::class);
    });
}
```

---

Route
-----

[](#route)

The package automatically registers the following route:

```
POST /api/social-login

```

Rate limited to 5 requests per minute by default. You can change the route path, prefix, middleware, and disable auto-registration in `config/social-auth.php`.

---

Request Payload
---------------

[](#request-payload)

FieldTypeRequiredValuesDescriptionproviderstringYesgoogle, appleThe social providerprovider\_idstringYes—The ID token from the mobile SDKdevicestringYesandroid, iosThe device type**Example:**

```
{
  "provider": "google",
  "provider_id": "ya29.a0AfH6SMDxxxxxxxx",
  "device": "android"
}
```

---

Response
--------

[](#response)

**Success (200):**

```
{
  "success": true,
  "message": "Login successful.",
  "data": {
    "user": { ... },
    "token": "1|abc123...",
    "token_type": "Bearer"
  }
}
```

**Error (422 — invalid token):**

```
{
  "success": false,
  "message": "Invalid social token or missing email.",
  "data": null
}
```

---

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

[](#configuration)

After publishing, `config/social-auth.php` provides full control:

```
// Disable the auto-registered route and define it manually
'route' => [
    'enabled'    => false,
    ...
],

// Connect your Plan model for automatic free-plan assignment
'plan_model'     => \App\Models\Plan::class,
'free_plan_slug' => 'free',
```

---

Customisation
-------------

[](#customisation)

The published `SocialAuthController` extends the package base controller. Override any method to customise behaviour without losing future package updates:

```
protected function findOrProvisionUser(mixed $socialiteUser, string $provider): User
{
    $user = parent::findOrProvisionUser($socialiteUser, $provider);

    // Add extra logic here, e.g. assign a referral code
    $user->referral_code = Str::upper(Str::random(8));
    $user->save();

    return $user;
}
```

Available override points:

- `findOrProvisionUser` — user creation and update logic
- `downloadAvatar` — avatar download and storage
- `resolvePlanId` — plan assignment
- `generateUniqueUsername` — username generation strategy

---

Disabling the Package Route
---------------------------

[](#disabling-the-package-route)

If you prefer to define the route yourself, set `route.enabled` to `false` in `config/social-auth.php`, then add the route manually in `routes/api.php`:

```
use App\Http\Controllers\Api\Auth\SocialAuthController;

Route::post('/social-login', [SocialAuthController::class, 'socialLogin'])
    ->middleware('throttle:5,1');
```

---

Publish Options
---------------

[](#publish-options)

Publish assets individually using tags:

```
# Config only
php artisan vendor:publish --tag=social-auth-config

# Controller only
php artisan vendor:publish --tag=social-auth-controller

# Migration only
php artisan vendor:publish --tag=social-auth-migrations
```

---

Common Errors
-------------

[](#common-errors)

**`Invalid ID token audience`**

The token was issued for a different client ID. Verify that Android tokens are sent with `device=android` and iOS tokens are sent with `device=ios`.

**`Undefined method stateless()`**

Ensure the SocialiteProviders event listener is registered as described in Step 5 above.

**`Class "SocialiteProviders\Apple\Provider" not found`**

Run `composer require socialiteproviders/apple` if you are using Apple login. The package declares it as a dependency, so this should be resolved automatically by Composer.

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release history.

---

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

---

Author
------

[](#author)

Built by [MD. Rahatul Rabbi](https://github.com/learnwithfair).

###  Health Score

39

—

LowBetter than 87% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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 ~0 days

Total

2

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa6c82f5103019993dbb163c60178a4e52a8aa2eb9f1007920f47066f35fcdf4?d=identicon)[learnwithfair](/maintainers/learnwithfair)

---

Top Contributors

[![learnwithfair](https://avatars.githubusercontent.com/u/103452668?v=4)](https://github.com/learnwithfair "learnwithfair (2 commits)")

---

Tags

apilaravelgooglesocialitefirebasemobilesanctumappleandroidiosSocial Login

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/learnwithfair-laravel-social-auth/health.svg)

```
[![Health](https://phpackages.com/badges/learnwithfair-laravel-social-auth/health.svg)](https://phpackages.com/packages/learnwithfair-laravel-social-auth)
```

###  Alternatives

[marcin-orlowski/laravel-api-response-builder

Helps building nice, normalized and easy to consume Laravel REST API.

838447.9k3](/packages/marcin-orlowski-laravel-api-response-builder)[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3594.0M26](/packages/mollie-laravel-mollie)[aimeos/aimeos-headless

Aimeos headless ecommerce system

2.5k2.3k](/packages/aimeos-aimeos-headless)[rupadana/filament-api-service

A simple api service for supporting filamentphp

20599.6k7](/packages/rupadana-filament-api-service)[chiiya/laravel-passes

Laravel library for creating iOS and Android Wallet Passes

3585.7k](/packages/chiiya-laravel-passes)[mbarwick83/shorty

Google Url Shortener API Package for Laravel 5.1

31204.9k](/packages/mbarwick83-shorty)

PHPackages © 2026

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