From 7157154eeb426130a51639392a405981fed94763 Mon Sep 17 00:00:00 2001 From: Nick Haynes Date: Wed, 29 Mar 2023 20:22:57 -0500 Subject: [PATCH 1/3] feat(app-check): added app-check to the ServiceProvider --- README.md | 1 + src/FirebaseProject.php | 11 +++++++++++ src/ServiceProvider.php | 3 +++ tests/ServiceProviderTest.php | 1 + 4 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 1d95a38..0b4b345 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" | Component | [Container Injection](https://laravel.com/docs/container#automatic-injection) | [Facades](https://laravel.com/docs/facades) | [`app()`](https://laravel.com/docs/helpers#method-app) | |-------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|---------------------------------------------|--------------------------------------------------------| +| [AppCheck](https://firebase-php.readthedocs.io/en/stable/app-check.html) | `\Kreait\Firebase\Contract\AppCheck` | `Firebase::appCheck()` | `app('firebase.app_check')` | | [Authentication](https://firebase-php.readthedocs.io/en/stable/authentication.html) | `\Kreait\Firebase\Contract\Auth` | `Firebase::auth()` | `app('firebase.auth')` | | [Cloud Firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html) | `\Kreait\Firebase\Contract\Firestore` | `Firebase::firestore()` | `app('firebase.firestore')` | | [Cloud Messaging (FCM)](https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html) | `\Kreait\Firebase\Contract\Messaging` | `Firebase::messaging()` | `app('firebase.messaging')` | diff --git a/src/FirebaseProject.php b/src/FirebaseProject.php index b7c21a9..56d80a1 100644 --- a/src/FirebaseProject.php +++ b/src/FirebaseProject.php @@ -4,6 +4,7 @@ namespace Kreait\Laravel\Firebase; +use Kreait\Firebase\Contract\AppCheck; use Kreait\Firebase\Contract\Auth; use Kreait\Firebase\Contract\Database; use Kreait\Firebase\Contract\DynamicLinks; @@ -19,6 +20,7 @@ class FirebaseProject protected array $config; + protected ?AppCheck $appCheck = null; protected ?Auth $auth = null; protected ?Database $database = null; protected ?DynamicLinks $dynamicLinks = null; @@ -33,6 +35,15 @@ public function __construct(Factory $factory, array $config) $this->config = $config; } + public function appCheck(): AppCheck + { + if (!$this->appCheck) { + $this->appCheck = $this->factory->createAppCheck(); + } + + return $this->appCheck; + } + public function auth(): Auth { if (!$this->auth) { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 714ca65..a8b4450 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -32,6 +32,9 @@ public function register(): void private function registerComponents(): void { + $this->app->singleton(Firebase\Contract\AppCheck::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->appcheck()); + $this->app->alias(Firebase\Contract\AppCheck::class, 'firebase.app_check'); + $this->app->singleton(Firebase\Contract\Auth::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->auth()); $this->app->alias(Firebase\Contract\Auth::class, 'firebase.auth'); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index b42ef3b..a47b2ef 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -18,6 +18,7 @@ public function it_provides_components(): void { $this->app->config->set('firebase.projects.app.credentials.file', \realpath(__DIR__ . '/_fixtures/service_account.json')); + $this->assertInstanceOf(Firebase\Contract\AppCheck::class, $this->app->make(Firebase\Contract\AppCheck::class)); $this->assertInstanceOf(Firebase\Contract\Auth::class, $this->app->make(Firebase\Contract\Auth::class)); $this->assertInstanceOf(Firebase\Contract\Database::class, $this->app->make(Firebase\Contract\Database::class)); $this->assertInstanceOf(Firebase\Contract\DynamicLinks::class, $this->app->make(Firebase\Contract\DynamicLinks::class)); From 41f205388c2d6b1735c2a74b8841b49855eb0608 Mon Sep 17 00:00:00 2001 From: Nick Haynes Date: Wed, 29 Mar 2023 20:26:38 -0500 Subject: [PATCH 2/3] feat(app-check): added app-check to the Facade --- src/Facades/Firebase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Facades/Firebase.php b/src/Facades/Firebase.php index 5f34496..92fa6de 100644 --- a/src/Facades/Firebase.php +++ b/src/Facades/Firebase.php @@ -10,6 +10,7 @@ * @method static \Kreait\Laravel\Firebase\FirebaseProject project(string $name = null) * @method static string getDefaultProject() * @method static void setDefaultProject(string $name) + * @method static \Kreait\Firebase\Contract\AppCheck appCheck() * @method static \Kreait\Firebase\Contract\Auth auth() * @method static \Kreait\Firebase\Contract\Database database() * @method static \Kreait\Firebase\Contract\DynamicLinks dynamicLinks() From 162b3a5fbbd8def1bec1062e176d5249758ef0e6 Mon Sep 17 00:00:00 2001 From: Nick Haynes Date: Wed, 29 Mar 2023 21:18:50 -0500 Subject: [PATCH 3/3] fix(app-check): corrected the name of the underlying method --- src/ServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index a8b4450..a53fe12 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -32,7 +32,7 @@ public function register(): void private function registerComponents(): void { - $this->app->singleton(Firebase\Contract\AppCheck::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->appcheck()); + $this->app->singleton(Firebase\Contract\AppCheck::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->appCheck()); $this->app->alias(Firebase\Contract\AppCheck::class, 'firebase.app_check'); $this->app->singleton(Firebase\Contract\Auth::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->auth());