fix: address review feedback on email verification OTP · appwrite/appwrite@b09c2e4 · GitHub
Skip to content

Commit b09c2e4

Browse files
committed
fix: address review feedback on email verification OTP
1 parent 273a302 commit b09c2e4

7 files changed

Lines changed: 43 additions & 7 deletions

File tree

‎app/controllers/api/account.php‎

Lines changed: 5 additions & 6 deletions

‎app/init/constants.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
const TOKEN_TYPE_OAUTH2 = 7;
205205
const TOKEN_TYPE_GENERIC = 8;
206206
const TOKEN_TYPE_EMAIL = 9; // OTP
207+
const TOKEN_TYPE_VERIFICATION_OTP = 10;
207208

208209
/**
209210
* Session Providers.
@@ -347,6 +348,7 @@
347348
const MAIL_TEMPLATE_MAGIC_URL = 'magic-url';
348349
const MAIL_TEMPLATE_MFA_CHALLENGE = 'mfa-challenge';
349350
const MAIL_TEMPLATE_OTP = 'otp';
351+
const MAIL_TEMPLATE_OTP_VERIFICATION = 'otp-verification';
350352
const MAIL_TEMPLATE_RECOVERY = 'recovery';
351353
const MAIL_TEMPLATE_SESSION_ALERT = 'session-alert';
352354
const MAIL_TEMPLATE_SMTP_TEST = 'smtp-test';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use this endpoint to send a 6-digit verification code to the currently logged in user's email address. Unlike [createEmailVerification](https://appwrite.io/docs/references/cloud/client-web/account#createEmailVerification), this method requires no redirect URL, which makes it suitable for mobile and desktop apps that cannot host a verification page. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateEmailVerificationOTP). The code sent to the user's email address is valid for 15 minutes.
2+
3+
Enable the **phrase** parameter to include a randomly generated security phrase in both the email and the response. Showing that phrase in your app lets the user confirm the email genuinely came from your request, which helps protect against phishing.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use this endpoint to complete the user email verification process using the 6-digit code that was emailed by [createEmailVerificationOTP](https://appwrite.io/docs/references/cloud/client-web/account#createEmailVerificationOTP). Pass the **userId** of the user being verified along with the **secret** code from the email. If confirmed, this route will return a 200 status code and the code is consumed.

‎src/Appwrite/Platform/Workers/Deletes.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ private function deleteExpiredTokens(Document $project, callable $getProjectDB):
12321232
TOKEN_TYPE_OAUTH2,
12331233
TOKEN_TYPE_GENERIC,
12341234
TOKEN_TYPE_EMAIL,
1235+
TOKEN_TYPE_VERIFICATION_OTP,
12351236
];
12361237

12371238
// Current index is on {`type`, `expire`}

‎tests/e2e/Services/Account/AccountCustomClientTest.php‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6140,7 +6140,6 @@ public function testCreateEmailVerificationOTP(): void
61406140
$data = $this->setupAccountWithSession();
61416141
$session = $data['session'];
61426142
$email = $data['email'];
6143-
$name = $data['name'];
61446143

61456144
/**
61466145
* Test for SUCCESS
@@ -6300,6 +6299,35 @@ public function testUpdateEmailVerificationOTP(): void
63006299
]);
63016300

63026301
$this->assertEquals(404, $response['headers']['status-code']);
6302+
6303+
/**
6304+
* Test for FAILURE - OTP is single use
6305+
*/
6306+
$response = $this->client->call(Client::METHOD_PUT, '/account/verifications/email/otp', array_merge([
6307+
'origin' => 'http://localhost',
6308+
'content-type' => 'application/json',
6309+
'x-appwrite-project' => $projectId,
6310+
'cookie' => 'a_session_' . $projectId . '=' . $session,
6311+
]), [
6312+
'userId' => $userId,
6313+
'secret' => $otp,
6314+
]);
6315+
6316+
$this->assertEquals(401, $response['headers']['status-code']);
6317+
$this->assertEquals('user_invalid_token', $response['body']['type']);
6318+
6319+
/**
6320+
* Test for FAILURE - email already verified
6321+
*/
6322+
$response = $this->client->call(Client::METHOD_POST, '/account/verifications/email/otp', array_merge([
6323+
'origin' => 'http://localhost',
6324+
'content-type' => 'application/json',
6325+
'x-appwrite-project' => $projectId,
6326+
'cookie' => 'a_session_' . $projectId . '=' . $session,
6327+
]));
6328+
6329+
$this->assertEquals(409, $response['headers']['status-code']);
6330+
$this->assertEquals('user_email_already_verified', $response['body']['type']);
63036331
}
63046332

63056333
public function testCreateIdTokenSessionGoogleShapedClaims(): void

‎tests/e2e/Services/Project/TemplatesBase.php‎

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)