Sub-Task #124
Updated by Bricklou 21 days ago
Technical specification of the profile sync on sign-in through a login provider. * When an account that is linked to a provider signs in through it, the profile follows the provider's claims: username, email username and avatar. email. The avatar joins them once avatars exist (#108). * The provider is the source of truth, which is why the profile is read-only for these accounts (#109). * The username is the provider's preferred username, then its name. It is applied when it is valid and free. * The email is applied only when the provider vouches for it, when it is valid and free. It then counts as verified. * Each change is written to the change log and announced as a profile change. * A value that breaks a rule or belongs to another account is skipped and logged. A failure of the sync is logged too. The sign-in succeeds in every case. * A suspended account is refused before anything is synced. Avatar: * The avatar is taken from the picture URL of the provider, at the first sign-in and whenever that URL changes. The URL the avatar was taken from is kept with the identity, so the same URL is not downloaded again at each sign-in. * The picture goes through the same checks and re-encoding as an uploaded avatar, and replaces the previous one. * The URL comes from a third party: only public HTTPS hosts are fetched. The addresses the host resolves to are checked, then the connection is pinned to them. Redirects are not followed, the answer is limited to 5 MB and the request to 5 seconds. * A picture that cannot be fetched or read is skipped and tried again at the next sign-in. A provider without a picture changes nothing. Acceptance criteria: * [x] A changed username or email at the provider is applied at the next sign-in. * [x] An email the provider does not vouch for is not applied. * [x] A value that conflicts with another account is skipped and the sign-in succeeds. * [x] Each applied change is in the change log. * [x] The provider's picture becomes the avatar, and is not downloaded again while its URL is the same. * [x] A picture that cannot be fetched, or is not an image, does not stop the sign-in. * [x] Addresses that are not public are never fetched. * [x] Every case is covered by a test, with a real database.