46
46
import com .google .android .gms .tasks .TaskCompletionSource ;
47
47
import com .google .android .gms .tasks .TaskExecutors ;
48
48
import com .google .android .libraries .identity .googleid .GetGoogleIdOption ;
49
+ import com .google .android .libraries .identity .googleid .GetSignInWithGoogleOption ;
49
50
import com .google .android .libraries .identity .googleid .GoogleIdTokenCredential ;
50
51
import com .unity3d .player .UnityPlayer ;
51
52
@@ -74,13 +75,13 @@ public static void enableDebugLogging(boolean flag) {
74
75
75
76
private CancellationSignal cancellationSignal ;
76
77
private Task <AuthorizationResult > task ;
77
- private Function <Boolean , Task <AuthorizationResult >> continuation ;
78
+ private Function <Boolean , Task <AuthorizationResult >> signInFunction ;
78
79
public boolean isPending () {
79
80
return task != null && !task .isComplete () && !task .isCanceled ();
80
81
}
81
82
82
83
public int getStatus () {
83
- if (continuation == null )
84
+ if (signInFunction == null )
84
85
return CommonStatusCodes .DEVELOPER_ERROR ;
85
86
86
87
if (task == null )
@@ -137,7 +138,7 @@ public void configure(
137
138
IListener requestHandle ) {
138
139
logDebug ("TokenFragment.configure called" );
139
140
140
- continuation = new Function <Boolean , Task <AuthorizationResult >>() {
141
+ signInFunction = new Function <Boolean , Task <AuthorizationResult >>() {
141
142
@ Override
142
143
public Task <AuthorizationResult > apply (@ NonNull Boolean silent ) {
143
144
if (isPending ()) {
@@ -148,21 +149,26 @@ public Task<AuthorizationResult> apply(@NonNull Boolean silent) {
148
149
149
150
cancellationSignal = new CancellationSignal ();
150
151
151
- CancellationSignal signal = cancellationSignal ;
152
+ GetCredentialRequest .Builder getCredentialRequestBuilder = new GetCredentialRequest .Builder ()
153
+ .setPreferImmediatelyAvailableCredentials (hideUiPopups );
152
154
153
- GetGoogleIdOption .Builder getGoogleIdOptionBuilder = new GetGoogleIdOption .Builder ()
154
- .setFilterByAuthorizedAccounts (silent )
155
- .setAutoSelectEnabled (hideUiPopups );
155
+ if (silent ) {
156
+ GetGoogleIdOption .Builder getGoogleIdOptionBuilder = new GetGoogleIdOption .Builder ()
157
+ .setFilterByAuthorizedAccounts (false )
158
+ .setAutoSelectEnabled (hideUiPopups );
156
159
157
- if (defaultAccountName != null )
158
- getGoogleIdOptionBuilder .setNonce (defaultAccountName );
160
+ if (defaultAccountName != null )
161
+ getGoogleIdOptionBuilder .setNonce (defaultAccountName );
159
162
160
- if (!Strings .isEmptyOrWhitespace (webClientId ))
161
- getGoogleIdOptionBuilder .setServerClientId (webClientId );
163
+ if (!Strings .isEmptyOrWhitespace (webClientId ))
164
+ getGoogleIdOptionBuilder .setServerClientId (webClientId );
162
165
163
- GetCredentialRequest .Builder getCredentialRequestBuilder = new GetCredentialRequest .Builder ()
164
- .addCredentialOption (getGoogleIdOptionBuilder .build ())
165
- .setPreferImmediatelyAvailableCredentials (hideUiPopups );
166
+ getCredentialRequestBuilder .addCredentialOption (getGoogleIdOptionBuilder .build ());
167
+ }
168
+ else {
169
+ GetSignInWithGoogleOption .Builder getSignInWithGoogleOptionBuilder = new GetSignInWithGoogleOption .Builder (webClientId );
170
+ getCredentialRequestBuilder .addCredentialOption (getSignInWithGoogleOptionBuilder .build ());
171
+ }
166
172
167
173
TaskCompletionSource <GetCredentialResponse > source = new TaskCompletionSource <>();
168
174
@@ -203,7 +209,6 @@ public Task<AuthorizationResult> then(GetCredentialResponse getCredentialRespons
203
209
204
210
int additionalCount = additionalScopes != null ? additionalScopes .length : 0 ;
205
211
List <Scope > scopes = new ArrayList <>(3 + additionalCount );
206
- scopes .add (new Scope ("openid" ));
207
212
scopes .add (new Scope (Scopes .PROFILE ));
208
213
if (requestEmail )
209
214
scopes .add (new Scope (Scopes .EMAIL ));
@@ -234,12 +239,12 @@ public void onComplete(@NonNull Task<AuthorizationResult> _unused) {
234
239
}
235
240
236
241
public GoogleSignInHelper signIn () {
237
- task = continuation .apply (false );
242
+ task = signInFunction .apply (false );
238
243
return this ;
239
244
}
240
245
241
246
public GoogleSignInHelper signInSilently () {
242
- task = continuation .apply (true );
247
+ task = signInFunction .apply (true );
243
248
return this ;
244
249
}
245
250
0 commit comments