diff --git a/.env b/.env index 351447a8b4..0b8c625a36 100644 --- a/.env +++ b/.env @@ -56,8 +56,8 @@ _APP_SMTP_PORT=1025 _APP_SMTP_SECURE= _APP_SMTP_USERNAME= _APP_SMTP_PASSWORD= -_APP_PHONE_PROVIDER=phone://mock -_APP_PHONE_FROM=+123456789 +_APP_SMS_PROVIDER=sms://mock +_APP_SMS_FROM=+123456789 _APP_STORAGE_LIMIT=30000000 _APP_STORAGE_PREVIEW_LIMIT=20000000 _APP_FUNCTIONS_SIZE_LIMIT=30000000 diff --git a/CHANGES.md b/CHANGES.md index 5ba47ab638..ea0dabf8d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -48,7 +48,7 @@ - Added Endpoint to update Account Phone Number (`PATCH:/v1/account/phone`) - Added Endpoint to create Account Phone Verification (`POST:/v1/account/verification/phone`) - Added Endpoint to confirm Account Phone Verification (`PUT:/v1/account/verification/phone`) - - Added `_APP_PHONE_PROVIDER` and `_APP_PHONE_FROM` Environment Variable + - Added `_APP_SMS_PROVIDER` and `_APP_SMS_FROM` Environment Variable - Added `phone` and `phoneVerification` Attribute to User - Added `$createdAt` and `$updatedAt` Attributes by @TorstenDittmann in https://github.com/appwrite/appwrite/pull/3382 - Bucket diff --git a/Dockerfile b/Dockerfile index bd437d047c..4930bdcb87 100755 --- a/Dockerfile +++ b/Dockerfile @@ -220,8 +220,8 @@ ENV _APP_SERVER=swoole \ _APP_SMTP_SECURE= \ _APP_SMTP_USERNAME= \ _APP_SMTP_PASSWORD= \ - _APP_PHONE_PROVIDER= \ - _APP_PHONE_FROM= \ + _APP_SMS_PROVIDER= \ + _APP_SMS_FROM= \ _APP_FUNCTIONS_SIZE_LIMIT=30000000 \ _APP_FUNCTIONS_TIMEOUT=900 \ _APP_FUNCTIONS_CONTAINERS=10 \ diff --git a/app/config/errors.php b/app/config/errors.php index 8420ddbb74..0c284027c1 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -50,7 +50,7 @@ return [ ], Exception::GENERAL_PHONE_DISABLED => [ 'name' => Exception::GENERAL_PHONE_DISABLED, - 'description' => 'Phone provider is not configured. Please check the _APP_PHONE_PROVIDER environment variable of your Appwrite server.', + 'description' => 'Phone provider is not configured. Please check the _APP_SMS_PROVIDER environment variable of your Appwrite server.', 'code' => 503, ], Exception::GENERAL_ARGUMENT_INVALID => [ diff --git a/app/config/variables.php b/app/config/variables.php index 7b4c4b4ace..ca86f3cc6d 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -394,8 +394,8 @@ return [ 'description' => '', 'variables' => [ [ - 'name' => '_APP_PHONE_PROVIDER', - 'description' => "Provider used for delivering SMS for Phone authentication. Use the following format: 'phone://[USER]:[SECRET]@[PROVIDER]'. \n\nAvailable providers are twilio, text-magic and telesign.", + 'name' => '_APP_SMS_PROVIDER', + 'description' => "Provider used for delivering SMS for Phone authentication. Use the following format: 'sms://[USER]:[SECRET]@[PROVIDER]'. \n\nAvailable providers are twilio, text-magic and telesign.", 'introduction' => '0.15.0', 'default' => '', 'required' => false, @@ -403,7 +403,7 @@ return [ 'filter' => '' ], [ - 'name' => '_APP_PHONE_FROM', + 'name' => '_APP_SMS_FROM', 'description' => 'Phone number used for sending out messages. Must start with a leading \'+\' and maximum of 15 digits without spaces (+123456789).', 'introduction' => '0.15.0', 'default' => '', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 27439cb2e1..4a3cd7608d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2,7 +2,7 @@ use Ahc\Jwt\JWT; use Appwrite\Auth\Auth; -use Appwrite\Auth\Phone; +use Appwrite\Auth\SMS; use Appwrite\Auth\Validator\Password; use Appwrite\Auth\Validator\Phone as ValidatorPhone; use Appwrite\Detector\Detector; @@ -58,6 +58,7 @@ App::post('/v1/account') ->param('userId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('email', '', new Email(), 'User email.') ->param('password', '', new Password(), 'User password. Must be at least 8 chars.') + ->param('phone', '', new Password(), 'User password. Must be at least 8 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -863,7 +864,7 @@ App::post('/v1/account/sessions/phone') ->label('abuse-limit', 10) ->label('abuse-key', 'url:{url},email:{param-email}') ->param('userId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') - ->param('number', '', new ValidatorPhone(), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.') + ->param('phone', '', new ValidatorPhone(), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.') ->inject('request') ->inject('response') ->inject('project') @@ -871,9 +872,9 @@ App::post('/v1/account/sessions/phone') ->inject('audits') ->inject('events') ->inject('messaging') - ->inject('phone') - ->action(function (string $userId, string $number, Request $request, Response $response, Document $project, Database $dbForProject, Audit $audits, Event $events, EventPhone $messaging, Phone $phone) { - if (empty(App::getEnv('_APP_PHONE_PROVIDER'))) { + ->inject('sms') + ->action(function (string $userId, string $phone, Request $request, Response $response, Document $project, Database $dbForProject, Audit $audits, Event $events, EventPhone $messaging, SMS $sms) { + if (empty(App::getEnv('_APP_SMS_PROVIDER'))) { throw new Exception('Phone provider not configured', 503, Exception::GENERAL_PHONE_DISABLED); } @@ -881,7 +882,7 @@ App::post('/v1/account/sessions/phone') $isPrivilegedUser = Auth::isPrivilegedUser($roles); $isAppUser = Auth::isAppUser($roles); - $user = $dbForProject->findOne('users', [new Query('phone', Query::TYPE_EQUAL, [$number])]); + $user = $dbForProject->findOne('users', [new Query('phone', Query::TYPE_EQUAL, [$phone])]); if (!$user) { $limit = $project->getAttribute('auths', [])['limit'] ?? 0; @@ -901,7 +902,7 @@ App::post('/v1/account/sessions/phone') '$read' => ['role:all'], '$write' => ['user:' . $userId], 'email' => null, - 'phone' => $number, + 'phone' => $phone, 'emailVerification' => false, 'phoneVerification' => false, 'status' => true, @@ -913,11 +914,11 @@ App::post('/v1/account/sessions/phone') 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $number]) + 'search' => implode(' ', [$userId, $phone]) ]))); } - $secret = $phone->generateSecretDigits(); + $secret = $sms->generateSecretDigits(); $expire = \time() + Auth::TOKEN_EXPIRATION_PHONE; @@ -941,7 +942,7 @@ App::post('/v1/account/sessions/phone') $dbForProject->deleteCachedDocument('users', $user->getId()); $messaging - ->setRecipient($number) + ->setRecipient($phone) ->setMessage($secret) ->trigger(); @@ -2277,7 +2278,7 @@ App::post('/v1/account/verification/phone') ->inject('messaging') ->action(function (Request $request, Response $response, Phone $phone, Document $user, Database $dbForProject, Audit $audits, Event $events, Stats $usage, EventPhone $messaging) { - if (empty(App::getEnv('_APP_PHONE_PROVIDER'))) { + if (empty(App::getEnv('_APP_SMS_PROVIDER'))) { throw new Exception('Phone provider not configured', 503, Exception::GENERAL_PHONE_DISABLED); } diff --git a/app/init.php b/app/init.php index 71407699b8..1d628ede96 100644 --- a/app/init.php +++ b/app/init.php @@ -23,12 +23,12 @@ use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; use Appwrite\Extend\Exception; use Appwrite\Auth\Auth; -use Appwrite\Auth\Phone\Mock; -use Appwrite\Auth\Phone\Telesign; -use Appwrite\Auth\Phone\TextMagic; -use Appwrite\Auth\Phone\Twilio; -use Appwrite\Auth\Phone\Msg91; -use Appwrite\Auth\Phone\Vonage; +use Appwrite\SMS\Adapter\Mock; +use Appwrite\SMS\Adapter\Telesign; +use Appwrite\SMS\Adapter\TextMagic; +use Appwrite\SMS\Adapter\Twilio; +use Appwrite\SMS\Adapter\Msg91; +use Appwrite\SMS\Adapter\Vonage; use Appwrite\DSN\DSN; use Appwrite\Event\Audit; use Appwrite\Event\Database as EventDatabase; @@ -982,8 +982,8 @@ App::setResource('geodb', function ($register) { return $register->get('geodb'); }, ['register']); -App::setResource('phone', function () { - $dsn = new DSN(App::getEnv('_APP_PHONE_PROVIDER')); +App::setResource('sms', function () { + $dsn = new DSN(App::getEnv('_APP_SMS_PROVIDER')); $user = $dsn->getUser(); $secret = $dsn->getPassword(); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 45628f5bcc..827e8c4d62 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -149,8 +149,8 @@ services: - _APP_MAINTENANCE_RETENTION_EXECUTION - _APP_MAINTENANCE_RETENTION_ABUSE - _APP_MAINTENANCE_RETENTION_AUDIT - - _APP_PHONE_PROVIDER - - _APP_PHONE_SECRET + - _APP_SMS_PROVIDER + - _APP_SMS_FROM appwrite-realtime: image: /: @@ -514,8 +514,8 @@ services: - _APP_REDIS_PORT - _APP_REDIS_USER - _APP_REDIS_PASS - - _APP_PHONE_PROVIDER - - _APP_PHONE_FROM + - _APP_SMS_PROVIDER + - _APP_SMS_FROM - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG diff --git a/app/workers/messaging.php b/app/workers/messaging.php index fd6eed6c22..1fc5deaf44 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -1,12 +1,12 @@ getUser(); $secret = $dsn->getPassword(); - $this->phone = match ($dsn->getHost()) { + $this->sms = match ($dsn->getHost()) { 'mock' => new Mock('', ''), // used for tests 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), @@ -43,12 +43,12 @@ class MessagingV1 extends Worker default => null }; - $this->from = App::getEnv('_APP_PHONE_FROM'); + $this->from = App::getEnv('_APP_SMS_FROM'); } public function run(): void { - if (empty(App::getEnv('_APP_PHONE_PROVIDER'))) { + if (empty(App::getEnv('_APP_SMS_PROVIDER'))) { Console::info('Skipped sms processing. No Phone provider has been set.'); return; } @@ -62,7 +62,7 @@ class MessagingV1 extends Worker $message = $this->args['message']; try { - $this->phone->send($this->from, $recipient, $message); + $this->sms->send($this->from, $recipient, $message); } catch (\Exception $error) { throw new Exception('Error sending message: ' . $error->getMessage(), 500); } diff --git a/docker-compose.yml b/docker-compose.yml index 20d2c5c2f9..ecb0d9fe2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -175,8 +175,8 @@ services: - _APP_MAINTENANCE_RETENTION_EXECUTION - _APP_MAINTENANCE_RETENTION_ABUSE - _APP_MAINTENANCE_RETENTION_AUDIT - - _APP_PHONE_PROVIDER - - _APP_PHONE_SECRET + - _APP_SMS_PROVIDER + - _APP_SMS_FROM appwrite-realtime: entrypoint: realtime @@ -545,8 +545,8 @@ services: - _APP_REDIS_PORT - _APP_REDIS_USER - _APP_REDIS_PASS - - _APP_PHONE_PROVIDER - - _APP_PHONE_FROM + - _APP_SMS_PROVIDER + - _APP_SMS_FROM - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG diff --git a/src/Appwrite/Auth/Phone/Mock.php b/src/Appwrite/SMS/Adapter/Mock.php similarity index 85% rename from src/Appwrite/Auth/Phone/Mock.php rename to src/Appwrite/SMS/Adapter/Mock.php index 03f4f7073f..fad97650b9 100644 --- a/src/Appwrite/Auth/Phone/Mock.php +++ b/src/Appwrite/SMS/Adapter/Mock.php @@ -1,10 +1,10 @@ utilized from for flow id * @param string $to * @param string $message diff --git a/src/Appwrite/Auth/Phone/Telesign.php b/src/Appwrite/SMS/Adapter/Telesign.php similarity index 90% rename from src/Appwrite/Auth/Phone/Telesign.php rename to src/Appwrite/SMS/Adapter/Telesign.php index 520dfc61bf..1ac6c1b284 100644 --- a/src/Appwrite/Auth/Phone/Telesign.php +++ b/src/Appwrite/SMS/Adapter/Telesign.php @@ -1,13 +1,13 @@ = 400) { - throw new Exception($response); + throw new \Exception($response); } return $response; diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 688bdb9df9..a2c0e33a6b 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2,7 +2,7 @@ namespace Tests\E2E\Services\Account; -use Appwrite\Auth\Phone\Mock; +use Appwrite\SMS\Adapter\Mock; use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectCustom;