Fetch and store Google profile pictures in Kaneo avatar storage on sign-in
OpenAuthenticationAndreas Michael ·
Summary
When signing in with Google, automatically fetch the user's Google profile picture and store it in Kaneo's built-in avatar storage (/api/user/avatar/:id).
Motivation
- Existing accounts that sign in with Google (for example, accounts originally created via email verification code or password) do not automatically get their Google profile picture set.
- Storing the fetched image in Kaneo's
user_avatarstorage (/api/user/avatar/:id) rather than referencing an externalgoogleusercontent.comURL keeps avatars self-contained in the database, avoids external third-party image requests/rate limits, and works consistently across web and mobile clients.
Proposed behavior
- On Google sign-in (and account linking), extract the
pictureURL from the Google ID token (falling back to Google's OIDCuserinfoendpoint if omitted). - Download and validate the image (HTTPS Google avatar host check, size limit, and MIME/magic-byte validation) and store it in
user_avatar. - Update the stored Google avatar on subsequent Google sign-ins if the picture has changed, without rotating the avatar ID when the image bytes are unchanged.
- Never overwrite a custom avatar that the user manually uploaded in Kaneo settings.