From 75e66e675b7e5f34c26a8cfa87257a13adf8a5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 10 Aug 2023 01:02:13 +0200 Subject: [PATCH] Move oauth secret to identity --- app/config/collections.php | 11 ----------- app/controllers/api/migrations.php | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 8817683db3..5760024bf5 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -242,17 +242,6 @@ $commonCollections = [ 'default' => null, 'array' => false, 'filters' => ['datetime'], - ], - [ - '$id' => ID::custom('migrationsFirebaseServiceAccount'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => ['encrypt'], ] ], 'indexes' => [ diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index 1592b98984..8d961a0450 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -146,14 +146,14 @@ App::post('/v1/migrations/firebase/oauth') $dbForConsole->updateDocument('identities', $identity->getId(), $identity); } - if ($user->getAttribute('migrationsFirebaseServiceAccount')) { - $serviceAccount = json_decode($user->getAttribute('migrationsFirebaseServiceAccount'), true); + if ($identity->getAttribute('secret')) { + $serviceAccount = $identity->getAttribute('secret'); } else { $serviceAccount = $firebase->createServiceAccount($accessToken, $projectId); - $user = $user - ->setAttribute('migrationsFirebaseServiceAccount', json_encode($serviceAccount)); + $identity = $identity + ->setAttribute('secret', $serviceAccount); - $dbForConsole->updateDocument('users', $user->getId(), $user); + $dbForConsole->updateDocument('identities', $identity->getId(), $identity); } $migration = $dbForProject->createDocument('migrations', new Document([ @@ -542,14 +542,14 @@ App::get('/v1/migrations/firebase/report/oauth') } // Get Service Account - if ($user->getAttribute('migrationsFirebaseServiceAccount')) { - $serviceAccount = json_decode($user->getAttribute('migrationsFirebaseServiceAccount'), true); + if ($identity->getAttribute('secret')) { + $serviceAccount = $identity->getAttribute('secret'); } else { $serviceAccount = $firebase->createServiceAccount($accessToken, $projectId); - $user = $user - ->setAttribute('migrationsFirebaseServiceAccount', json_encode($serviceAccount)); + $identity = $identity + ->setAttribute('secret', $serviceAccount); - $dbForConsole->updateDocument('users', $user->getId(), $user); + $dbForConsole->updateDocument('identities', $identity->getId(), $identity); } $firebase = new Firebase(array_merge($serviceAccount, ['project_id' => $projectId]));