Piano ID SDK (Google) for Flutter

Google sign-in for piano_id: PianoIDGoogleOAuthProvider is the PianoIDOAuthProvider behind the Google button on the Piano ID sign-in screen.

Installation

Add the dependency to your pubspec.yaml:

dependencies:
  piano_id: ^1.0.8
  piano_id_google: ^1.0.8

The provider signs in through google_sign_in, so your application still needs that package's platform setup:

  • Android — register your app's package name and signing-key SHA-1 with the Google Cloud project of the credentials Piano ID uses. No client id goes into the app.
  • iOS — add GIDClientID (your iOS OAuth client id) and the matching URL scheme to Info.plist, or pass the client id as googleClientId.

See the google_sign_in platform integration guide for the details.

Usage

List the provider in the Piano ID configuration:

import 'package:piano_common/piano_common.dart';
import 'package:piano_id/piano_id.dart';
import 'package:piano_id_google/piano_id_google.dart';

final piano = await Piano.init(
  endpoint: PianoEndpoint.production,
  aid: '<AID>',
  configurations: [
    PianoIDConfiguration(providers: [PianoIDGoogleOAuthProvider()]),
  ],
);

// The sign-in screen now shows a Google button; picking it signs the user in
// with Google and finishes the Piano ID sign-in with the resulting token.
final token = await piano.id().signIn(context: context);

Nothing else is needed: Piano ID supplies the client id of its own Google credentials, and the provider requests an ID token issued for it. A user who dismisses the Google UI leaves the sign-in screen open, so another way to sign in can be picked.

Configuration

PianoIDGoogleOAuthProvider(
  // Your application's own Google OAuth client id. Unused on Android; read
  // from `GIDClientID` in `Info.plist` on iOS when omitted.
  googleClientId: '<IOS_CLIENT_ID>',
  // Set to false when your application calls `GoogleSignIn.instance.initialize`
  // itself — it may only run once in a process.
  initializeGoogleSignIn: false,
)

The client id the ID token is issued for is always the one Piano ID supplies, since that is what Piano ID verifies the token against.

google_sign_in is initialized once per process, and every provider built in it shares that initialization — so a second Piano instance costs nothing as long as Piano ID supplies it the same Google client id. A sign-in that would need a different one is refused with a PianoException rather than initializing again, which google_sign_in leaves undefined; pass initializeGoogleSignIn: false and initialize the package yourself to decide what the process signs in against.

Libraries

piano_id_google