GoogleWebSignInService class

Service to manage Google OAuth sign-in on the web platform.

Handles the OAuth 2.0 authorization code flow with PKCE (Proof Key for Code Exchange) for Google authentication on web. Uses flutter_web_auth_2 to open the browser to Google's authorization page and capture the callback via window.postMessage.

This service is intended for web only. On native platforms (iOS, Android, macOS), use GoogleSignInService with the google_sign_in package instead. The GoogleAuthController dispatches to this service automatically when running on web.

Example usage:

// Initialize once during app startup (web only)
await client.auth.initializeGoogleSignIn(
  clientId: 'your-client-id.apps.googleusercontent.com',
  redirectUri: 'https://yourdomain.com/auth.html',
);

// Sign in
final result = await GoogleWebSignInService.instance.signIn();

// Send result to backend
await endpoint.loginWithCode(
  code: result.code,
  codeVerifier: result.codeVerifier,
  redirectUri: result.redirectUri,
);

Properties

hashCode → int
The hash code for this object.
no setterinherited
isInitialized → bool
Whether the service has been initialized with a redirect URI.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

ensureInitialized({required String clientId, required String redirectUri, String? callbackUrlScheme, bool? useWebview, Map<String, String> additionalAuthParams = const {}}) → Future<void>
Ensures that Google web sign-in is initialized.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
signIn({List<String>? scopes}) → Future<GoogleWebSignInResult>
Starts the Google web OAuth sign-in flow using PKCE.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

instance → GoogleWebSignInService
Singleton instance of the GoogleWebSignInService.
final

Constants

defaultScopes → const List<String>
Default OAuth scopes for Google sign-in.