64
64
* If an alternative app instance is in use, call
65
65
* {@link AuthUI#getInstance(FirebaseApp) AuthUI.getInstance(app} instead, passing the
66
66
* appropriate app instance.
67
- *
67
+ * <p>
68
68
* <h2>Sign-in</h2>
69
- *
69
+ * <p>
70
70
* If a user is not currently signed in (as can be determined by checking
71
71
* {@code auth.getCurrentUser() != null}, where {@code auth} is the {@link FirebaseAuth}
72
72
* associated with your {@link FirebaseApp}) then the sign-in process can be started by creating
73
73
* a sign-in intent using {@link SignInIntentBuilder}. A builder instance can be retrieved by
74
74
* calling {@link AuthUI#createSignInIntentBuilder()}.
75
- *
75
+ * <p>
76
76
* <p>The builder provides the following customization options for the authentication flow
77
77
* implemented by this library:
78
- *
78
+ * <p>
79
79
* <ul>
80
80
* <li>The set of authentication methods desired can be specified.</li>
81
81
* <li>The terms of service URL for your app can be specified, which is included as a link
86
86
* the flow for consistent customization of colors and typography.
87
87
* </li>
88
88
* </ul>
89
- *
90
- *
89
+ * <p>
90
+ * <p>
91
91
* <h3>Sign-in examples</h3>
92
- *
92
+ * <p>
93
93
* If no customization is required, and only email authentication is required, the sign-in flow
94
94
* can be started as follows:
95
- *
95
+ * <p>
96
96
* <pre>
97
97
* {@code
98
98
* startActivityForResult(
99
99
* AuthUI.getInstance().createSignInIntentBuilder().build(),
100
100
* RC_SIGN_IN);
101
101
* }
102
102
* </pre>
103
- *
103
+ * <p>
104
104
* If Google Sign-in and Facebook Sign-in are also required, then this can be replaced with:
105
- *
105
+ * <p>
106
106
* <pre>
107
107
* {@code
108
108
* startActivityForResult(
119
119
* RC_SIGN_IN);
120
120
* }
121
121
* </pre>
122
- *
122
+ * <p>
123
123
* Finally, if a terms of service URL and a custom theme are required:
124
- *
124
+ * <p>
125
125
* <pre>
126
126
* {@code
127
127
* startActivityForResult(
134
134
* RC_SIGN_IN);
135
135
* }
136
136
* </pre>
137
- *
137
+ * <p>
138
138
* <h3>Handling the Sign-in response</h3>
139
- *
139
+ * <p>
140
140
* The authentication flow provides only two response codes:
141
141
* {@link ResultCodes#OK RESULT_OK} if a user is signed in,
142
142
* and {@link ResultCodes#CANCELED RESULT_CANCELLED} if sign in
143
143
* failed. No further information on failure is provided as it is not typically useful; the only
144
144
* recourse for most apps if sign in fails is to ask the user to sign in again later, or proceed
145
145
* with an anonymous account if supported.
146
- *
146
+ * <p>
147
147
* <pre>
148
148
* {@code
149
149
* @Override
162
162
* }
163
163
* }
164
164
* </pre>
165
- *
165
+ * <p>
166
166
* <h2>Sign-out</h2>
167
- *
167
+ * <p>
168
168
* With the integrations provided by AuthUI, signing out a user is a multi-stage process:
169
- *
169
+ * <p>
170
170
* <ol>
171
171
* <li>The user must be signed out of the {@link FirebaseAuth} instance.</li>
172
172
* <li>Smart Lock for Passwords must be instructed to disable automatic sign-in, in
180
180
* would also prevent the user from switching between accounts on the same provider.
181
181
* </li>
182
182
* </ol>
183
- *
183
+ * <p>
184
184
* In order to make this process easier, AuthUI provides a simple
185
185
* {@link AuthUI#signOut(Activity) signOut} method to encapsulate this behavior. The method returns
186
186
* a {@link Task} which is marked completed once all necessary sign-out operations are completed:
187
- *
187
+ * <p>
188
188
* <pre>
189
189
* {@code
190
190
* public void onClick(View v) {
200
200
* }
201
201
* }
202
202
* </pre>
203
- *
203
+ * <p>
204
204
* <h2>IDP Provider configuration</h2>
205
- *
205
+ * <p>
206
206
* Interacting with identity providers typically requires some additional client configuration.
207
207
* AuthUI currently supports Google Sign-in and Facebook Sign-in, and currently requires the
208
208
* basic configuration for these providers to be specified via string properties:
209
- *
209
+ * <p>
210
210
* <ul>
211
- *
211
+ * <p>
212
212
* <li>Google Sign-in: If your app build uses the
213
213
* <a href="https://developers.google.com/android/guides/google-services-plugin">Google
214
214
* Services Gradle Plugin</a>, no additional configuration is required. If not, please override
215
215
* {@code R.string.default_web_client_id} to provide your
216
216
* <a href="https://developers.google.com/identity/sign-in/web/devconsole-project">Google OAuth
217
217
* web client id.</a>
218
218
* </li>
219
- *
219
+ * <p>
220
220
* <li>Facebook Sign-in: Please override the string resource
221
221
* {@code facebook_application_id} to provide the
222
222
* <a href="https://developers.facebook.com/docs/apps/register">App ID</a> for your app as
223
223
* registered on the
224
224
* <a href="https://developers.facebook.com/apps">Facebook Developer Dashboard</a>.
225
225
* </li>
226
- *
226
+ * <p>
227
227
* </ul>
228
228
*/
229
229
public class AuthUI {
@@ -276,6 +276,40 @@ private AuthUI(FirebaseApp app) {
276
276
mAuth = FirebaseAuth .getInstance (mApp );
277
277
}
278
278
279
+ /**
280
+ * Retrieves the {@link AuthUI} instance associated with the default app, as returned by
281
+ * {@code FirebaseApp.getInstance()}.
282
+ *
283
+ * @throws IllegalStateException if the default app is not initialized.
284
+ */
285
+ public static AuthUI getInstance () {
286
+ return getInstance (FirebaseApp .getInstance ());
287
+ }
288
+
289
+ /**
290
+ * Retrieves the {@link AuthUI} instance associated the the specified app.
291
+ */
292
+ public static AuthUI getInstance (FirebaseApp app ) {
293
+ AuthUI authUi ;
294
+ synchronized (INSTANCES ) {
295
+ authUi = INSTANCES .get (app );
296
+ if (authUi == null ) {
297
+ authUi = new AuthUI (app );
298
+ INSTANCES .put (app , authUi );
299
+ }
300
+ }
301
+ return authUi ;
302
+ }
303
+
304
+ /**
305
+ * Default theme used by {@link SignInIntentBuilder#setTheme(int)} if no theme
306
+ * customization is required.
307
+ */
308
+ @ StyleRes
309
+ public static int getDefaultTheme () {
310
+ return R .style .FirebaseUI ;
311
+ }
312
+
279
313
/**
280
314
* Signs the current user out, if one is signed in.
281
315
*
@@ -380,44 +414,9 @@ public SignInIntentBuilder createSignInIntentBuilder() {
380
414
return new SignInIntentBuilder ();
381
415
}
382
416
383
- /**
384
- * Retrieves the {@link AuthUI} instance associated with the default app, as returned by
385
- * {@code FirebaseApp.getInstance()}.
386
- *
387
- * @throws IllegalStateException if the default app is not initialized.
388
- */
389
- public static AuthUI getInstance () {
390
- return getInstance (FirebaseApp .getInstance ());
391
- }
392
-
393
- /**
394
- * Retrieves the {@link AuthUI} instance associated the the specified app.
395
- */
396
- public static AuthUI getInstance (FirebaseApp app ) {
397
- AuthUI authUi ;
398
- synchronized (INSTANCES ) {
399
- authUi = INSTANCES .get (app );
400
- if (authUi == null ) {
401
- authUi = new AuthUI (app );
402
- INSTANCES .put (app , authUi );
403
- }
404
- }
405
- return authUi ;
406
- }
407
-
408
- /**
409
- * Default theme used by {@link SignInIntentBuilder#setTheme(int)} if no theme
410
- * customization is required.
411
- */
412
- @ StyleRes
413
- public static int getDefaultTheme () {
414
- return R .style .FirebaseUI ;
415
- }
416
-
417
-
418
417
/**
419
418
* Configuration for an identity provider.
420
- *
419
+ * <p>
421
420
* In the simplest case, you can supply the provider ID and build the config like this:
422
421
* {@code new IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()}
423
422
*/
@@ -430,6 +429,11 @@ private IdpConfig(@NonNull String providerId, List<String> scopes) {
430
429
mProviderId = providerId ;
431
430
}
432
431
432
+ private IdpConfig (Parcel in ) {
433
+ mProviderId = in .readString ();
434
+ mScopes = in .createStringArrayList ();
435
+ }
436
+
433
437
public String getProviderId () {
434
438
return mProviderId ;
435
439
}
@@ -438,11 +442,6 @@ public List<String> getScopes() {
438
442
return mScopes ;
439
443
}
440
444
441
- protected IdpConfig (Parcel in ) {
442
- mProviderId = in .readString ();
443
- mScopes = in .createStringArrayList ();
444
- }
445
-
446
445
public static final Creator <IdpConfig > CREATOR = new Creator <IdpConfig >() {
447
446
@ Override
448
447
public IdpConfig createFromParcel (Parcel in ) {
@@ -488,14 +487,14 @@ public Builder(@NonNull String providerId) {
488
487
/**
489
488
* Specifies the additional permissions that the application will request for this
490
489
* identity provider.
491
- *
490
+ * <p>
492
491
* For Facebook permissions see:
493
492
* https://developers.facebook.com/docs/facebook-login/android
494
493
* https://developers.facebook.com/docs/facebook-login/permissions
495
- *
494
+ * <p>
496
495
* For Google permissions see:
497
496
* https://developers.google.com/identity/protocols/googlescopes
498
- *
497
+ * <p>
499
498
* Twitter permissions are only configurable through the Twitter developer console.
500
499
*/
501
500
public Builder setPermissions (List <String > permissions ) {
@@ -556,7 +555,7 @@ public SignInIntentBuilder setTosUrl(@Nullable String tosUrl) {
556
555
/**
557
556
* Specified the set of supported authentication providers. At least one provider must
558
557
* be specified. There may only be one instance of each provider.
559
- *
558
+ * <p>
560
559
* <p>If no providers are explicitly specified by calling this method, then the email
561
560
* provider is the default supported provider.
562
561
*
@@ -583,7 +582,7 @@ public SignInIntentBuilder setProviders(@NonNull List<IdpConfig> idpConfigs) {
583
582
* Specifies the set of supported authentication providers. At least one provider
584
583
* must be specified, and the set of providers must be a subset of
585
584
* {@link #SUPPORTED_PROVIDERS}. There may only be one instance of each provider.
586
- *
585
+ * <p>
587
586
* <p>If no providers are explicitly specified by calling this method, then
588
587
* {@link #EMAIL_PROVIDER email} is the default supported provider.
589
588
*
@@ -605,7 +604,7 @@ public SignInIntentBuilder setProviders(@NonNull String... providers) {
605
604
606
605
/**
607
606
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
608
- *
607
+ * <p>
609
608
* <p>SmartLock is enabled by default
610
609
*/
611
610
public SignInIntentBuilder setIsSmartLockEnabled (boolean enabled ) {
0 commit comments