@@ -271,36 +271,39 @@ public static int getDefaultTheme() {
271
271
* Signs the user in without any UI if possible. If this operation fails, you can safely start a
272
272
* UI-based sign-in flow knowing it is required.
273
273
*
274
- * @param context requesting the user be signed in
275
- * @param configs to use for silent sign in
274
+ * @param context requesting the user be signed in
275
+ * @param desiredConfigs to use for silent sign in. Only Google and email are currently
276
+ * supported, the rest will be ignored.
276
277
* @return a task which indicates whether or not the user was successfully signed in.
277
278
*/
278
279
@ NonNull
279
- public Task <AuthResult > silentSignIn (@ NonNull final Context context ,
280
- @ NonNull List <IdpConfig > configs ) {
281
- if (configs .isEmpty ()) {
280
+ public Task <AuthResult > silentSignIn (@ NonNull Context context ,
281
+ @ NonNull List <IdpConfig > desiredConfigs ) {
282
+ if (mAuth .getCurrentUser () != null ) {
283
+ throw new IllegalArgumentException ("User already signed in!" );
284
+ }
285
+ if (desiredConfigs .isEmpty ()) {
282
286
throw new IllegalArgumentException ("At least one provider must be specified." );
283
287
}
284
- for (IdpConfig config : configs ) {
288
+
289
+ List <IdpConfig > configs = new ArrayList <>();
290
+ for (IdpConfig config : desiredConfigs ) {
285
291
String provider = config .getProviderId ();
286
- if (!provider .equals (EmailAuthProvider .PROVIDER_ID )
287
- && !provider .equals (GoogleAuthProvider .PROVIDER_ID )) {
288
- throw new IllegalArgumentException ("Only email and google providers are supported " +
289
- "for silent sign-in." );
292
+ if (provider .equals (EmailAuthProvider .PROVIDER_ID )
293
+ || provider .equals (GoogleAuthProvider .PROVIDER_ID )) {
294
+ configs .add (config );
290
295
}
291
296
}
292
- if (mAuth .getCurrentUser () != null ) {
293
- throw new IllegalArgumentException ("User already signed in!" );
294
- }
295
297
298
+ final Context appContext = context .getApplicationContext ();
296
299
final IdpConfig google =
297
300
ProviderUtils .getConfigFromIdps (configs , GoogleAuthProvider .PROVIDER_ID );
298
301
final IdpConfig email =
299
302
ProviderUtils .getConfigFromIdps (configs , EmailAuthProvider .PROVIDER_ID );
300
303
301
304
GoogleSignInOptions googleOptions = null ;
302
305
if (google != null ) {
303
- GoogleSignInAccount last = GoogleSignIn .getLastSignedInAccount (context );
306
+ GoogleSignInAccount last = GoogleSignIn .getLastSignedInAccount (appContext );
304
307
if (last != null && last .getIdToken () != null ) {
305
308
return mAuth .signInWithCredential (GoogleAuthProvider .getCredential (
306
309
last .getIdToken (), null ));
@@ -325,7 +328,7 @@ public Task<AuthResult> then(@NonNull Task<CredentialRequestResponse> task) {
325
328
String password = credential .getPassword ();
326
329
327
330
if (TextUtils .isEmpty (password )) {
328
- return GoogleSignIn .getClient (context ,
331
+ return GoogleSignIn .getClient (appContext ,
329
332
new GoogleSignInOptions .Builder (finalGoogleOptions )
330
333
.setAccountName (email )
331
334
.build ())
0 commit comments