feat(identity): confirm the email address with a six-digit code from the message

This commit is contained in:
shira committed 2026-10-10 00:52:46 +03:00
1 parent c94434cd09
commit d365a05c96
87 files changed
+4764 -224

No files matched your search

+117
View File
@@ -291,6 +291,65 @@ paths:
$ref: '#/components/responses/TooManyRequests'
default:
$ref: '#/components/responses/Problem'
/api/v1/identity/email-verifications/code:
post:
operationId: ConfirmEmailByCode
summary: Verify an email with the six-digit code from the verification message.
description: |-
Public operation without a session. The verification message carries a six-digit code next to the link. The client sends the address, the code, and the password chosen for the registration that issued the code, so the user types only the code after registration. A reloaded page has no password in memory, so it asks for the address, the password, and the code together.
The server finds the newest open verification token of the unverified account with this normalized address, whose registration is current and which carries a code. It compares the keyed digest of the code with the stored digest, checks the password against the token's pending password hash, and checks that the code has not expired. The code lives 30 minutes, or until the token ends if the token ends sooner. When all three checks pass, the server consumes the token, verifies the email, and applies the pending credentials in one transaction, exactly as the link confirmation does, and answers 200 with the same body. Success does not start a session.
Each refusal answers 400 `verification_token_invalid` with the same body, whatever the cause: an unknown address, an address without an open code, a wrong code, an expired code, a wrong password, or a code that was burned. This keeps the answer from showing which addresses have a pending registration. Every failed attempt of an open code counts against that token. The fifth failed attempt burns the token: the code and the link stop working, and the user must request a new message. A refused attempt changes nothing else.
The same refusal is returned after the rate limits are checked. The operation is limited per client address (`IDENTITY_CLIENT_HOURLY_LIMIT`) and per normalized email (`IDENTITY_LOGIN_EMAIL_HOURLY_LIMIT`, shared with login); a refused request answers 429 with Retry-After. A body that does not match the contract, such as a code that is not six digits, answers 400 `validation_failed` before any lookup. Like every unsafe public identity operation, it requires an Origin equal to the configured public application origin and answers 403 `csrf_check_failed` otherwise.
security: []
tags:
- identity
parameters:
- name: Origin
in: header
required: false
description: The exact configured public application origin. This optional parameter is read by the server as empty when absent, so the operation answers csrf_check_failed rather than treating a missing Origin as an allowed request.
schema:
type: string
minLength: 1
maxLength: 2048
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/EmailVerificationCodeRequest'
examples:
code:
summary: Address, code from the message, and the registration password
value:
email: candidate@example.com
code: '482915'
password: correct horse battery staple
responses:
'200':
description: The email is verified.
content:
application/json:
schema:
$ref: '#/components/schemas/EmailVerificationResult'
examples:
candidate:
summary: A candidate continues with consents
value:
email_verified: true
scenario: candidate
onboarding_step: candidate_consents
'400':
$ref: '#/components/responses/EmailVerificationCodeFailed'
'403':
$ref: '#/components/responses/CsrfCheckFailed'
'429':
$ref: '#/components/responses/TooManyRequests'
default:
$ref: '#/components/responses/Problem'
/api/v1/identity/sessions:
post:
operationId: Login
@@ -10019,6 +10078,30 @@ components:
type: string
enum:
- ok
VerificationCode:
type: string
minLength: 6
maxLength: 6
pattern: ^[0-9]{6}$
description: Six-digit code from the verification message, with leading zeros. It is request input only; the server keeps a keyed digest of it, never the code.
EmailVerificationCodeRequest:
type: object
description: Address, the six-digit code from its verification message, and the password chosen for the registration that issued the code. The password is checked the same way as in EmailVerificationRequest.
additionalProperties: false
required:
- email
- code
- password
properties:
email:
$ref: '#/components/schemas/EmailAddress'
code:
$ref: '#/components/schemas/VerificationCode'
password:
type: string
minLength: 1
maxLength: 128
description: Password chosen for the registration that issued the code. The server applies NFKC normalization and the login length bounds, without reapplying the current new-registration blocklist.
AssessmentRealMode:
type: string
description: Server-selected mode available to a real category assessment.
@@ -11863,6 +11946,17 @@ components:
examples:
limit_reached:
$ref: '#/components/examples/HiddenOrganizationLimitReached'
EmailVerificationCodeFailed:
description: 'The code does not verify the email. Code verification_token_invalid covers every refusal in the same shape: an unknown address, an address without an open code, a wrong code, an expired code, a wrong password, and a code that was burned after five failed attempts. Code validation_failed means the body does not match the contract, such as a code that is not six digits, and carries the pointer `/code`, `/email`, or `/password`. Nothing was changed in any case.'
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
examples:
verification_code_invalid:
$ref: '#/components/examples/VerificationCodeInvalid'
validation_failed:
$ref: '#/components/examples/VerificationCodeMalformed'
securitySchemes:
sessionCookie:
type: apiKey
@@ -12032,6 +12126,29 @@ components:
pointer: /token
code: invalid
message: The value does not match the contract.
VerificationCodeInvalid:
summary: The code does not verify the email
value:
type: urn:lincodex:problem:verification_token_invalid
title: Verification code is not valid
status: 400
code: verification_token_invalid
detail: Check the code and the password, or request a new message.
trace_id: 6e7f8a9b-0c1d-4e2f-9a3b-4c5d6e7f8a9b
VerificationCodeMalformed:
summary: The code is not six digits
value:
type: urn:lincodex:problem:validation_failed
title: Request validation failed
status: 400
code: validation_failed
detail: One or more request fields are invalid.
trace_id: 7f8a9b0c-1d2e-4f3a-8b4c-5d6e7f8a9b0c
errors:
- in: body
pointer: /code
code: invalid
message: The value does not match the contract.
CandidateSession:
summary: Session of a verified candidate
value: