Skip to content

feat(auth2): Add support for Google account in backwards compatibility package - #3778

Merged
tp merged 2 commits into
serverpod:mainfrom
tp:3451-backwards-compatiblity
Aug 1, 2025
Merged

tp merged 2 commits into
serverpod:mainfrom
tp:3451-backwards-compatiblity

Conversation

@tp

@tp tp commented Jul 10, 2025 •

Copy link
Copy Markdown
Contributor

Adds support for importing Google user identifiers from the legacy auth system, linking the external ID to an existing auth user upon their first Google-based login through the new endpoint.

Relates to #3661

Summary by CodeRabbit

  • New Features

    • Added support for Google account authentication, including endpoints for both standard and backwards-compatible Google login.
    • Introduced logic to import and link legacy Google accounts to current user profiles during authentication.
    • Added administrative tools for managing Google account authentication and linking.
  • Refactor

    • Modularized Google account verification and linking logic for improved maintainability and abstraction.
  • Documentation

    • Improved documentation for handling legacy external user identifiers.
  • Chores

    • Updated dependencies and configuration files to include new authentication modules and ensure compatibility across server and client test setups.

@coderabbitai

coderabbitai Bot commented Jul 10, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change introduces and refactors logic to support backwards compatibility for Google account authentication in the Serverpod auth modules. It adds new methods for importing and cleaning up legacy Google account identifiers, modularizes Google account verification and linking logic into a new admin class, updates exports, and adjusts dependencies and test endpoints to integrate the new Google authentication features.

Changes

Cohort / File(s) Change Summary
Backwards Compatibility Logic
modules/new_serverpod_auth/serverpod_auth_backwards_compatibility/serverpod_auth_backwards_compatibility_server/lib/src/business/auth_backwards_compatibility.dart
Added import for Google account server package, expanded legacy external user identifier documentation, added methods to remove legacy mappings and import Google accounts, extending backwards compatibility for Google account imports and cleanup.
Google Account Admin Business Logic
modules/new_serverpod_auth/serverpod_auth_google_account/serverpod_auth_google_account_server/lib/src/business/google_accounts_admin.dart
Introduced GoogleAccountsAdmin class with methods for finding users by Google ID, verifying Google ID tokens, and linking Google accounts; added GoogleAccountDetails typedef.
Google Account Business Logic Refactor
modules/new_serverpod_auth/serverpod_auth_google_account/serverpod_auth_google_account_server/lib/src/business/google_accounts.dart
Refactored GoogleAccounts to delegate token verification and linking to GoogleAccountsAdmin, removed direct HTTP verification logic and related typedef, introduced static admin and secrets fields.
Exports for Google Account Modules
modules/new_serverpod_auth/serverpod_auth_google_account/serverpod_auth_google_account_server/lib/serverpod_auth_google_account_server.dart,
modules/new_serverpod_auth/serverpod_auth_google/serverpod_auth_google_server/lib/serverpod_auth_google_server.dart
Added exports for admin and endpoint modules to make new business logic and endpoints publicly accessible.
Dependency Updates: Backwards Compatibility and Migration
modules/new_serverpod_auth/serverpod_auth_backwards_compatibility/serverpod_auth_backwards_compatibility_server/pubspec.yaml,
modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/pubspec.yaml,
templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_backwards_compatibility/serverpod_auth_backwards_compatibility_server/pubspec.yaml,
templates/pubspecs/modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/pubspec.yaml
Added or updated dependencies and overrides for Google account auth server modules, replacing or supplementing previous email auth dependencies.
Test Endpoints and Integration
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/endpoints/backwards_compatible_google_acccount_endpoint.dart,
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/endpoints/google_account_endpoint.dart,
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart
Added endpoints for Google account authentication and backwards compatibility import, updated test tools to include new endpoints and adjust type imports, added wrapper classes for new endpoints.
Test and Template Dependency Updates
templates/pubspecs/tests/serverpod_new_auth_test/serverpod_new_auth_test_client/pubspec.yaml,
templates/pubspecs/tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml,
tests/serverpod_new_auth_test/serverpod_new_auth_test_client/pubspec.yaml,
tests/serverpod_new_auth_test/serverpod_new_auth_test_flutter/pubspec.yaml,
tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml
Added or updated dependencies and overrides for Google account and related auth client/server modules in test and template pubspec files.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BackwardsCompatEndpoint as BackwardsCompatiblityGoogleAccountEndpoint
    participant AuthBackCompat as AuthBackwardsCompatibility
    participant GoogleBaseEndpoint as GoogleAccountBaseEndpoint
    participant GoogleAdmin as GoogleAccountsAdmin

    Client->>BackwardsCompatEndpoint: authenticate(idToken)
    BackwardsCompatEndpoint->>AuthBackCompat: importGoogleAccount(session, idToken)
    AuthBackCompat->>GoogleAdmin: fetchAccountDetails(session, idToken)
    GoogleAdmin-->>AuthBackCompat: GoogleAccountDetails
    AuthBackCompat->>GoogleAdmin: findUserByGoogleUserId(...)
    GoogleAdmin-->>AuthBackCompat: userId or null
    AuthBackCompat->>GoogleAdmin: linkGoogleAuthentication(...) (if legacy found)
    GoogleAdmin-->>AuthBackCompat: GoogleAccount
    AuthBackCompat->>AuthBackCompat: clearLegacyExternalUserIdentifier(...) (if needed)
    BackwardsCompatEndpoint->>GoogleBaseEndpoint: authenticate(session, idToken)
    GoogleBaseEndpoint-->>Client: AuthSuccess
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat(auth2): Add helpers for "one stop" migration #3747: Introduces a migration helper framework and a new entity for managing legacy user ID migration across providers, conceptually related to this PR's focus on importing and linking legacy Google account identifiers, though the implementation details and affected classes differ.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tp
tp force-pushed the 3451-backwards-compatiblity branch 10 times, most recently from 49567af to be3267f Compare July 30, 2025 09:18
@tp
tp marked this pull request as ready for review July 30, 2025 10:53
@tp

tp commented Jul 30, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 30, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
modules/new_serverpod_auth/serverpod_auth_google_account/serverpod_auth_google_account_server/lib/src/business/google_accounts_admin.dart (1)

128-128: Email normalization already implemented.

The email is correctly normalized to lowercase as previously suggested.

🧹 Nitpick comments (5)
tests/serverpod_new_auth_test/serverpod_new_auth_test_flutter/pubspec.yaml (1)

25-25: Version range for flutter_lints may be too permissive

>=3.0.0 <7.0.0 accepts yet-to-be-released major versions that could introduce breaking rules and make the analysis unstable. Consider capping at the latest tested major (<4.0.0 or similar) unless you have automatic rule suppression in place.

modules/new_serverpod_auth/serverpod_auth_google/serverpod_auth_google_server/lib/serverpod_auth_google_server.dart (1)

1-1: Publicly exporting the base endpoint widens API surface
Exporting google_account_base_endpoint.dart is convenient but exposes low-level classes to end-users. If the intent is only subclassing inside test code, consider re-exporting with show GoogleAccountBaseEndpoint (or placing it under src/internal) to keep the public API minimal.

tests/serverpod_new_auth_test/serverpod_new_auth_test_server/lib/src/endpoints/google_account_endpoint.dart (1)

1-4: Endpoint stub is fine but add registration comment or remove if unused

The endpoint simply subclasses GoogleAccountBaseEndpoint without additional logic, which is perfectly valid.
However, an empty endpoint typically exists only to be registered in Server.endpoints. Consider adding a comment that clarifies this intent or remove the class if registration is handled elsewhere to avoid dead code confusion.

templates/pubspecs/tests/serverpod_new_auth_test/serverpod_new_auth_test_server/pubspec.yaml (1)

37-40: Duplicate Google overrides between server & client

Both test server and test client override the same Google packages with local paths.
To avoid mismatch, extract these overrides into the root dependency_overrides: of the mono-repo or a shared include, otherwise one file might drift.

templates/pubspecs/tests/serverpod_new_auth_test/serverpod_new_auth_test_client/pubspec.yaml (1)

23-34: Keep override list minimal

Many overrides added but not listed in dependencies: (e.g., serverpod_auth_google_account_client).
If they aren’t imported by tests, the override is redundant noise—consider pruning.

@tp
tp force-pushed the 3451-backwards-compatiblity branch from be3267f to 69a649d Compare July 30, 2025 13:58
@tp
tp requested a review from exaby73 July 31, 2025 08:43
@tp
tp merged commit 9cf356f into serverpod:main Aug 1, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants