Skip to content

feat: Add serverpod_auth_idp_flutter with Google Sign-In IDP implementation - #4150

Merged
marcelomendoncasoares merged 22 commits into
serverpod:mainfrom
marcelomendoncasoares:google-idp-flutter
Nov 6, 2025
Merged

marcelomendoncasoares merged 22 commits into
serverpod:mainfrom
marcelomendoncasoares:google-idp-flutter

Conversation

@marcelomendoncasoares

@marcelomendoncasoares marcelomendoncasoares commented Nov 4, 2025 •

Copy link
Copy Markdown
Collaborator

Closes #3646.
Closes #3451.

This package introduces the serverpod_auth_idp_flutter package, which provides Flutter widgets for integrating third-party identity providers (IdPs). The initial release includes only Google Sign-In support.

To develop and test IDP widgets, the package contains a storybook app that demonstrates the available widgets and their configurations.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None.

Summary by CodeRabbit

  • New Features

    • Added Google Sign-In support for Flutter applications with native and web button variants
    • Introduced user profile display and management UI components
    • Added authentication session management with device sign-out capabilities
    • Implemented Google account disconnection functionality
  • Documentation

    • Added comprehensive Google Sign-In setup guides for web, iOS, and Android platforms
  • Chores

    • Updated project dependencies and configuration for authentication modules

@coderabbitai

coderabbitai Bot commented Nov 4, 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 PR introduces a new Flutter package serverpod_auth_idp_flutter for Identity Provider (IDP) authentication, adds Google Sign-In UI components and token verification, updates existing auth endpoints, and expands the authentication example app with profile management and improved setup documentation.

Changes

Cohort / File(s) Summary
New Flutter IDP Package – Root & Config
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/{.gitignore, .metadata, CHANGELOG.md, LICENSE, README.md, analysis_options.yaml, pubspec.yaml, lib/serverpod_auth_idp_flutter.dart, lib/widgets.dart}
Scaffolds a new Flutter package for IDP authentication with standard project files, linting config, and core library exports for Google auth and UI widgets.
Google Auth Controller & Service
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/google/{google_auth_controller.dart, google_sign_in_service.dart}
Implements GoogleAuthController state machine managing Google Sign-In lifecycle, server-side token exchange, and GoogleSignInService singleton for idempotent initialization with client integration.
Google Sign-In Widgets – Base & Native
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/google/{common/button.dart, common/style.dart, native/button.dart, native/icon.dart, google_sign_in_widget.dart}
Provides configurable Google Sign-In button base class with style factory, platform-specific native button with multiple variants (filled, outlined, elevated), icon component with loading/disabled states, and bridge widget selecting native or web button.
Google Sign-In Web Widgets
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/google/web/{button.dart, wrapper.dart, wrapper_stub.dart, wrapper_web.dart}
Implements web-specific button rendering with conditional imports; stub provides enum definitions for non-web platforms; web variant exports google_sign_in_web.
Common UI Widgets & Utilities
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/common/widgets/{column.dart, divider.dart, gaps.dart}
Exports spacing constants (smallGap, largeGap), expandable divider, and constrained column layout widget for sign-in form composition.
Sign-In & Provider Components
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/{sign_in_widget.dart, providers.dart}
Orchestrates available IDP options and renders corresponding sign-in widgets; AvailableIDPs class inspects server endpoints for provider availability.
Storybook Demo App
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/storybook/{.gitignore, .metadata, README.md, analysis_options.yaml, lib/main.dart, lib/stories/google.dart, lib/utils/{client.dart, story.dart}, pubspec.yaml, web/{index.html, manifest.json}}
Adds Storybook setup for visual testing of Google Sign-In button variants and states with mock client for offline development.
Server-side Google IDP Updates
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/{business/{google_idp.dart, google_idp_admin.dart, google_idp_config.dart, google_idp_token_verifier.dart, google_idp_utils.dart}, endpoints/google_idp_base_endpoint.dart, models/google_id_token_verification_exception.spy.yaml}
Adds accessToken parameter to Google login flows; implements GoogleIdTokenVerifier with JWKS caching for offline token validation; updates utils to use new token verifier and access user info via Bearer token.
Core Auth Endpoint Restructuring
modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/lib/src/profile/endpoints/user_profile_base_endpoint.dart
Splits monolithic UserProfileBaseEndpoint into UserProfileInfoEndpoint (read-only with concrete get method) and UserProfileEditBaseEndpoint (extends read-only, contains mutating methods).
Auth Backwards Compatibility
modules/new_serverpod_auth/serverpod_auth_bridge/serverpod_auth_bridge_server/lib/src/business/auth_backwards_compatibility.dart
Adds required accessToken parameter to importGoogleAccount method.
IDP Client Export
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_client/lib/serverpod_auth_idp_client.dart
Re-exports protocol client definitions.
Example App – Flutter
examples/auth/auth_flutter/{.gitignore, README.md, lib/main.dart, lib/widgets/{profile_info.dart, profile_picture.dart}, pubspec.yaml, web/index.html}
Refactors auth example with new architecture; adds ProfileWidget and ProfilePictureWidget for user display; updates imports and dependencies for Google IDP and extended_image; expands README with web/iOS/Android setup steps.
Example Server Configuration
examples/auth/auth_server/config/template.passwords.yaml
Adds template fields for Google, Apple, and email/password authentication configuration.
Test Infrastructure Updates
modules/new_serverpod_auth/serverpod_auth_core/serverpod_auth_core_server/test/serverpod_test_tools.dart, tests/serverpod_new_auth_test/serverpod_new_auth_test_server/{lib/src/endpoints/{google_account_backwards_compatibility_test_endpoint.dart, user_profile_endpoint.dart}, test/integration/test_tools/serverpod_test_tools.dart}
Updates TestEndpoints with UserProfileInfoEndpoint; adds accessToken to Google account test endpoints; refactors user profile endpoint methods to match new base structure.
Configuration & Build Files
PUBLISHABLE_PACKAGES, util/{all_packages, update_pubspecs}, templates/pubspecs/..., .gitignore
Adds serverpod_auth_idp_flutter to published packages list; extends build utilities and template pubspecs; adds devtools_options.yaml to repository-wide ignore.

Sequence Diagram(s)

sequenceDiagram
    participant App as Flutter App
    participant Ctrl as GoogleAuthController
    participant GIS as GoogleSignInService
    participant Endpoint as Google IDP Endpoint
    participant Verifier as GoogleIdTokenVerifier
    participant Server as Serverpod Server

    App->>Ctrl: signIn()
    Ctrl->>GIS: ensureInitialized()
    GIS->>GIS: GoogleSignIn.initialize()
    Ctrl->>Ctrl: _handleAuthenticationEvent()
    Ctrl->>Endpoint: login(idToken, accessToken)
    Endpoint->>Server: Call server endpoint
    Server->>Verifier: verifyOAuth2Token(idToken)
    Verifier->>Verifier: Fetch JWKS, verify signature
    Verifier->>Server: Return token payload
    Server->>Server: Fetch user info (via accessToken)
    Server->>Server: Create/update user session
    Server->>Endpoint: Return AuthSuccess
    Endpoint->>Ctrl: onAuthenticated callback
    Ctrl->>App: Update state to authenticated
Loading
sequenceDiagram
    participant UI as UI Layer
    participant SignInWidget as SignInWidget
    participant AvailableIDPs as AvailableIDPs
    participant Endpoint as Server Endpoint
    
    UI->>SignInWidget: render(client)
    SignInWidget->>AvailableIDPs: check provider availability
    AvailableIDPs->>Endpoint: reflect() inspect endpoints
    Endpoint->>AvailableIDPs: return endpoint metadata
    AvailableIDPs->>SignInWidget: hasGoogle=true, hasEmail=false
    SignInWidget->>UI: render GoogleSignInWidget only
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Areas requiring extra attention:

  • GoogleIdTokenVerifier (token_verifier.dart) — JWT validation logic with JWKS caching, clock skew handling, and error recovery strategies; requires careful verification of signature validation and claims checking.
  • Google IDP utilities (google_idp_utils.dart) — Updated authentication flow with token verification integration and user info fetching via Bearer token; confirm consistency with prior authentication paths.
  • GoogleAuthController & service integration — State machine transitions, listener wiring, and server-side token exchange coordination; verify proper lifecycle management and edge case handling.
  • UI widget composition — Multiple button variants across native/web platforms with style factory; verify button styling consistency and responsive layout behavior.
  • Profile endpoint restructuring — Split from monolithic base into read-only and edit variants; confirm test coverage reflects new inheritance hierarchy and all dependent code is updated.
  • Test infrastructure updates — Multiple test tool refactors with endpoint method reordering and signature changes; verify all test paths exercise the new parameter flows correctly.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main addition: a new Flutter package for Google Sign-In IDP implementation.
Description check ✅ Passed The description is mostly complete with issue references, feature explanation, and a pre-launch checklist. However, the new tests checkbox is unchecked while the author claims all tests pass, creating ambiguity about test coverage.
Linked Issues check ✅ Passed The PR delivers the core objectives from #3646 (Flutter package for Google Sign-In) and #3451 (Google authentication module with IDP support). The implementation includes Google Sign-In widgets, authentication controller, and UI components that enable Flutter-side integration with the new IDP system.
Out of Scope Changes check ✅ Passed All changes directly support the two linked issues: the new Flutter package, Google Sign-In widgets, authentication flow implementation, example app updates, and supporting infrastructure are all within scope. Minor unrelated updates to .gitignore and configuration files are negligible.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@marcelomendoncasoares

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review.

@coderabbitai

coderabbitai Bot commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

@marcelomendoncasoares: I'll perform a full review of the PR changes for the new serverpod_auth_idp_flutter package with Google Sign-In IDP implementation.


🧠 Learnings used
Learnt from: SandPod
Repo: serverpod/serverpod PR: 4144
File: modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/passkey/endpoints/passkey_idp_base_endpoint.dart:0-0
Timestamp: 2025-11-03T15:40:41.827Z
Learning: In Serverpod authentication IDP endpoint files (modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server), endpoint base classes should import `serverpod_auth_idp_server/core.dart` to access the Session type, rather than importing `package:serverpod_auth_core_server/session.dart` directly. This pattern is consistently used in Apple, Email, and Google endpoint files.

Learnt from: tp
Repo: serverpod/serverpod PR: 3787
File: modules/new_serverpod_auth/serverpod_auth_apple_account/serverpod_auth_apple_account_server/pubspec.yaml:18-18
Timestamp: 2025-07-15T13:38:58.183Z
Learning: For Sign in with Apple authentication, there are two distinct packages: `sign_in_with_apple` is the client-side package for mobile apps, while `sign_in_with_apple_server` is a server-side utility package for handling Sign in with Apple tokens and validation on Dart servers.

Learnt from: tp
Repo: serverpod/serverpod PR: 3747
File: modules/new_serverpod_auth/serverpod_auth_migration/serverpod_auth_migration_server/lib/src/business/migrating_email_endpoint_base.dart:4-4
Timestamp: 2025-07-02T16:07:50.947Z
Learning: In Serverpod, tp prefers importing the full package (e.g., 'package:serverpod_auth_migration_server/serverpod_auth_migration_server.dart') as a baseline rather than using smaller local imports, even within the same package where it might be considered a "self-import".

Learnt from: tp
Repo: serverpod/serverpod PR: 3777
File: modules/new_serverpod_auth/serverpod_auth_google_account/serverpod_auth_google_account_server/lib/src/business/google_accounts.dart:126-138
Timestamp: 2025-07-10T12:33:42.871Z
Learning: In Serverpod Google authentication, tp prefers a flexible field validation approach: only require user ID always, require email only on first-time sign-ups (and make this configurable), and make other profile fields optional. If apps don't want to collect emails, the system shouldn't rely on the verified_email attribute. This allows apps to have configurable data collection policies.
✅ 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: 9

🧹 Nitpick comments (8)
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_server/lib/src/providers/google/business/google_idp_config.dart (1)

69-77: LGTM! Correct type safety fix for JSON deserialization.

