Skip to content

Commit c1e737f

Browse files
committed
Add GetSignInWithGoogleOption for sign in manually flow
1 parent f5e644c commit c1e737f

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

Plugins/Android/src/main/java/com/google/googlesignin/GoogleSignInHelper.java

+22-17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.google.android.gms.tasks.TaskCompletionSource;
4747
import com.google.android.gms.tasks.TaskExecutors;
4848
import com.google.android.libraries.identity.googleid.GetGoogleIdOption;
49+
import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption;
4950
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;
5051
import com.unity3d.player.UnityPlayer;
5152

@@ -74,13 +75,13 @@ public static void enableDebugLogging(boolean flag) {
7475

7576
private CancellationSignal cancellationSignal;
7677
private Task<AuthorizationResult> task;
77-
private Function<Boolean, Task<AuthorizationResult>> continuation;
78+
private Function<Boolean, Task<AuthorizationResult>> signInFunction;
7879
public boolean isPending() {
7980
return task != null && !task.isComplete() && !task.isCanceled();
8081
}
8182

8283
public int getStatus() {
83-
if(continuation == null)
84+
if(signInFunction == null)
8485
return CommonStatusCodes.DEVELOPER_ERROR;
8586

8687
if(task == null)
@@ -137,7 +138,7 @@ public void configure(
137138
IListener requestHandle) {
138139
logDebug("TokenFragment.configure called");
139140

140-
continuation = new Function<Boolean, Task<AuthorizationResult>>() {
141+
signInFunction = new Function<Boolean, Task<AuthorizationResult>>() {
141142
@Override
142143
public Task<AuthorizationResult> apply(@NonNull Boolean silent) {
143144
if(isPending()) {
@@ -148,21 +149,26 @@ public Task<AuthorizationResult> apply(@NonNull Boolean silent) {
148149

149150
cancellationSignal = new CancellationSignal();
150151

151-
CancellationSignal signal = cancellationSignal;
152+
GetCredentialRequest.Builder getCredentialRequestBuilder = new GetCredentialRequest.Builder()
153+
.setPreferImmediatelyAvailableCredentials(hideUiPopups);
152154

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);
156159

157-
if(defaultAccountName != null)
158-
getGoogleIdOptionBuilder.setNonce(defaultAccountName);
160+
if(defaultAccountName != null)
161+
getGoogleIdOptionBuilder.setNonce(defaultAccountName);
159162

160-
if(!Strings.isEmptyOrWhitespace(webClientId))
161-
getGoogleIdOptionBuilder.setServerClientId(webClientId);
163+
if(!Strings.isEmptyOrWhitespace(webClientId))
164+
getGoogleIdOptionBuilder.setServerClientId(webClientId);
162165

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+
}
166172

167173
TaskCompletionSource<GetCredentialResponse> source = new TaskCompletionSource<>();
168174

@@ -203,7 +209,6 @@ public Task<AuthorizationResult> then(GetCredentialResponse getCredentialRespons
203209

204210
int additionalCount = additionalScopes != null ? additionalScopes.length : 0;
205211
List<Scope> scopes = new ArrayList<>(3 + additionalCount);
206-
scopes.add(new Scope("openid"));
207212
scopes.add(new Scope(Scopes.PROFILE));
208213
if (requestEmail)
209214
scopes.add(new Scope(Scopes.EMAIL));
@@ -234,12 +239,12 @@ public void onComplete(@NonNull Task<AuthorizationResult> _unused) {
234239
}
235240

236241
public GoogleSignInHelper signIn() {
237-
task = continuation.apply(false);
242+
task = signInFunction.apply(false);
238243
return this;
239244
}
240245

241246
public GoogleSignInHelper signInSilently() {
242-
task = continuation.apply(true);
247+
task = signInFunction.apply(true);
243248
return this;
244249
}
245250

0 commit comments

Comments
 (0)