diff --git a/composer.lock b/composer.lock index 9362d2a45c..79cee0b33e 100644 --- a/composer.lock +++ b/composer.lock @@ -4658,16 +4658,16 @@ }, { "name": "utopia-php/migration", - "version": "1.13.0", + "version": "1.13.2", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "0395af61922b52fb73bd9dbfb2dd10ac7aed2b01" + "reference": "50526e121efcf73e11309446f194623a431d7e32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/0395af61922b52fb73bd9dbfb2dd10ac7aed2b01", - "reference": "0395af61922b52fb73bd9dbfb2dd10ac7aed2b01", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/50526e121efcf73e11309446f194623a431d7e32", + "reference": "50526e121efcf73e11309446f194623a431d7e32", "shasum": "" }, "require": { @@ -4707,9 +4707,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.13.0" + "source": "https://github.com/utopia-php/migration/tree/1.13.2" }, - "time": "2026-06-03T06:15:27+00:00" + "time": "2026-06-04T05:09:07+00:00" }, { "name": "utopia-php/mongo", diff --git a/src/Appwrite/Utopia/Response/Model/MigrationReport.php b/src/Appwrite/Utopia/Response/Model/MigrationReport.php index dd8387d580..f2304fa16d 100644 --- a/src/Appwrite/Utopia/Response/Model/MigrationReport.php +++ b/src/Appwrite/Utopia/Response/Model/MigrationReport.php @@ -167,6 +167,13 @@ class MigrationReport extends Model 'default' => '', 'example' => '1.4.0', ]); + + $this->addRule(Resource::TYPE_OAUTH2_PROVIDER, [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Number of OAuth2 provider configurations to be migrated. Secrets (clientSecret, p8File) are never migrated — destination admin must re-enter them per provider.', + 'default' => 0, + 'example' => 5, + ]); } /** diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 0a0a045844..05b1866afe 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -3361,6 +3361,148 @@ trait MigrationsBase $this->client->call(Client::METHOD_PATCH, '/project/smtp', $destinationKeyHeaders, ['enabled' => false]); } + public function testAppwriteMigrationOAuth(): void + { + $sourceProjectId = $this->getProject()['$id']; + $destinationProjectId = $this->getDestinationProject()['$id']; + + $sourceKeyHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $sourceProjectId, + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $destinationKeyHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $destinationProjectId, + 'x-appwrite-key' => $this->getDestinationProject()['apiKey'], + ]; + + $clientId = 'gh-client-' . ID::unique(); + $configure = $this->client->call(Client::METHOD_PATCH, '/project/oauth2/github', $sourceKeyHeaders, [ + 'clientId' => $clientId, + 'clientSecret' => 'gh-secret-not-migrated', + 'enabled' => false, + ]); + $this->assertEquals(200, $configure['headers']['status-code']); + $this->assertSame($clientId, $configure['body']['clientId']); + + $keycloak = $this->client->call(Client::METHOD_PATCH, '/project/oauth2/keycloak', $sourceKeyHeaders, [ + 'clientId' => 'keycloak-client-' . ID::unique(), + 'clientSecret' => 'keycloak-secret-not-migrated', + 'endpoint' => 'keycloak.example.com', + 'realmName' => 'appwrite', + 'enabled' => false, + ]); + $this->assertEquals(200, $keycloak['headers']['status-code']); + + $oidc = $this->client->call(Client::METHOD_PATCH, '/project/oauth2/oidc', $sourceKeyHeaders, [ + 'clientId' => 'oidc-client-' . ID::unique(), + 'clientSecret' => 'oidc-secret-not-migrated', + 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', + 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', + 'tokenURL' => 'https://idp.example.com/oauth2/token', + 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', + 'enabled' => false, + ]); + $this->assertEquals(200, $oidc['headers']['status-code']); + + $okta = $this->client->call(Client::METHOD_PATCH, '/project/oauth2/okta', $sourceKeyHeaders, [ + 'clientId' => 'okta-client-' . ID::unique(), + 'clientSecret' => 'okta-secret-not-migrated', + 'domain' => 'trial-6400025.okta.com', + 'authorizationServerId' => 'aus000000000000000h7z', + 'enabled' => false, + ]); + $this->assertEquals(200, $okta['headers']['status-code']); + + $result = $this->performMigrationSync([ + 'resources' => [ + Resource::TYPE_OAUTH2_PROVIDER, + ], + 'endpoint' => $this->webEndpoint, + 'projectId' => $sourceProjectId, + 'apiKey' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals('completed', $result['status']); + $this->assertEquals([Resource::TYPE_OAUTH2_PROVIDER], $result['resources']); + $this->assertArrayHasKey(Resource::TYPE_OAUTH2_PROVIDER, $result['statusCounters']); + $oauthCounters = $result['statusCounters'][Resource::TYPE_OAUTH2_PROVIDER]; + $this->assertEquals(0, $oauthCounters['error']); + $this->assertEquals(0, $oauthCounters['pending']); + $this->assertEquals(0, $oauthCounters['processing']); + $this->assertEquals(0, $oauthCounters['warning']); + $this->assertEquals(4, $oauthCounters['success']); + + $fetched = $this->client->call(Client::METHOD_GET, '/project/oauth2/github', $destinationKeyHeaders); + $this->assertEquals(200, $fetched['headers']['status-code']); + $this->assertSame($clientId, $fetched['body']['clientId']); + $this->assertFalse($fetched['body']['enabled']); + $this->assertSame('', $fetched['body']['clientSecret']); + + $fetched = $this->client->call(Client::METHOD_GET, '/project/oauth2/keycloak', $destinationKeyHeaders); + $this->assertEquals(200, $fetched['headers']['status-code']); + $this->assertSame($keycloak['body']['clientId'], $fetched['body']['clientId']); + $this->assertSame('keycloak.example.com', $fetched['body']['endpoint']); + $this->assertSame('appwrite', $fetched['body']['realmName']); + $this->assertFalse($fetched['body']['enabled']); + $this->assertSame('', $fetched['body']['clientSecret']); + + $fetched = $this->client->call(Client::METHOD_GET, '/project/oauth2/oidc', $destinationKeyHeaders); + $this->assertEquals(200, $fetched['headers']['status-code']); + $this->assertSame($oidc['body']['clientId'], $fetched['body']['clientId']); + $this->assertSame('https://idp.example.com/.well-known/openid-configuration', $fetched['body']['wellKnownURL']); + $this->assertSame('https://idp.example.com/oauth2/authorize', $fetched['body']['authorizationURL']); + $this->assertSame('https://idp.example.com/oauth2/token', $fetched['body']['tokenURL']); + $this->assertSame('https://idp.example.com/oauth2/userinfo', $fetched['body']['userInfoURL']); + $this->assertFalse($fetched['body']['enabled']); + $this->assertSame('', $fetched['body']['clientSecret']); + + $fetched = $this->client->call(Client::METHOD_GET, '/project/oauth2/okta', $destinationKeyHeaders); + $this->assertEquals(200, $fetched['headers']['status-code']); + $this->assertSame($okta['body']['clientId'], $fetched['body']['clientId']); + $this->assertSame('trial-6400025.okta.com', $fetched['body']['domain']); + $this->assertSame('aus000000000000000h7z', $fetched['body']['authorizationServerId']); + $this->assertFalse($fetched['body']['enabled']); + $this->assertSame('', $fetched['body']['clientSecret']); + + $this->client->call(Client::METHOD_PATCH, '/project/oauth2/github', $sourceKeyHeaders, [ + 'clientId' => '', + 'clientSecret' => '', + 'enabled' => false, + ]); + $this->client->call(Client::METHOD_PATCH, '/project/oauth2/github', $destinationKeyHeaders, [ + 'clientId' => '', + 'clientSecret' => '', + 'enabled' => false, + ]); + foreach ([$sourceKeyHeaders, $destinationKeyHeaders] as $headers) { + $this->client->call(Client::METHOD_PATCH, '/project/oauth2/keycloak', $headers, [ + 'clientId' => '', + 'clientSecret' => '', + 'endpoint' => '', + 'realmName' => '', + 'enabled' => false, + ]); + $this->client->call(Client::METHOD_PATCH, '/project/oauth2/oidc', $headers, [ + 'clientId' => '', + 'clientSecret' => '', + 'wellKnownURL' => '', + 'authorizationURL' => '', + 'tokenURL' => '', + 'userInfoURL' => '', + 'enabled' => false, + ]); + $this->client->call(Client::METHOD_PATCH, '/project/oauth2/okta', $headers, [ + 'clientId' => '', + 'clientSecret' => '', + 'domain' => '', + 'authorizationServerId' => '', + 'enabled' => false, + ]); + } + } + /** * Import documents from a CSV file. */