google_identity_services_web 0.1.1 copy "google_identity_services_web: ^0.1.1" to clipboard
google_identity_services_web: ^0.1.1 copied to clipboard

outdated

A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.

example/lib/main.dart

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_print

import 'package:google_identity_services_web/id.dart' as id;
// #docregion use-loader
import 'package:google_identity_services_web/loader.dart' as gis;
// #enddocregion use-loader
import 'package:js/js.dart' show allowInterop;
import 'package:jwt_decoder/jwt_decoder.dart' as jwt;

// #docregion use-loader
void main() async {
  await gis.loadWebSdk(); // Load the GIS SDK
  // The rest of your code...
// #enddocregion use-loader
  id.setLogLevel('debug');

  final id.IdConfiguration config = id.IdConfiguration(
    client_id: 'your-client_id.apps.googleusercontent.com',
    ux_mode: id.UxMode.popup,
    callback: allowInterop(onCredentialResponse),
  );

  id.initialize(config);
  id.prompt(allowInterop(onPromptMoment));
// #docregion use-loader
}
// #enddocregion use-loader

/// Handles the ID token returned from the One Tap prompt.
/// See: https://developers.google.com/identity/gsi/web/reference/js-reference#callback
void onCredentialResponse(id.CredentialResponse o) {
  final Map<String, dynamic>? payload = jwt.JwtDecoder.tryDecode(o.credential);
  if (payload != null) {
    print('Hello, ${payload["name"]}');
    print(o.select_by);
    print(payload);
  } else {
    print('Could not decode ${o.credential}');
  }
}

/// Handles Prompt UI status notifications.
/// See: https://developers.google.com/identity/gsi/web/reference/js-reference#google.accounts.id.prompt
void onPromptMoment(id.PromptMomentNotification o) {
  final id.MomentType type = o.getMomentType();
  print(type.runtimeType);
  print(type);
  print(type.index);
  print(o.getDismissedReason());
  print(o.getNotDisplayedReason());
  print(o.getSkippedReason());
}
2
likes
0
pub points
94%
popularity

Publisher

verified publisherflutter.dev

A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

js, meta

More

Packages that depend on google_identity_services_web