PHPackages                             square1/laravel-passport-firebase-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. square1/laravel-passport-firebase-auth

ActiveLibrary

square1/laravel-passport-firebase-auth
======================================

Create and authenticate users with Firebase Auth providers, and let Laravel Passport handle the rest!

3.1.0(5y ago)172.4k14MITPHPPHP ^7.3

Since Sep 8Pushed 2y ago9 watchersCompare

[ Source](https://github.com/square1-io/laravel-passport-firebase-auth)[ Packagist](https://packagist.org/packages/square1/laravel-passport-firebase-auth)[ Docs](https://github.com/square1-io/laravel-passport-firebase-auth)[ RSS](/packages/square1-laravel-passport-firebase-auth/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (9)Versions (11)Used By (0)

Let Google Firebase create and authenticate users to your Laravel API (using Laravel Passport)
==============================================================================================

[](#let-google-firebase-create-and-authenticate-users-to-your-laravel-api-using-laravel-passport)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b2d23fec76d0f04115cb1fa559d9ea431921750c3395549ae43958a045fb0592/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737175617265312f6c61726176656c2d70617373706f72742d66697265626173652d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/square1/laravel-passport-firebase-auth)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://github.com/square1-io/laravel-passport-firebase-auth/workflows/Tests/badge.svg?style=flat-square)](https://github.com/square1-io/laravel-passport-firebase-auth/actions?query=workflow%3ATests+branch%3Amaster)

Create and authenticate users with Firebase Auth providers (Google, Facebook, Apple, email, etc), and let Laravel Passport know and handle your backend secure endpoints!

This is an opinionated way to create Laravel Passport tokens from a Firebase valid token.

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

[](#installation)

You can install the package via composer:

```
composer require square1/laravel-passport-firebase-auth
```

You will need a `firebase_uid` column on your users table. You can publish and run the migrations and customize that column with:

```
php artisan vendor:publish --provider="Square1\LaravelPassportFirebaseAuth\LaravelPassportFirebaseAuthServiceProvider" --tag="migrations"

# after column customization run:
php artisan migrate
```

Publish the config file with:

```
php artisan vendor:publish --provider="Square1\LaravelPassportFirebaseAuth\LaravelPassportFirebaseAuthServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
return [
    /**
     * We will load all the package routes under your api prefix for consistency
     */
    'api_prefix' => env('API_PREFIX', 'api/v1'),

    /**
     * Declare the amount of minutes in the future. Laravel Passport will create a token that endures
     * that long. See: https://laravel.com/docs/7.x/passport#token-lifetimes
     */
    'token_expiration_in_minutes' => 60 * 24 * 7, // Default 1 week expiration

    /**
     * Please update the column names in the array (the values) to match your users database columns.
     * Remove all the key pairs you don't need to store, but leave 'uid' and 'email', we need them!
     * For the 'uid' create a nullable string (we'll do this if use this package migrations)
     * Of course, make all columns fillable in your User model
     * or we can't save them if those columns are protected.
     */
    'map_user_columns' => [
        'uid' => 'firebase_uid', // REQUIRED
        'email' => 'email', // REQUIRED
        'displayName' => 'name',
        'emailVerified' => 'email_verified_at',
        'phoneNumber' => 'phone',
        'photoURL' => 'avatar',
        'provider' => 'provider' // e.g facebook, google, password
    ],

    /**
     * Define a set of columns to add to `user` key in returned payload
     */
    'expose_user_columns' => [
        'id',
        // 'username',
        // 'role',
    ],

    /**
     * If you need some mandatory columns in order to store your laravel user model,
     * you can indicate them in here along with the validation rules you need.
     * Of course, you will need to post this keys as indicated in the readme.
     * And of course, make all columns fillable in your User model,
     * or we can't save them if those columns are protected.
     */
    'extra_user_columns' => [
        // 'username' => 'required|unique:users|max:255',
        // 'birthday' => 'require|date|before:today|date_format:Y-m-d'
    ],

    /**
     * Please indicate if anonymous firebase users capability is alowed in your application.
     * If so, we will need to olso create an "anonymous" user in your database in order
     * to let Laravel Passport issue a token for that particular user.
     */
    'allow_anonymous_users' => false,

    /**
     * Indicate the mandatory fields for anonymous user creation in your laravel database.
     * For the email, we'll concatenate (prefix) with the UID from firebase.
     */
    'anonymous_columns' => [
        'email' => '@anonymous.com', // This will end up being firebasetoken@anonymous.com
        'name' => 'Anonymous',
        'anonymous' => true,
        // 'avatar' => 'sample_anonymous_avatar.png'
    ]
];
```

### Configure Laravel Passport

[](#configure-laravel-passport)

This package has Laravel Passport as a dependency, if you did not already, please [configure Laravel Passport](https://laravel.com/docs/7.x/passport).

### Configure Firebase

[](#configure-firebase)

Create a Firebase project in the console .

If you did not already please generated your Service Account auth file, do it from this url: [https://console.firebase.google.com/project/\_/settings/serviceaccounts/adminsdk](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk). You will be asked to select the Firebase Project. After that, the Firebase Admin SDK screen will ask you to pick a language, just leave `Node.js` selected and click `Generate new private key`.

Once you have downloaded the Service Account JSON file in your project (**ATENTION! please git ignore this file** as it has sensible credentials), indicate the path to your file in `.env` like this:

```
FIREBASE_CREDENTIALS=storage/firebase_credentials.json

```

#### Configure auth providers

[](#configure-auth-providers)

In your firebase project create and configure all providers you want to use:

Usage
-----

[](#usage)

This package will expose 2 endpoints under your api prefix (configurable):

1. **POST**: `api/v1/firebase/user/create`

In your mobile app or front end, you will allow your users to create an account using the [Firebase client SDK of your choice](https://firebase.google.com/docs/firestore/client/libraries).

Then you will call this endpoint with a valid firebase token using the `firebase_token` key in the payload posted.

This endpoint will reach firebase database, find and validate the user just created in your front end / mobile app, and it will create a user record in your laravel database saving the `firebase_uid` in users table you populated previously in the installation step.

Optionaly, you can perform 2 extra user configuration steps here:

**1 - a) Conect extra user data from the firebase users payload:**

In your config/laravel-passport-firebase-auth.php indicate the keys you want to match against your laravel users table using the "map\_user\_columns" key in the array.

**1 - b) Pass any other custom data you need for the user creation proces in your laravel database:**

An example will be if user creation require some mandatory columns (e.g. user\_plan, username, role, etc.). For this you will use the instructions on the "extra\_user\_columns" key in the config array.

For security reasons, we'll validate this data, and we'll ignore any other values not declared in this "extra\_user\_columns" array.

---

Example payload posted to `api/v1/firebase/user/create`:

```
{
    "firebase_token": "super_long_firebase_token_here",
    "username": "tonystark",
    "plan": "platinum",
    "role": "superadmin"
}
```

if in your `config/laravel-passport-firebase-auth.php` file you have the followin configuration:

```
    'map_user_columns' => [
        'uid' => 'firebase_uid',
        'email' => 'email',
        'displayName' => 'full_name',
        'photoURL' => 'avatar',
    ],
    'extra_user_columns' => [
        'username' => 'required|unique:users|max:255',
        'plan' => 'required|in:silver,gold,platinum'
    ]
```

The result will be that, the newly created firebase user will be stored in your database with the uid, email, displayName as the full\_name column, photoURL as the avatar column, and the rest of the firebase metadata will be discarted.

Also the username and plan will be stored, but the `role` manipulation attempt will be ignored.

You will receive a `success` status from the endpoint, along with the backend user ID and valid Laravel Passport access token.

```
{
    "status": "success",
    "data": {
        "access_token": "valid_laravel_passport_token",
        "token_type": "Bearer",
        "expires_at": "2020-09-14T23:16:35.000000Z",
        "user": {
            "id": 1
        }
    }
}
```

2. **POST**: `api/v1/firebase/user/login`

You will need to call this endpoint with only a valid firebase token using the key `firebase_token` in the payload posted.

In case we find the user in the laravel database, the result will contain a `success` status along with the passport token to use in furter requests.

```
{
    "status": "success",
    "data": {
        "access_token": "valid_laravel_passport_token",
        "token_type": "Bearer",
        "expires_at": "2020-09-14T23:17:02.000000Z",
        "user": {
            "id": 1
        }
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Emiliano Tisato](https://github.com/emilianotisato)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~45 days

Total

10

Last Release

1888d ago

Major Versions

0.5 → 1.0.02020-09-09

1.0.0 → 2.0.02020-09-09

2.2.1 → 3.1.02021-03-11

PHP version history (2 changes)0.5PHP ^7.4

2.2.1PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a6096b0455d662c5963ed82e1f0968bc4a18bdfedd332f7fd2598480b4c17bd?d=identicon)[conroyp](/maintainers/conroyp)

---

Top Contributors

[![emilianotisato](https://avatars.githubusercontent.com/u/18596215?v=4)](https://github.com/emilianotisato "emilianotisato (48 commits)")[![Benjacho](https://avatars.githubusercontent.com/u/11976865?v=4)](https://github.com/Benjacho "Benjacho (2 commits)")[![juanmanavarro](https://avatars.githubusercontent.com/u/1380040?v=4)](https://github.com/juanmanavarro "juanmanavarro (1 commits)")

---

Tags

google-firebaseFirebase AuthFirebase FCM laravellaravel-passport-firebase-auth

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/square1-laravel-passport-firebase-auth/health.svg)

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

###  Alternatives

[laravel-notification-channels/fcm

FCM (Firebase Cloud Messaging) Notifications Driver for Laravel

5917.0M16](/packages/laravel-notification-channels-fcm)[corbosman/laravel-passport-claims

Add claims to Laravel Passport JWT Tokens

88655.9k](/packages/corbosman-laravel-passport-claims)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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