From bba6e118a182a9ae7edc1864bd840556483cb3ab Mon Sep 17 00:00:00 2001 From: Michael Slowik Date: Wed, 31 May 2023 18:48:48 +0200 Subject: [PATCH] Update README.md --- README.md | 65 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0938837..836bfaa 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,24 @@ -# Firebase Authentication for Laravel +# Laravel Firebase Authentication -Firebase authentication API driver for Laravel/Firevel. +A robust Firebase Authentication API driver for Laravel and Firevel. -## Overview +## Introduction -The driver contains a firebase guard that authenticates user by Firebase Authentication JWT token. To login use [Firebase Authentication](https://firebase.google.com/docs/auth/web/firebaseui). +Laravel Firebase Authentication provides a sophisticated firebase guard for user authentication via the Firebase Authentication JWT token. This allows you to securely authenticate users in your Laravel or Firevel applications, leveraging the power of [Firebase Authentication](https://firebase.google.com/docs/auth/web/firebaseui). -## Installation +## Getting Started + +Follow these steps to get started with Laravel Firebase Authentication. + +### Installation +Begin by installing the package using composer with the command: -### Install the package using composer. ``` composer require firevel/firebase-authentication ``` -### Update `config/auth.php`. +### Standard Configuration +1. **Update `config/auth.php`**: Specify Firebase as the authentication driver for your application. ``` 'guards' => [ 'web' => [ @@ -27,14 +32,12 @@ composer require firevel/firebase-authentication ], ], ``` -### Set firebase project name. -Add `GOOGLE_CLOUD_PROJECT` to your env or `firebase.project_id` config variable. - -### Update your `User` model. -Add `Firevel\FirebaseAuthentication\FirebaseAuthenticable` trait `$incrementing = false` and fillables. +2. **Set Firebase project name**: Configure your firebase project by adding **`GOOGLE_CLOUD_PROJECT`** to your environment variables or set the **`firebase.project_id`** config variable. +3. **Update your `User` model**: Integrate **`Firevel\FirebaseAuthentication\FirebaseAuthenticable`** trait, set **`$incrementing = false`** and define `$fillable`. +Below are examples of how to update your User model for Eloquent and Firequent: -Eloquent example: +Eloquent ``` string('id'); $table->string('name'); @@ -111,11 +113,29 @@ $table->string('picture'); $table->timestamps(); ``` -## Web guard +## Micro-service Configuration + +To avoid sharing users database credentials between micro-services, the recommended configuration differs slightly: + +1. **Update `config/auth.php`**: Specify Firebase as the authentication driver for the 'api' guard. +``` +'guards' => [ + ... + 'api' => [ + 'driver' => 'firebase', + 'provider' => 'users', + ], +], +``` +2. **Update User Provider**: In the **`config/auth.php`** file, define the user provider to use the **`Firevel\FirebaseAuthentication\FirebaseIdentity`** model. + -In order to use firebase authentication in web routes you must attach bearer token to each http request. +## Web Guard Usage + +To utilize firebase authentication within your web routes, it is necessary to attach the bearer token to each HTTP request. + +The bearer token can be stored in the `bearer_token` cookie variable. To do this, add the following to your `Kernel.php`: -You can also store bearer token in `bearer_token` cookie variable and add to your `Kernel.php`: ``` protected $middlewareGroups = [ 'web' => [ @@ -128,8 +148,7 @@ You can also store bearer token in `bearer_token` cookie variable and add to you ]; ``` -If you are using `EncryptCookies` middleware you must set: - +If the EncryptCookies middleware is in use, the following settings must be applied: ``` protected $except = [ ... @@ -137,7 +156,3 @@ If you are using `EncryptCookies` middleware you must set: ... ]; ``` - -## Usage - -Attach to each API call regular bearer token provided by Firebase Authentication.