Skip to content

Commit d49b5fb

Browse files
tomykhojeromegamez
authored andcommitted
Support for Database Auth Variable Override
1 parent 2c2289b commit d49b5fb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

config/firebase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@
8686
* https://my-project-id.firebaseio.com
8787
*/
8888
'url' => env('FIREBASE_DATABASE_URL'),
89+
90+
/*
91+
* As a best practice, a service should have access to only the resources it needs.
92+
* To get more fine-grained control over the resources a Firebase app instance can access,
93+
* use a unique identifier in your Security Rules to represent your service.
94+
*
95+
* https://firebase.google.com/docs/database/admin/start#authenticate-with-limited-privileges
96+
*/
97+
// 'auth_variable_override' => [
98+
// 'uid' => 'my-service-worker'
99+
// ],
89100
],
90101

91102
'dynamic_links' => [

src/FirebaseProjectManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ protected function configure(string $name): FirebaseProject
8080
$factory = $factory->withDatabaseUri($databaseUrl);
8181
}
8282

83+
if ($authVariableOverride = $config['database']['auth_variable_override'] ?? null) {
84+
$factory = $factory->withDatabaseAuthVariableOverride($authVariableOverride);
85+
}
86+
8387
if ($defaultStorageBucket = $config['storage']['default_bucket'] ?? null) {
8488
$factory = $factory->withDefaultStorageBucket($defaultStorageBucket);
8589
}

tests/FirebaseProjectManagerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public function the_realtime_database_url_can_be_configured(): void
221221
{
222222
$projectName = $this->app->config->get('firebase.default');
223223
$this->app->config->set('firebase.projects.'.$projectName.'.database.url', $url = 'https://domain.tld');
224+
$this->app->config->set('firebase.projects.'.$projectName.'.database.auth_variable_override', ['uid' => 'some-uid']);
224225

225226
$database = $this->app->make(Firebase\Database::class);
226227

0 commit comments

Comments
 (0)