Skip to content

Commit 3ce16c5

Browse files
committed
Consolidate OAuth2 provider resources into a single class
Replace the per-provider class hierarchy (OAuth2Provider base + StandardProvider/WithEndpointProvider + ~40 one-line subclasses) with a single OAuth2Provider class driven by a `providerKey => non-secret fields` map. Addresses review feedback to have one class for all providers. - Source dispatch: drop the 42-entry class registry + oauth2ClassFor(); build providers via OAuth2Provider::fromArray($key, $payload). - Destination dispatch: replace the instanceof chain with a key check (Apple) + data-driven settings routing for endpoint/tenant/prompt. - The field map doubles as a secret allow-list: only declared non-secret fields are copied off the listOAuth2Providers payload, so a future upstream secret field cannot leak into the migration. Net 44 fewer files. Pint, PHPStan level 3, and the Unit suite all pass.
1 parent 6e4e416 commit 3ce16c5

47 files changed

Lines changed: 175 additions & 898 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Migration/Destinations/Appwrite.php

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@
4545
use Utopia\Migration\Resources\Auth\AuthMethods;
4646
use Utopia\Migration\Resources\Auth\Hash;
4747
use Utopia\Migration\Resources\Auth\Membership;
48-
use Utopia\Migration\Resources\Auth\OAuth2\Apple as OAuth2Apple;
49-
use Utopia\Migration\Resources\Auth\OAuth2\Google as OAuth2Google;
50-
use Utopia\Migration\Resources\Auth\OAuth2\Microsoft as OAuth2Microsoft;
5148
use Utopia\Migration\Resources\Auth\OAuth2\OAuth2Provider;
52-
use Utopia\Migration\Resources\Auth\OAuth2\StandardProvider as OAuth2Standard;
53-
use Utopia\Migration\Resources\Auth\OAuth2\WithEndpointProvider as OAuth2WithEndpoint;
5449
use Utopia\Migration\Resources\Auth\Policies;
5550
use Utopia\Migration\Resources\Auth\Team;
5651
use Utopia\Migration\Resources\Auth\User;
@@ -3568,39 +3563,35 @@ protected function createAuthMethods(AuthMethods $resource): bool
35683563
*/
35693564
protected function createOAuth2Provider(OAuth2Provider $resource): bool
35703565
{
3571-
$key = $resource::getProviderKey();
3566+
$key = $resource->getProviderKey();
35723567
$project = $this->dbForPlatform->getDocument('projects', $this->projectId);
35733568
$oAuthProviders = $project->getAttribute('oAuthProviders', []);
35743569

3575-
if ($resource instanceof OAuth2Apple) {
3576-
if ($resource->getServiceId() !== '') {
3577-
$oAuthProviders[$key . 'Appid'] = $resource->getServiceId();
3570+
if ($key === 'apple') {
3571+
// Apple's app id is the serviceId; keyId/teamId ride in the secret JSON blob.
3572+
$serviceId = (string) $resource->getSetting('serviceId');
3573+
if ($serviceId !== '') {
3574+
$oAuthProviders[$key . 'Appid'] = $serviceId;
35783575
}
35793576
$oAuthProviders[$key . 'Secret'] = $this->mergeAppleSecret(
35803577
$oAuthProviders[$key . 'Secret'] ?? '',
3581-
$resource->getKeyId(),
3582-
$resource->getTeamId(),
3578+
(string) $resource->getSetting('keyId'),
3579+
(string) $resource->getSetting('teamId'),
35833580
);
3584-
} elseif ($resource instanceof OAuth2Standard) {
3585-
if ($resource->getClientId() !== '') {
3586-
$oAuthProviders[$key . 'Appid'] = $resource->getClientId();
3581+
} else {
3582+
$clientId = (string) $resource->getSetting('clientId');
3583+
if ($clientId !== '') {
3584+
$oAuthProviders[$key . 'Appid'] = $clientId;
35873585
}
35883586
// Per-shape extras (endpoint/tenant/prompt) ride inside the JSON secret blob.
3589-
if ($resource instanceof OAuth2WithEndpoint && $resource->getEndpoint() !== '') {
3590-
$oAuthProviders[$key . 'Secret'] = $this->mergeJsonSecret(
3591-
$oAuthProviders[$key . 'Secret'] ?? '',
3592-
['endpoint' => $resource->getEndpoint()],
3593-
);
3594-
} elseif ($resource instanceof OAuth2Microsoft && $resource->getTenant() !== '') {
3595-
$oAuthProviders[$key . 'Secret'] = $this->mergeJsonSecret(
3596-
$oAuthProviders[$key . 'Secret'] ?? '',
3597-
['tenant' => $resource->getTenant()],
3598-
);
3599-
} elseif ($resource instanceof OAuth2Google && !empty($resource->getPrompt())) {
3600-
$oAuthProviders[$key . 'Secret'] = $this->mergeJsonSecret(
3601-
$oAuthProviders[$key . 'Secret'] ?? '',
3602-
['prompt' => $resource->getPrompt()],
3603-
);
3587+
foreach (['endpoint', 'tenant', 'prompt'] as $field) {
3588+
$value = $resource->getSetting($field);
3589+
if ($value !== null && $value !== '' && $value !== []) {
3590+
$oAuthProviders[$key . 'Secret'] = $this->mergeJsonSecret(
3591+
$oAuthProviders[$key . 'Secret'] ?? '',
3592+
[$field => $value],
3593+
);
3594+
}
36043595
}
36053596
}
36063597

src/Migration/Resources/Auth/OAuth2/Amazon.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Apple.php

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Auth0.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Authentik.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Autodesk.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Bitbucket.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Bitly.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Box.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Migration/Resources/Auth/OAuth2/Dailymotion.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)