Skip to content
Firebase authentication driver for Laravel
PHP
Branch: master
Clone or download
Latest commit 2038a9c Nov 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Merge pull request #5 from firevel/bugfix/save-only-dirty-models Nov 22, 2019
.gitignore initial composer file Jul 11, 2019
LICENSE MIT license Jul 11, 2019
README.md Update README.md Nov 22, 2019
composer.json initial composer file Jul 11, 2019

README.md

Firebase Authentication for Laravel

Firebase authentication API driver for Laravel/Firevel.

Overview

The driver contains a firebase guard that authenticates user by Firebase Authentication JWT token. To login use Firebase Authentication.

Installation

  1. Install the package using composer:
composer require firevel/firebase-authentication
  1. Update config/auth.php.
'guards' => [
    'web' => [
        'driver' => 'firebase',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],
  1. Update your User model with Firevel\FirebaseAuthentication\FirebaseAuthenticable trait $incrementing = false and fillables.

Eloquent example:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, FirebaseAuthenticable;

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'picture'
    ];
}

Firequent example:

<?php

namespace App;

use Firevel\FirebaseAuthentication\FirebaseAuthenticable;
use Firevel\Firequent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Model implements Authenticatable
{
    use Notifiable, FirebaseAuthenticable;

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'picture'
    ];

}

  1. If you are using Eloquent you need to create or update migration for users table manually.
$table->string('id');
$table->string('name');
$table->string('email')->unique();
$table->string('picture');
$table->timestamps();

Web guard

In order to use firebase authentication in web routes you must attach bearer token to each http request.

You can also store bearer token in bearer_token cookie variable and add to your Kernel.php:

    protected $middlewareGroups = [
        'web' => [
            ...
            \Firevel\FirebaseAuthentication\Http\Middleware\AddAccessTokenFromCookie::class,
            ...
        ],

        ...
    ];

If you are using EncryptCookies middleware you must set:

    protected $except = [
        ...
        'bearer_token',
        ...
    ];

Usage

Attach to each API call regular bearer token provided by Firebase Authentication.

You can’t perform that action at this time.