|
28 | 28 | import com.google.firebase.auth.EmailAuthProvider;
|
29 | 29 |
|
30 | 30 | import java.util.ArrayList;
|
| 31 | +import java.util.Collections; |
31 | 32 | import java.util.List;
|
32 | 33 |
|
33 | 34 | /**
|
34 |
| - * Factory class to configure the intent that starts the auth flow |
| 35 | + * Provides the entry point to the user authentication flow. |
35 | 36 | */
|
36 | 37 | public class AuthFlowFactory {
|
| 38 | + |
| 39 | + /** |
| 40 | + * Provider identifier for email and password credentials, for use with {@link #createIntent}. |
| 41 | + */ |
37 | 42 | public static final String EMAIL_PROVIDER = "email";
|
| 43 | + |
| 44 | + /** |
| 45 | + * Provider identifier for Google, for use with {@link #createIntent}. |
| 46 | + */ |
38 | 47 | public static final String GOOGLE_PROVIDER = "google";
|
| 48 | + |
| 49 | + /** |
| 50 | + * Provider identifier for Facebook, for use with {@link #createIntent}. |
| 51 | + */ |
39 | 52 | public static final String FACEBOOK_PROVIDER = "facebook";
|
40 | 53 |
|
41 | 54 | /**
|
42 |
| - * Creates the intent that starts the auth flow |
| 55 | + * The theme identifier to use in {@link #createIntent} if no theme customization is required. |
| 56 | + */ |
| 57 | + public static final int DEFAULT_THEME = 0; |
| 58 | + |
| 59 | + /** |
| 60 | + * Creates an intent to start the user authentication flow. |
| 61 | + * |
| 62 | + * <p>IDP Provider instructions: |
43 | 63 | *
|
44 |
| - * IDP Provider instructions: |
45 |
| - * Enabling Google Sign In: If you're using Google Services Gradle Plugin, there are no additional |
46 |
| - * steps needed. If not, please override the R.string.default_web_client_id |
47 |
| - * to provider your google oauth web client id. |
48 |
| - * Enabling Facebook Sign In: Please override the R.string.facebook_application_id to provide the |
49 |
| - * App Id from Facebook Developer Dashboard |
| 64 | + * <ul> |
| 65 | + * <li>Enabling Google Sign In: If you're using the |
| 66 | + * <a href="https://developers.google.com/android/guides/google-services-plugin">Google |
| 67 | + * Services Gradle Plugin</a>, no additional configuration is required. If not, please override |
| 68 | + * {@code R.string.default_web_client_id} to provide your |
| 69 | + * <a href="https://developers.google.com/identity/sign-in/web/devconsole-project">Google OAuth |
| 70 | + * web client id.</a> |
| 71 | + * </li> |
| 72 | + * <li>Enabling Facebook Sign In: Please override the |
| 73 | + * {@code R.string.facebook_application_id} to provide the |
| 74 | + * <a href="https://developers.facebook.com/docs/apps/register">App Id</a> from |
| 75 | + * <a href="https://developers.facebook.com/apps">Facebook Developer Dashboard</a>. |
| 76 | + * </li> |
| 77 | + * </ul> |
50 | 78 | *
|
51 |
| - * @param context activity context |
52 |
| - * @param firebaseApp the FirebaseApp that's to used for the authentication flow |
53 |
| - * @param termsOfServiceUrl the URL to the Term of Service page to be present to the user |
54 |
| - * @param theme the customized theme to be applied to the authentication flow. 0 will use the default theme. |
55 |
| - * @param providers the supported identity providers that you wish to enable (google, facebook, etc) |
56 |
| - * @return |
| 79 | + * @param context The context of the activity that is starting the authentication flow. |
| 80 | + * @param firebaseApp the {@link com.google.firebase.FirebaseApp FirebaseApp} instance to |
| 81 | + * that the authentication flow should use and update. |
| 82 | + * @param tosUrl the URL of the Term of Service page for your app that should be presented to |
| 83 | + * the user. |
| 84 | + * @param theme the resource identifier of the customized theme to be applied to the |
| 85 | + * authentication flow. Use {@link #DEFAULT_THEME} if no customization is required. |
| 86 | + * @param providers the identity providers that you wish to enable (e.g. |
| 87 | + * {@link #GOOGLE google}, {@link #FACEBOOK facebook}, etc). |
| 88 | + * @return An intent to launch the authentication flow. |
57 | 89 | */
|
58 | 90 | public static Intent createIntent(
|
59 |
| -// * @param providers the supported identity providers that you wish to enable (google, facebook, etc) |
60 | 91 | @NonNull Context context,
|
61 | 92 | @NonNull FirebaseApp firebaseApp,
|
62 |
| - String termsOfServiceUrl, |
| 93 | + String tosUrl, |
63 | 94 | int theme,
|
64 | 95 | @Nullable List<String> providers) {
|
65 |
| - ArrayList<IDPProviderParcel> providerParcels = new ArrayList<>(); |
66 |
| - String appName = firebaseApp.getName(); |
67 |
| - String apiaryKey = firebaseApp.getOptions().getApiKey(); |
68 |
| - String applicationId = firebaseApp.getOptions().getApplicationId(); |
69 | 96 | if (providers == null || providers.size() == 0) {
|
70 |
| - return CredentialsInitActivity.createIntent( |
71 |
| - context, |
72 |
| - appName, |
73 |
| - providerParcels, |
74 |
| - apiaryKey, |
75 |
| - applicationId, |
76 |
| - termsOfServiceUrl, |
77 |
| - theme |
78 |
| - ); |
| 97 | + providers = Collections.emptyList(); |
79 | 98 | }
|
80 | 99 |
|
| 100 | + ArrayList<IDPProviderParcel> providerParcels = new ArrayList<>(); |
81 | 101 | for (String provider : providers) {
|
82 | 102 | if (provider.equalsIgnoreCase(FACEBOOK_PROVIDER)) {
|
83 | 103 | providerParcels.add(FacebookProvider.createFacebookParcel(
|
84 | 104 | context.getString(R.string.facebook_application_id)));
|
85 | 105 | } else if (provider.equalsIgnoreCase(GOOGLE_PROVIDER)) {
|
86 |
| - providerParcels.add( |
87 |
| - GoogleProvider.createParcel(context.getString(R.string.default_web_client_id))); |
| 106 | + providerParcels.add(GoogleProvider.createParcel( |
| 107 | + context.getString(R.string.default_web_client_id))); |
88 | 108 | } else if (provider.equalsIgnoreCase(EMAIL_PROVIDER)) {
|
89 | 109 | providerParcels.add(
|
90 | 110 | new IDPProviderParcel(EmailAuthProvider.PROVIDER_ID, new Bundle())
|
91 | 111 | );
|
92 | 112 | }
|
93 | 113 | }
|
| 114 | + |
94 | 115 | return CredentialsInitActivity.createIntent(
|
95 | 116 | context,
|
96 |
| - appName, |
| 117 | + firebaseApp.getName(), |
97 | 118 | providerParcels,
|
98 |
| - apiaryKey, |
99 |
| - applicationId, |
100 |
| - termsOfServiceUrl, |
| 119 | + firebaseApp.getOptions().getApiKey(), |
| 120 | + firebaseApp.getOptions().getApplicationId(), |
| 121 | + tosUrl, |
101 | 122 | theme
|
102 | 123 | );
|
103 | 124 | }
|
|
0 commit comments