Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.12

* Move google_sign_in plugin to google_sign_in/google_sign_in to prepare for federated implementations.

## 4.0.11

* Update iOS CocoaPod dependency to 5.0 to fix deprecated API usage issue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ Future<void> _handleSignIn() async {

## Example

Find the example wiring in the [Google sign-in example application](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/example/lib/main.dart).
Find the example wiring in the [Google sign-in example application](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/google_sign_in/example/lib/main.dart).

## API details

See the [google_sign_in.dart](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/lib/google_sign_in.dart) for more API details.
See the [google_sign_in.dart](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart) for more API details.

## Issues and feedback

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
version: 4.0.11
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.0.12

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

* Initial release.
27 changes: 27 additions & 0 deletions packages/google_sign_in/google_sign_in_platform_interface/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# google_sign_in_platform_interface

A common platform interface for the [`google_sign_in`][1] plugin.

This interface allows platform-specific implementations of the `google_sign_in`
plugin, as well as the plugin itself, to ensure they are supporting the
same interface.

# Usage

To implement a new platform-specific implementation of `google_sign_in`, extend
[`GoogleSignInPlatform`][2] with an implementation that performs the
platform-specific behavior, and when you register your plugin, set the default
`GoogleSignInPlatform` by calling
`GoogleSignInPlatform.instance = MyPlatformGoogleSignIn()`.

# Note on breaking changes

Strongly prefer non-breaking changes (such as adding a method to the interface)
over breaking changes for this package.

See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
on why a less-clean interface is preferable to a breaking change.

[1]: ../google_sign_in
[2]: lib/google_sign_in_platform_interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'package:meta/meta.dart' show required, visibleForTesting;
import 'src/method_channel_google_sign_in.dart';
import 'src/types.dart';

export 'src/method_channel_google_sign_in.dart';
export 'src/types.dart';

/// The interface that implementations of google_sign_in must implement.
///
/// Platform implementations that live in a separate package should extend this
/// class rather than implement it as `google_sign_in` does not consider newly
/// added methods to be breaking changes. Extending this class (using `extends`)
/// ensures that the subclass will get the default implementation, while
/// platform implementations that `implements` this interface will be broken by
/// newly added [GoogleSignInPlatform] methods.
abstract class GoogleSignInPlatform {
/// Only mock implementations should set this to `true`.
///
/// Mockito mocks implement this class with `implements` which is forbidden
/// (see class docs). This property provides a backdoor for mocks to skip the
/// verification that the class isn't implemented with `implements`.
@visibleForTesting
bool get isMock => false;

/// The default instance of [GoogleSignInPlatform] to use.
///
/// Platform-specific plugins should override this with their own
/// platform-specific class that extends [GoogleSignInPlatform] when they
/// register themselves.
///
/// Defaults to [MethodChannelGoogleSignIn].
static GoogleSignInPlatform get instance => _instance;

static GoogleSignInPlatform _instance = MethodChannelGoogleSignIn();

// TODO(amirh): Extract common platform interface logic.
// https://github.com/flutter/flutter/issues/43368
static set instance(GoogleSignInPlatform instance) {
if (!instance.isMock) {
try {
instance._verifyProvidesDefaultImplementations();
} on NoSuchMethodError catch (_) {
throw AssertionError(
'Platform interfaces must not be implemented with `implements`');
}
}
_instance = instance;
}

/// This method ensures that [GoogleSignInPlatform] isn't implemented with `implements`.
///
/// See class docs for more details on why using `implements` to implement
/// [GoogleSignInPlatform] is forbidden.
///
/// This private method is called by the [instance] setter, which should fail
/// if the provided instance is a class implemented with `implements`.
void _verifyProvidesDefaultImplementations() {}

/// Initializes the plugin. You must call this method before calling other methods.
/// See: https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
Future<void> init(
{@required String hostedDomain,
List<String> scopes,
SignInOption signInOption,
String clientId}) async {
throw UnimplementedError('init() has not been implemented.');
}

/// Attempts to reuse pre-existing credentials to sign in again, without user interaction.
Future<GoogleSignInUserData> signInSilently() async {
throw UnimplementedError('signInSilently() has not been implemented.');
}

/// Signs in the user with the options specified to [init].
Future<GoogleSignInUserData> signIn() async {
throw UnimplementedError('signIn() has not been implemented.');
}

/// Returns the Tokens used to authenticate other API calls.
Future<GoogleSignInTokenData> getTokens(
{@required String email, bool shouldRecoverAuth}) async {
throw UnimplementedError('getTokens() has not been implemented.');
}

/// Signs out the current account from the application.
Future<void> signOut() async {
throw UnimplementedError('signOut() has not been implemented.');
}

/// Revokes all of the scopes that the user granted.
Future<void> disconnect() async {
throw UnimplementedError('disconnect() has not been implemented.');
}

/// Returns whether the current user is currently signed in.
Future<bool> isSignedIn() async {
throw UnimplementedError('isSignedIn() has not been implemented.');
}

/// Clears any cached information that the plugin may be holding on to.
Future<void> clearAuthCache({@required String token}) async {
throw UnimplementedError('clearAuthCache() has not been implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:meta/meta.dart' show required, visibleForTesting;

import '../google_sign_in_platform_interface.dart';
import 'types.dart';
import 'utils.dart';

/// An implementation of [GoogleSignInPlatform] that uses method channels.
class MethodChannelGoogleSignIn extends GoogleSignInPlatform {
@visibleForTesting
MethodChannel channel =
const MethodChannel('plugins.flutter.io/google_sign_in');

@override
Future<void> init(
{@required String hostedDomain,
List<String> scopes = const <String>[],
SignInOption signInOption = SignInOption.standard,
String clientId}) {
return channel.invokeMethod<void>('init', <String, dynamic>{
'signInOption': signInOption.toString(),
'scopes': scopes,
'hostedDomain': hostedDomain,
});
}

@override
Future<GoogleSignInUserData> signInSilently() {
return channel
.invokeMapMethod<String, dynamic>('signInSilently')
.then(getUserDataFromMap);
}

@override
Future<GoogleSignInUserData> signIn() {
return channel
.invokeMapMethod<String, dynamic>('signIn')
.then(getUserDataFromMap);
}

@override
Future<GoogleSignInTokenData> getTokens(
{String email, bool shouldRecoverAuth = true}) {
return channel
.invokeMapMethod<String, dynamic>('getTokens', <String, dynamic>{
'email': email,
'shouldRecoverAuth': shouldRecoverAuth,
}).then(getTokenDataFromMap);
}

@override
Future<void> signOut() {
return channel.invokeMapMethod<String, dynamic>('signOut');
}

@override
Future<void> disconnect() {
return channel.invokeMapMethod<String, dynamic>('disconnect');
}

@override
Future<bool> isSignedIn() {
return channel.invokeMethod<bool>('isSignedIn');
}

@override
Future<void> clearAuthCache({String token}) {
return channel.invokeMethod<void>(
'clearAuthCache',
<String, String>{'token': token},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:quiver_hashcode/hashcode.dart';

enum SignInOption { standard, games }

class GoogleSignInUserData {
GoogleSignInUserData(
{this.displayName, this.email, this.id, this.photoUrl, this.idToken});
String displayName;
String email;
String id;
String photoUrl;
String idToken;

@override
int get hashCode =>
hashObjects(<String>[displayName, email, id, photoUrl, idToken]);

@override
bool operator ==(dynamic other) {
if (identical(this, other)) return true;
if (other is! GoogleSignInUserData) return false;
final GoogleSignInUserData otherUserData = other;
return otherUserData.displayName == displayName &&
otherUserData.email == email &&
otherUserData.id == id &&
otherUserData.photoUrl == photoUrl &&
otherUserData.idToken == idToken;
}
}

class GoogleSignInTokenData {
GoogleSignInTokenData({this.idToken, this.accessToken});
String idToken;
String accessToken;

@override
int get hashCode => hash2(idToken, accessToken);

@override
bool operator ==(dynamic other) {
if (identical(this, other)) return true;
if (other is! GoogleSignInTokenData) return false;
final GoogleSignInTokenData otherTokenData = other;
return otherTokenData.idToken == idToken &&
otherTokenData.accessToken == accessToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../google_sign_in_platform_interface.dart';

/// Converts user data coming from native code into the proper platform interface type.
GoogleSignInUserData getUserDataFromMap(Map<String, dynamic> data) {
if (data == null) {
return null;
}
return GoogleSignInUserData(
displayName: data['displayName'],
email: data['email'],
id: data['id'],
photoUrl: data['photoUrl'],
idToken: data['idToken']);
}

/// Converts token data coming from native code into the proper platform interface type.
GoogleSignInTokenData getTokenDataFromMap(Map<String, dynamic> data) {
if (data == null) {
return null;
}
return GoogleSignInTokenData(
idToken: data['idToken'],
accessToken: data['accessToken'],
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: google_sign_in_platform_interface
description: A common platform interface for the google_sign_in plugin.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.0

dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
quiver_hashcode: ^2.0.0

dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.1.1

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"
Loading