The change from as List<String>? to as List<dynamic>? with a subsequent .cast<String>() correctly handles JSON deserialization in Dart, where arrays are decoded as List<dynamic> rather than typed lists. This fix ensures the code passes strict Dart analysis.

Optional: Consider more explicit validation for consistency.

For consistency with other validation in this method that throws FormatException, you could optionally add explicit element validation before casting:

final webRedirectUris = web['redirect_uris'] as List<dynamic>?;
if (webRedirectUris == null) {
  throw const FormatException('Missing "redirect_uris"');
}
if (webRedirectUris.any((uri) => uri is! String)) {
  throw const FormatException('Invalid "redirect_uris": all elements must be strings');
}

return GoogleClientSecret._(
  clientId: webClientId,
  clientSecret: webClientSecret,
  redirectUris: webRedirectUris.cast<String>(),
);

This would provide more consistent error messages, though the current approach is acceptable since .cast<String>() will throw a clear error if non-string elements are present.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/README.md (1)

1-9: Consider adding package-specific documentation.

The README contains generic Serverpod boilerplate but doesn't describe what the serverpod_auth_idp_flutter package provides (e.g., Flutter widgets for Google Sign-In and other identity providers). Package-specific documentation would help developers understand the purpose and usage of this package.

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/storybook/web/index.html (2)

23-25: Consider documenting the Google client ID setup requirement.

The placeholder GOOGLE_CLIENT_ID.apps.googleusercontent.com in the meta tag will likely cause Google Sign-In to fail at runtime if not replaced. While the comment instructs developers to replace this value, consider:

  1. Adding a more prominent warning or error handling when the placeholder is detected
  2. Documenting the setup steps in a README for the storybook app
  3. Potentially using an environment variable or configuration file approach

21-21: Consider updating the meta description.

The generic description "A new Flutter project" could be more specific, such as "Serverpod Auth IDP Flutter Storybook - UI component examples for Google Sign-In integration."

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/storybook/web/manifest.json (1)

8-8: Consider a more descriptive description.

The description "A new Flutter project." is generic. Consider something more specific like "Serverpod Auth IDP Storybook - Component showcase for authentication widgets."

modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/common/widgets/column.dart (1)

24-27: Clarify the assertion error message.

The assertion checks width > 0, which excludes 0, but the error message says "between 0 and 400" which could be interpreted as including 0. Consider making the message more explicit.

Apply this diff to clarify the message:

   }) : assert(
          width > 0 && width <= 400,
-          'Invalid width. Must be between 0 and 400.',
+          'Invalid width. Must be greater than 0 and at most 400.',
        );
examples/auth/auth_flutter/lib/widgets/profile_picture.dart (1)

29-29: Consider increasing the default size.

The default size of 20.0 seems quite small for a profile picture. Typical profile pictures are usually at least 40-50 pixels to be clearly visible.

-    this.size = 20.0,
+    this.size = 40.0,
modules/new_serverpod_auth/serverpod_auth_idp/serverpod_auth_idp_flutter/lib/src/sign_in_widget.dart (1)

89-89: Separator condition is currently unreachable.

The separator on line 89 will never render because:

  • The email widget above it is commented out
  • Without the email widget, the separator doesn't make sense visually
  • The condition requires both count > 1 and hasEmail, but no email UI is present

This is expected given the TODO comments, but consider removing this line until the email widget is implemented to avoid confusion.

-        if (auth.idp.count > 1 && auth.idp.hasEmail) const _SignInSeparator(),
+        // TODO: Add separator when email widget is implemented
+        // if (auth.idp.count > 1 && auth.idp.hasEmail) const _SignInSeparator(),

Comment thread examples/auth/auth_flutter/README.md Resolved

@SandPod SandPod 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.

Minor comments + last suggestions from our call.

@SandPod SandPod 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.

LGTM! 🚀

@marcelomendoncasoares
marcelomendoncasoares merged commit 90a8a27 into serverpod:main Nov 6, 2025
@marcelomendoncasoares
marcelomendoncasoares deleted the google-idp-flutter branch November 6, 2025 02:03
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 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.

Add Flutter package for new Google authentication module Create Google authentication module

2 participants