Skip to content

Commit ced9dba

Browse files
committed
Add auth docs
1 parent 007c6c1 commit ced9dba

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

README.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,103 @@ dependencies {
3232

3333
After the project is synchronized, we're ready to start using Firebase functionality in our app.
3434

35+
## Using FirebaseUI for Authentication
36+
37+
FirebaseUI has a wonderful built-in login dialog which you can use to provide a headful UI for your users to authenticate with.
38+
39+
![FirebaseUI Login Dialog](doc-images/mdialog.png "FirebaseUI Login Dialog")
40+
41+
To use FirebaseUI to authenticate users we need to do a few things:
42+
43+
1. Add our Facebook/Twitter/Google keys to strings.xml
44+
2. Add our activities to our AndroidManifest.xml
45+
3. Inherit from FirebaseLoginBaseActivity
46+
4. Call showFirebaseLoginDialog();
47+
48+
### Add our Facebook/Twitter/Google keys to strings.xml
49+
50+
Open your `res/values/strings.xml` file and add the following lines, replacing `[VALUE]` with your key.
51+
52+
Keep in mind, these are all optional. If you don't plan to use Twitter/Facebook/Google login, you can leave those values empty or remove the string definition entirely.
53+
54+
*Note:* If you're not using *all* available providers, you'll need to manually create and manage your `FirebaseLoginDialog` and specify the enabled providers as demonstrated in [`FirebaseLoginBaseActivity.java`](library/src/main/java/com/firebase/ui/auth/core/FirebaseLoginBaseActivity.java).
55+
56+
```xml
57+
<string name="facebook_app_id">[VALUE]</string>
58+
<string name="twitter_app_key">[VALUE]</string>
59+
<string name="twitter_app_secret">[VALUE]</string>
60+
<string name="google_client_id">[VALUE]</string>
61+
```
62+
63+
### Add our activities to our AndroidManifest.xml
64+
65+
Open your `manifests/AndroidManifest.xml` file.
66+
67+
Add the following to your `<application>` tag.
68+
69+
```xml
70+
<!-- Twitter Configuration -->
71+
<activity android:name="com.firebase.ui.auth.twitter.TwitterPromptActivity" />
72+
<meta-data
73+
android:name="com.firebase.ui.TwitterKey"
74+
android:value="@string/twitter_app_key"/>
75+
<meta-data
76+
android:name="com.firebase.ui.TwitterSecret"
77+
android:value="@string/twitter_app_secret"/>
78+
79+
<!-- Facebook Configuration -->
80+
<activity
81+
android:name="com.facebook.FacebookActivity"
82+
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
83+
android:label="@string/app_name"
84+
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
85+
<meta-data
86+
android:name="com.facebook.sdk.ApplicationId"
87+
android:value="@string/facebook_app_id" />
88+
```
89+
90+
### Inherit from FirebaseLoginBaseActivity
91+
92+
Now we get to the juicy bits. Open your `MainActivity` and change your activity to extend `FirebaseLoginBaseActivity`
93+
94+
```java
95+
public class MainActivity extends FirebaseLoginBaseActivity {
96+
...
97+
}
98+
```
99+
100+
This activity should implement a few methods so your application can react to changing authentication state.
101+
102+
```
103+
public class MainActivity extends FirebaseLoginBaseActivity {
104+
...
105+
@Override
106+
public Firebase getFirebaseRef() {}
107+
108+
@Override
109+
public void onFirebaseLoginSuccess(AuthData authData) {}
110+
111+
@Override
112+
public void onFirebaseLogout() {}
113+
114+
@Override
115+
public void onFirebaseLoginProviderError(FirebaseLoginError firebaseError) {}
116+
117+
@Override
118+
public void onFirebaseLoginUserError(FirebaseLoginError firebaseError) {}
119+
}
120+
```
121+
122+
### Call showFirebaseLoginDialog();
123+
124+
You're now ready to display the login dialog!
125+
126+
Simply call `showFirebaseLoginPrompt()` from within your activity and you'll see the dialog!
127+
128+
35129
## Using FirebaseUI to Populate a ListView
36130

37-
To use the FirebaseUI library in our project, we need to do a few things:
131+
To use the FirebaseUI to display Firebase data, we need to do a few things:
38132

39133
1. Create a class to represent the properties of our objects, as they are stored into the database
40134
2. Create a custom list adapter to map from Firebase to Android

0 commit comments

Comments
 (0)