Skip to content

Commit

Permalink
[google_sign_in] Add forceCodeForRefreshToken parameter (and new Sign…
Browse files Browse the repository at this point in the history
…InInitParameters class) (flutter#5325)
  • Loading branch information
fbcouch authored and mauricioluz committed Jan 26, 2023
1 parent 797ccc0 commit 5f9577b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <[email protected]>
Anton Borries <[email protected]>
Alex Li <[email protected]>
Rahul Raj <[email protected]>
Twin Sun, LLC <[email protected]>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.1.3

* Removes unnecessary imports.
* Adds `SignInInitParameters` class to hold all sign in params, including the new `forceCodeForRefreshToken`.

## 2.1.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ abstract class GoogleSignInPlatform {
/// if the provided instance is a class implemented with `implements`.
void _verifyProvidesDefaultImplementations() {}

/// Initializes the plugin. You must call this method before calling other
/// methods.
/// Initializes the plugin. Deprecated: call [initWithParams] instead.
///
/// The [hostedDomain] argument specifies a hosted domain restriction. By
/// setting this, sign in will be restricted to accounts of the user in the
Expand All @@ -89,6 +88,21 @@ abstract class GoogleSignInPlatform {
throw UnimplementedError('init() has not been implemented.');
}

/// Initializes the plugin with specified [params]. You must call this method
/// before calling other methods.
///
/// See:
///
/// * [SignInInitParameters]
Future<void> initWithParams(SignInInitParameters params) async {
await init(
scopes: params.scopes,
signInOption: params.signInOption,
hostedDomain: params.hostedDomain,
clientId: params.clientId,
);
}

/// Attempts to reuse pre-existing credentials to sign in again, without user interaction.
Future<GoogleSignInUserData?> signInSilently() async {
throw UnimplementedError('signInSilently() has not been implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform {
String? hostedDomain,
String? clientId,
}) {
return initWithParams(SignInInitParameters(
scopes: scopes,
signInOption: signInOption,
hostedDomain: hostedDomain,
clientId: clientId));
}

@override
Future<void> initWithParams(SignInInitParameters params) {
return channel.invokeMethod<void>('init', <String, dynamic>{
'signInOption': signInOption.toString(),
'scopes': scopes,
'hostedDomain': hostedDomain,
'clientId': clientId,
'signInOption': params.signInOption.toString(),
'scopes': params.scopes,
'hostedDomain': params.hostedDomain,
'clientId': params.clientId,
'forceCodeForRefreshToken': params.forceCodeForRefreshToken,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
import 'package:quiver/core.dart';

/// Default configuration options to use when signing in.
Expand All @@ -22,6 +23,42 @@ enum SignInOption {
games
}

/// The parameters to use when initializing the sign in process.
///
/// See:
/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
@immutable
class SignInInitParameters {
/// The parameters to use when initializing the sign in process.
const SignInInitParameters({
this.scopes = const <String>[],
this.signInOption = SignInOption.standard,
this.hostedDomain,
this.clientId,
this.forceCodeForRefreshToken = false,
});

/// The list of OAuth scope codes to request when signing in.
final List<String> scopes;

/// The user experience to use when signing in. [SignInOption.games] is
/// only supported on Android.
final SignInOption signInOption;

/// Restricts sign in to accounts of the user in the specified domain.
/// By default, the list of accounts will not be restricted.
final String? hostedDomain;

/// The client ID to use when signing in.
final String? clientId;

/// If true, ensures the authorization code can be exchanged for an access
/// token.
///
/// This is only used on Android.
final bool forceCodeForRefreshToken;
}

/// Holds information about the signed in user.
class GoogleSignInUserData {
/// Uses the given data to construct an instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
# 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: 2.1.2
version: 2.1.3

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void main() {
'scopes': <String>['two', 'scopes'],
'signInOption': 'SignInOption.games',
'clientId': 'fakeClientId',
'forceCodeForRefreshToken': false,
}),
() {
googleSignIn.getTokens(
Expand Down Expand Up @@ -136,5 +137,23 @@ void main() {

expect(log, tests.values);
});

test('initWithParams passes through arguments to the channel', () async {
await googleSignIn.initWithParams(const SignInInitParameters(
hostedDomain: 'example.com',
scopes: <String>['two', 'scopes'],
signInOption: SignInOption.games,
clientId: 'fakeClientId',
forceCodeForRefreshToken: true));
expect(log, <Matcher>[
isMethodCall('init', arguments: <String, dynamic>{
'hostedDomain': 'example.com',
'scopes': <String>['two', 'scopes'],
'signInOption': 'SignInOption.games',
'clientId': 'fakeClientId',
'forceCodeForRefreshToken': true,
}),
]);
});
});
}

0 comments on commit 5f9577b

Please sign in to comment.