Project

General

Profile

Sub-Task #308

Updated by Bricklou 22 days ago

Technical specification of how an account changes its email address. 

 Request (`POST /api/v1/me/email-change`): 

 * The body carries the new address, the current password and, when the account has an authenticator app, its code (`totp_code`). A code works once. 
 * Rate limit: shared with the password change, per account. 
 * The new address is kept aside, one pending change per account; a new request replaces the previous one. The account keeps its current address. 
 * An account that signs in through a login provider is refused. 

 Links: 

 * The worker issues the tokens after the request event, so no secret travels on the event bus. Only hashes are stored. 
 * The new address receives a confirm link. 
 * The current address receives a cancel link. Without an authenticator app it also receives an approve link. 
 * The links carry their token in the URL fragment. The public endpoints are `POST /api/v1/authentication/verify-email-change`, `approve-email-change` and `cancel-email-change`, with the token in the body. 
 * Links work for 24 hours. A confirm or approve link can be followed again while the other side is awaited; the cancel link works until the change applies. 

 Applying: 

 * The change applies when the new address confirmed and, if required, the current address approved, in any order. Both links must be unexpired. 
 * The new address is stored as verified. The change is written to the change log and announced as a profile change. 
 * Every session of the account ends. 
 * An address taken by another account in the meantime refuses the change. 

 State: 

 * `GET /api/v1/me` returns the pending change: the new address, whether the new address still has to confirm and whether the current address still has to approve. 
 * `DELETE /api/v1/me/email-change` cancels it from a session. 

 Acceptance criteria: 

 * [x] Password and authenticator code are checked before anything is stored. 
 * [x] Without an authenticator app both addresses must agree; with one, the new address alone confirms. 
 * [x] Every state change is covered by a test, with a real database. 
 * [x] The mails are covered by a handler test each, and read well on a phone. 

 Known limit: a 
 * [ ] A security key alone does not count is accepted as a second factor here; such an account is treated as having none. factor.

Back