GoogleProvider constructor

GoogleProvider({
  1. required String clientId,
  2. String? clientSecret,
  3. String? redirectUri,
  4. List<String> scopes = const ['openid', 'email', 'profile'],
})

Creates a GoogleProvider.

  • clientId: The OAuth 2.0 client ID from Google Cloud Console.
  • clientSecret: Required for confidential clients (backend / desktop with secret). Omit for mobile PKCE flows.
  • redirectUri: Defaults to the reverse client ID scheme required by native Google OAuth: com.googleusercontent.apps.<clientId>:/oauth2redirect.
  • scopes: OAuth 2.0 scopes to request. Defaults to ['openid', 'email', 'profile'].

Implementation

GoogleProvider({
  required String clientId,
  String? clientSecret,
  String? redirectUri,
  List<String> scopes = const ['openid', 'email', 'profile'],
}) : super(
        config: OAuth2Config(
          providerName: 'google',
          clientId: clientId,
          clientSecret: clientSecret,
          authorizationEndpoint:
              'https://accounts.google.com/o/oauth2/v2/auth',
          tokenEndpoint: 'https://oauth2.googleapis.com/token',
          userInfoEndpoint: 'https://www.googleapis.com/oauth2/v3/userinfo',
          redirectUri: redirectUri ??
              'com.googleusercontent.apps.$clientId:/oauth2redirect',
          scopes: scopes,
          usePkce: true,
          additionalAuthParams: const {
            // Ensures a refresh token is returned on first consent.
            'access_type': 'offline',
            // Forces the consent screen so a refresh token is always issued.
            // Remove 'prompt: consent' after the first sign-in if you store
            // the refresh token and don't want to re-prompt on every login.
            'prompt': 'consent',
          },
          userExtractor: _extractGoogleUser,
        ),
      );