Skip to content

added support for updating user Oauth2 avatars via updateSession method - #13671

Merged
Meldiron merged 6 commits into
appwrite:mainfrom
imtia33:feat/oauth-avatar-session-refresh
Sep 21, 2026
Merged

Meldiron merged 6 commits into
appwrite:mainfrom
imtia33:feat/oauth-avatar-session-refresh

Conversation

@imtia33

@imtia33 imtia33 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for refetching and updating the user's OAuth2 profile photo (identities.photo) during the updateSession (PATCH /v1/account/sessions/:sessionId) endpoint.

Motivation

Some OAuth2 providers issue rolling or temporary CDN image links for user avatars that expire after a certain duration. While initial OAuth logins populate identities.photo, calling updateSession previously only refreshed the provider access tokens without updating the stored profile picture URL.

This PR updates updateSession so that whenever an OAuth session is refreshed:

  1. The matching identity document for the session (provider and providerUid) is located.
  2. $oauth2->getUserPhoto($accessToken) is called to refetch the latest avatar URL.
  3. The identities document's photo attribute is updated in the database.

Because OAuth2::getUserPhoto() safely returns '' by default when un-overridden, this feature handles all OAuth2 providers universally without provider-specific logic.

Test Plan

  1. Expanded OAuth2 Mock Endpoints (app/controllers/mock.php):

    • Configured grant_type === 'refresh_token' mock endpoint to return a refreshed access token (refreshed-123456).
    • Added a mock handler for refreshed-123456 returning a refreshed photo URL (/v1/mock/tests/general/oauth2/photo-refreshed).
    • Added a mock image endpoint (/v1/mock/tests/general/oauth2/photo-refreshed) serving a refreshed profile picture.
  2. Expanded E2E Tests (tests/e2e/Services/Account/AccountCustomClientTest.php):

    • Expanded AccountCustomClientTest::testOAuth2 to verify that executing PATCH /account/sessions/current updates the provider access token to refreshed-123456.
    • Added assertions to verify that GET /avatars/photo successfully resolves the updated photo from the refreshed identity document.
  3. Automated Verification:

    • Ran E2E suite inside the container:
      docker compose exec appwrite vendor/bin/phpunit tests/e2e/Services/Account/AccountCustomClientTest.php --filter=testOAuth2
    • Result: OK (1 test, 30 assertions).

Related PRs and Issues

  • N/A

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (N/A - No API parameters or response models were altered).

@greptile-apps

greptile-apps Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with both previous findings resolved and no new actionable failures identified.

Summary

This PR extends OAuth2 session refreshes to retrieve and persist the provider’s latest profile photo.

  • Locates the refreshed session’s identity by provider and provider UID.
  • Updates the identity photo without allowing photo-related failures to block token refresh.
  • Expands the OAuth2 mock to serve observably different initial and refreshed avatars.
  • Verifies through the public avatar endpoint that the returned image content changes after refreshing the session.

Reviews (5) · Last reviewed commit: "Merge branch 'main' into feat/oauth-avat..."

Comment thread app/controllers/api/account.php Resolved
@imtia33

imtia33 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

the failed checks introduced after merging main branch into this PR .
so no changes required from here.

@Meldiron
Meldiron merged commit ec5517a into appwrite:main Sep 21, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants