Skip to content

Commit

Permalink
tenant id support
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0wik authored and jeromegamez committed Feb 2, 2021
1 parent 4fa91e5 commit c2f9569
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
'auto_discovery' => true,
],

/*
* ------------------------------------------------------------------------
* Firebase Auth Component
* ------------------------------------------------------------------------
*/

'auth' => [
'tenant_id' => env('FIREBASE_AUTH_TENANT_ID'),
],

/*
* ------------------------------------------------------------------------
* Firebase Realtime Database
Expand Down
4 changes: 4 additions & 0 deletions src/FirebaseProjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected function configure(string $name): FirebaseProject

$config = $this->configuration($name);

if ($tenantId = $config['auth']['tenant_id'] ?? null) {
$factory = $factory->withTenantId($tenantId);
}

if ($credentials = $config['credentials']['file'] ?? null) {
$resolvedCredentials = $this->resolveCredentials((string) $credentials);

Expand Down
17 changes: 17 additions & 0 deletions tests/FirebaseProjectManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ public function credentials_can_be_configured(): void
$this->assertSame($credentials, $serviceAccount->asArray());
}

/**
* @test
*/
public function a_tenant_id_can_be_set(): void
{
$this->app->config->set('firebase.projects.app.auth.tenant_id', $expected = 'abc123');

$auth = $this->app->make(Firebase\Auth::class);

/** @var Firebase\Auth\TenantId|null $tenantId */
$tenantId = ReflectionObject::createFromInstance($auth)->getProperty('tenantId')->getValue($auth);

$this->assertInstanceOf(Firebase\Auth\TenantId::class, $tenantId);

$this->assertSame($expected, $tenantId->toString());
}

/**
* @test
*/
Expand Down

0 comments on commit c2f9569

Please sign in to comment.