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

Commit a15d65d

Browse files
authored
[google_sign_in] Add forceCodeForRefreshToken parameter (and new SignInInitParameters class) (#5325)
1 parent ff01c1d commit a15d65d

File tree

7 files changed

+90
-8
lines changed

7 files changed

+90
-8
lines changed

packages/google_sign_in/google_sign_in_platform_interface/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <sanekyy@gmail.com>
6464
Anton Borries <mail@antonborri.es>
6565
Alex Li <google@alexv525.com>
6666
Rahul Raj <64.rahulraj@gmail.com>
67+
Twin Sun, LLC <google-contrib@twinsunsolutions.com>

packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 2.1.3
22

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

56
## 2.1.2
67

packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ abstract class GoogleSignInPlatform {
6363
/// if the provided instance is a class implemented with `implements`.
6464
void _verifyProvidesDefaultImplementations() {}
6565

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

91+
/// Initializes the plugin with specified [params]. You must call this method
92+
/// before calling other methods.
93+
///
94+
/// See:
95+
///
96+
/// * [SignInInitParameters]
97+
Future<void> initWithParams(SignInInitParameters params) async {
98+
await init(
99+
scopes: params.scopes,
100+
signInOption: params.signInOption,
101+
hostedDomain: params.hostedDomain,
102+
clientId: params.clientId,
103+
);
104+
}
105+
92106
/// Attempts to reuse pre-existing credentials to sign in again, without user interaction.
93107
Future<GoogleSignInUserData?> signInSilently() async {
94108
throw UnimplementedError('signInSilently() has not been implemented.');

packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform {
2525
String? hostedDomain,
2626
String? clientId,
2727
}) {
28+
return initWithParams(SignInInitParameters(
29+
scopes: scopes,
30+
signInOption: signInOption,
31+
hostedDomain: hostedDomain,
32+
clientId: clientId));
33+
}
34+
35+
@override
36+
Future<void> initWithParams(SignInInitParameters params) {
2837
return channel.invokeMethod<void>('init', <String, dynamic>{
29-
'signInOption': signInOption.toString(),
30-
'scopes': scopes,
31-
'hostedDomain': hostedDomain,
32-
'clientId': clientId,
38+
'signInOption': params.signInOption.toString(),
39+
'scopes': params.scopes,
40+
'hostedDomain': params.hostedDomain,
41+
'clientId': params.clientId,
42+
'forceCodeForRefreshToken': params.forceCodeForRefreshToken,
3343
});
3444
}
3545

packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/widgets.dart';
56
import 'package:quiver/core.dart';
67

78
/// Default configuration options to use when signing in.
@@ -22,6 +23,42 @@ enum SignInOption {
2223
games
2324
}
2425

26+
/// The parameters to use when initializing the sign in process.
27+
///
28+
/// See:
29+
/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
30+
@immutable
31+
class SignInInitParameters {
32+
/// The parameters to use when initializing the sign in process.
33+
const SignInInitParameters({
34+
this.scopes = const <String>[],
35+
this.signInOption = SignInOption.standard,
36+
this.hostedDomain,
37+
this.clientId,
38+
this.forceCodeForRefreshToken = false,
39+
});
40+
41+
/// The list of OAuth scope codes to request when signing in.
42+
final List<String> scopes;
43+
44+
/// The user experience to use when signing in. [SignInOption.games] is
45+
/// only supported on Android.
46+
final SignInOption signInOption;
47+
48+
/// Restricts sign in to accounts of the user in the specified domain.
49+
/// By default, the list of accounts will not be restricted.
50+
final String? hostedDomain;
51+
52+
/// The client ID to use when signing in.
53+
final String? clientId;
54+
55+
/// If true, ensures the authorization code can be exchanged for an access
56+
/// token.
57+
///
58+
/// This is only used on Android.
59+
final bool forceCodeForRefreshToken;
60+
}
61+
2562
/// Holds information about the signed in user.
2663
class GoogleSignInUserData {
2764
/// Uses the given data to construct an instance.

packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.1.2
7+
version: 2.1.3
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void main() {
107107
'scopes': <String>['two', 'scopes'],
108108
'signInOption': 'SignInOption.games',
109109
'clientId': 'fakeClientId',
110+
'forceCodeForRefreshToken': false,
110111
}),
111112
() {
112113
googleSignIn.getTokens(
@@ -136,5 +137,23 @@ void main() {
136137

137138
expect(log, tests.values);
138139
});
140+
141+
test('initWithParams passes through arguments to the channel', () async {
142+
await googleSignIn.initWithParams(const SignInInitParameters(
143+
hostedDomain: 'example.com',
144+
scopes: <String>['two', 'scopes'],
145+
signInOption: SignInOption.games,
146+
clientId: 'fakeClientId',
147+
forceCodeForRefreshToken: true));
148+
expect(log, <Matcher>[
149+
isMethodCall('init', arguments: <String, dynamic>{
150+
'hostedDomain': 'example.com',
151+
'scopes': <String>['two', 'scopes'],
152+
'signInOption': 'SignInOption.games',
153+
'clientId': 'fakeClientId',
154+
'forceCodeForRefreshToken': true,
155+
}),
156+
]);
157+
});
139158
});
140159
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy