This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[google_sign_in] Move plugin to its subdir to allow for federated implementations #2244
Merged
ditman
merged 7 commits into
flutter-team-archive:master
from
ditman:federated_google_sign_in
Nov 11, 2019
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
778860b
Move google_sign_in to google_sign_in/google_sign_in
ditman 4fdbdda
Update docs
ditman eaa78d4
Add the google_sign_in_platform_interface package.
ditman f0b24d9
Address PR feedback
ditman 95013af
Appease linter
ditman 784e8bf
Add copyright headers
ditman 52f2c99
Lower flutter version to match native plugin.
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/google_sign_in/CHANGELOG.md → ...oogle_sign_in/google_sign_in/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
27
packages/google_sign_in/google_sign_in_platform_interface/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
26 changes: 26 additions & 0 deletions
26
packages/google_sign_in/google_sign_in_platform_interface/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
109 changes: 109 additions & 0 deletions
109
...ogle_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.'); | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...ogle_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}, | ||
| ); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
packages/google_sign_in/google_sign_in_platform_interface/lib/src/utils.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'], | ||
| ); | ||
| } |
22 changes: 22 additions & 0 deletions
22
packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 <flutter-dev@googlegroups.com> | ||
| 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.9.1+hotfix.4 <2.0.0" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.