PHPackages                             firevel/firebase-authentication - 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. firevel/firebase-authentication

ActiveLibrary

firevel/firebase-authentication
===============================

Firebase authentication driver for Laravel

2.1.0(2mo ago)2223.6k↓47.9%9[1 PRs](https://github.com/firevel/firebase-authentication/pulls)1MITPHP

Since Jul 12Pushed 2mo agoCompare

[ Source](https://github.com/firevel/firebase-authentication)[ Packagist](https://packagist.org/packages/firevel/firebase-authentication)[ RSS](/packages/firevel-firebase-authentication/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (1)

Laravel Firebase Authentication
===============================

[](#laravel-firebase-authentication)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Latest Stable Version](https://camo.githubusercontent.com/496b5ab21bed93b9cee91bddca1a3ba3455417024fdaffbe2dfeb3cd7f3d8ec6/68747470733a2f2f706f7365722e707567782e6f72672f6669726576656c2f66697265626173652d61757468656e7469636174696f6e2f762f737461626c65)](https://packagist.org/packages/firevel/firebase-authentication)

A production-ready Firebase Authentication driver for Laravel that enables seamless JWT-based authentication using Firebase tokens.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
    - [Standard Setup (with Database)](#standard-setup-with-database)
    - [Microservice Setup (without Database)](#microservice-setup-without-database)
    - [Multiple Guards](#multiple-guards)
    - [Web Guard Configuration](#web-guard-configuration)
- [Usage](#usage)
    - [Basic Authentication](#basic-authentication)
    - [Anonymous Users](#anonymous-users)
    - [Accessing JWT Claims](#accessing-jwt-claims)
    - [Working with Firebase Tokens](#working-with-firebase-tokens)
- [API Reference](#api-reference)
- [Common Use Cases](#common-use-cases)
- [Security Considerations](#security-considerations)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- **JWT Token Verification**: Securely verify Firebase Authentication JWT tokens
- **Automatic User Sync**: Automatically create/update users from Firebase claims
- **Anonymous Authentication**: Built-in support for Firebase anonymous users
- **Microservice Ready**: Stateless authentication without database dependency
- **Web &amp; API Guards**: Support for both session-based and API authentication
- **Token Caching**: Optimized token verification with built-in caching
- **Laravel Integration**: Native integration with Laravel's authentication system
- **Flexible User Models**: Works with Eloquent, or custom models

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

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.x, 10.x, 11.x, 12.x
- Firebase project with Authentication enabled

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

[](#installation)

Install the package via Composer:

```
composer require firevel/firebase-authentication
```

The package will automatically register its service provider.

Quick Start
-----------

[](#quick-start)

For a quick setup with API authentication:

1. **Set your Firebase project ID** in `.env`:

```
GOOGLE_CLOUD_PROJECT=your-firebase-project-id
```

2. **Configure auth guard** in `config/auth.php`:

```
'guards' => [
    'api' => [
        'driver' => 'firebase',
        'provider' => 'users',
    ],
],
```

3. **Add trait to your User model**:

```
use Firevel\FirebaseAuthentication\FirebaseAuthenticable;

class User extends Authenticatable
{
    use FirebaseAuthenticable;

    public $incrementing = false;
    protected $fillable = ['name', 'email', 'picture'];

    // Optional: Customize how users are matched (default: ['sub' => 'id'])
    protected $firebaseResolveBy = 'email'; // use 'email' to automatically create or find user by email

    // Optional: Customize which Firebase claims map to which user attributes
    protected $firebaseClaimsMapping = [
        'email' => 'email',
        'name' => 'name',
    ];
}
```

4. **Protect your routes**:

```
Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
```

That's it! Send requests with `Authorization: Bearer {firebase-jwt-token}` header.

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

[](#configuration)

### Standard Setup (with Database)

[](#standard-setup-with-database)

This setup stores user data in your database and syncs it with Firebase claims.

#### 1. Environment Configuration

[](#1-environment-configuration)

Add your Firebase project ID to `.env`:

```
GOOGLE_CLOUD_PROJECT=your-firebase-project-id
```

Alternatively, publish and configure the firebase config:

```
// config/firebase.php
return [
    'project_id' => env('FIREBASE_PROJECT_ID', 'your-project-id'),
];
```

#### 2. Update Authentication Configuration

[](#2-update-authentication-configuration)

Modify `config/auth.php` to use the Firebase driver:

```
'guards' => [
    'web' => [
        'driver' => 'firebase',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'firebase',
        'provider' => 'users',
    ],
],
```

#### 3. Update Your User Model

[](#3-update-your-user-model)

Add the `FirebaseAuthenticable` trait to your User model:

**Eloquent Example:**

```
