mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(account): offer only ID token providers on the ID token session
The route described `apple, google` while whitelisting all 52 OAuth providers and generating the shared `OAuthProvider` enum, so an SDK offered every provider on this method and the docs example was `amazon`. Sending any of them passed validation and then failed in the action with PROJECT_PROVIDER_UNSUPPORTED. The whitelist now holds the providers that configure `idToken`, and the parameter generates its own `IdTokenProvider` enum. The mock providers stay whitelisted, since the e2e suites sign in with them, and the generated enum keeps excluding them, so it reads `apple, google`.
This commit is contained in:
2 files changed
+30
-2
No files matched your search
@@ -53,7 +53,8 @@ class Create extends Action
|
||||
public function __construct()
|
||||
{
|
||||
$providers = Config::getParam('oAuthProviders', []);
|
||||
$idTokenProviders = \array_keys(\array_filter($providers, fn ($node) => !empty($node['idToken']) && empty($node['mock'])));
|
||||
$idTokenProviders = \array_keys(\array_filter($providers, fn ($node) => !empty($node['idToken'])));
|
||||
$documentedProviders = \array_filter($idTokenProviders, fn (string $provider) => empty($providers[$provider]['mock']));
|
||||
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_POST)
|
||||
@@ -84,7 +85,7 @@ class Create extends Action
|
||||
->label('abuse-limit', 10)
|
||||
->label('abuse-key', 'url:{url},ip:{ip}')
|
||||
->label('abuse-reset', [201])
|
||||
->param('provider', '', new WhiteList(\array_keys($providers), true), 'OAuth2 provider that issued the ID token. Currently, supported providers are: ' . \implode(', ', $idTokenProviders) . '.', enum: new Enum(name: 'OAuthProvider', exclude: ['mock', 'mock-unverified']))
|
||||
->param('provider', '', new WhiteList($idTokenProviders, true), 'OAuth2 provider that issued the ID token. Currently, supported providers are: ' . \implode(', ', $documentedProviders) . '.', enum: new Enum(name: 'IdTokenProvider', exclude: ['mock', 'mock-unverified']))
|
||||
->param('idToken', '', new Text(8192, 0), 'OpenID Connect ID token (JWT) obtained natively from the provider, for example via Google Credential Manager or Sign in with Apple.')
|
||||
->param('nonce', '', new Text(256, 0), 'Raw nonce used when requesting the ID token. Required for Apple, and whenever the token carries a nonce claim, which must match it. Ignored when the provider issued the token without a nonce.', true)
|
||||
->param('accessToken', '', new Text(4096, 0), 'Provider access token to store alongside the session for calling provider APIs. Never used for authentication.', true)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Platform\Modules\Account;
|
||||
|
||||
use Appwrite\Platform\Modules\Account\Http\Account\Sessions\IdToken\Create;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Config\Config;
|
||||
|
||||
final class IdTokenSessionTest extends TestCase
|
||||
{
|
||||
public function testProviderAcceptsOnlyIdTokenProviders(): void
|
||||
{
|
||||
$providers = Config::getParam('oAuthProviders', []);
|
||||
$expected = \array_keys(\array_filter($providers, fn (array $node): bool => !empty($node['idToken'])));
|
||||
|
||||
$parameter = (new Create())->getParams()['provider'];
|
||||
$validator = $parameter['validator'];
|
||||
$validator = \is_callable($validator) ? $validator() : $validator;
|
||||
|
||||
$this->assertSame($expected, $validator->getList());
|
||||
$this->assertNotContains('amazon', $validator->getList());
|
||||
$this->assertStringContainsString('apple, google', $parameter['description']);
|
||||
$this->assertSame('IdTokenProvider', $parameter['enum']->name);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user