authyra_google
Native Google Sign-In for Authyra, built on google_sign_in 7: Credential Manager on Android, the Google SDK on iOS and macOS, Google Identity Services on the web.
Install
flutter pub add authyra_flutter authyra_google
Then follow the platform setup of google_sign_in. On Android, an ID token is only issued when serverClientId (an OAuth client of type "Web application") is set.
With your backend (recommended)
Google's ID token proves who the user is. Your backend verifies it and returns your session tokens:
import 'package:authyra_google/authyra_google.dart';
GoogleProvider.withExchange(
serverClientId: 'xxxx.apps.googleusercontent.com',
exchange: (credential) async {
// POST credential.idToken to your backend, which verifies it.
final json = await api.signInWithGoogle(credential.idToken);
return AuthSignInResult(
user: AuthUser(id: json['user_id'] as String, email: credential.email),
tokens: AuthTokens.expiringIn(
Duration(seconds: json['expires_in'] as int),
accessToken: json['access_token'] as String,
refreshToken: json['refresh_token'] as String?,
),
);
},
refresh: (refreshToken) => api.refresh(refreshToken), // Your backend.
)
await authyra.signIn('google');
refresh and signOut call your backend. Google's own tokens are never stored as session tokens and never refreshed from the app.
Identity only
GoogleProvider(serverClientId: 'xxxx.apps.googleusercontent.com')
The session carries no tokens; the ID token is in session.providerData['idToken']. Use this to hand the credential to another SDK, such as Firebase or Supabase.
Web
google_sign_in cannot open the Google prompt programmatically on the web. Call signIn when the sign-in screen opens, and render Google's button with renderButton() from package:google_sign_in_web/web_only.dart (add google_sign_in_web to your dependencies); the call completes when the user uses it.
Errors
- The user closes the picker:
SignInCancelledException. - Misconfiguration, missing ID token, network:
SignInFailedException, with a message naming the fix when possible.
License
MIT
Libraries
- authyra_google
- Native Google Sign-In for Authyra.