Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in] Add forceCodeForRefreshToken parameter (and new SignInInitParameters class) #5325

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
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.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the comment on init to say Deprecated: call initWithParams instead. instead of You must call this method before calling other methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think the statement can be combined to reduce redundancy, something like: "Initializes the plugin with specified params".


/// 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 {
fbcouch marked this conversation as resolved.
Show resolved Hide resolved
/// 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:/flutter/plugins/tree/main/packages/google_sign_in
issue_tracker: https:/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,
}),
]);
});
});
}