Skip to content

Commit ad98c24

Browse files
authored
Merge pull request #7 from firebase/master
Pull latest changes
2 parents 213a4e6 + a95d541 commit ad98c24

29 files changed

+466
-241
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ those separately in your app.
2525
In your `app/build.gradle` file add a dependency on one of the FirebaseUI
2626
libraries.
2727

28-
```
28+
```groovy
2929
dependencies {
3030
// Single target that includes all FirebaseUI libraries
31-
compile 'com.firebaseui:firebase-ui:0.5.1'
31+
compile 'com.firebaseui:firebase-ui:0.5.3'
3232
3333
// FirebaseUI Database only
34-
compile 'com.firebaseui:firebase-ui-database:0.5.1'
34+
compile 'com.firebaseui:firebase-ui-database:0.5.3'
3535
3636
// FirebaseUI Auth only
37-
compile 'com.firebaseui:firebase-ui-auth:0.5.1'
37+
compile 'com.firebaseui:firebase-ui-auth:0.5.3'
3838
}
3939
```
4040

@@ -61,7 +61,7 @@ For convenience, here are some examples:
6161

6262
| FirebaseUI Version | Firebase/Play Services Version |
6363
|--------------------|--------------------------------|
64-
| 0.5.1 | 9.4.0 |
64+
| 0.5.3 | 9.4.0 |
6565
| 0.4.4 | 9.4.0 |
6666
| 0.4.3 | 9.2.1 |
6767
| 0.4.2 | 9.2.0 |

auth/README.md

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ Firebase: see the
4141
Then, add the FirebaseUI auth library dependency. If your project uses
4242
Gradle, add:
4343

44-
```
44+
```groovy
4545
dependencies {
4646
// ...
47-
compile 'com.firebaseui:firebase-ui-auth:0.5.1'
47+
compile 'com.firebaseui:firebase-ui-auth:0.5.3'
4848
}
4949
```
5050

5151
If instead your project uses Maven, add:
5252

53-
```
53+
```xml
5454
<dependency>
5555
<groupId>com.firebaseui</groupId>
5656
<artifactId>firebase-ui-auth</artifactId>
57-
<version>0.5.1</version>
57+
<version>0.5.3</version>
5858
</dependency>
5959
```
6060

@@ -70,7 +70,7 @@ If support for Facebook Sign-in is also required, define the
7070
resource string `facebook_application_id` to match the application ID in
7171
the [Facebook developer dashboard](https://developers.facebook.com):
7272

73-
```
73+
```xml
7474
<resources>
7575
<!-- ... -->
7676
<string name="facebook_application_id" translatable="false">APPID</string>
@@ -83,7 +83,7 @@ Before invoking the FirebaseUI authentication flow, your app should check
8383
whether a
8484
[user is already signed in](https://firebase.google.com/docs/auth/android/manage-users#get_the_currently_signed-in_user) from a previous session:
8585

86-
```
86+
```java
8787
FirebaseAuth auth = FirebaseAuth.getInstance();
8888
if (auth.getCurrentUser() != null) {
8989
// already signed in
@@ -115,15 +115,15 @@ The builder provides the following customization options for the authentication
115115
a link in the small-print of the account creation step for new users. If no
116116
terms of service URL is provided, the associated small-print is omitted.
117117

118-
- A custom theme can specified for the flow, which is applied to all the
118+
- A custom theme can be specified for the flow, which is applied to all the
119119
activities in the flow for consistent customization of colors and typography.
120120

121121
#### Sign-in examples
122122

123123
If no customization is required, and only email authentication is required, the sign-in flow
124124
can be started as follows:
125125

126-
```
126+
```java
127127
startActivityForResult(
128128
// Get an instance of AuthUI based on the default app
129129
AuthUI.getInstance().createSignInIntentBuilder().build(),
@@ -133,7 +133,7 @@ startActivityForResult(
133133
You can enable sign-in providers like Google Sign-In or Facebook Log In by calling the
134134
`setProviders` method:
135135

136-
```
136+
```java
137137
startActivityForResult(
138138
AuthUI.getInstance()
139139
.createSignInIntentBuilder()
@@ -147,7 +147,7 @@ startActivityForResult(
147147

148148
If a terms of service URL and a custom theme are required:
149149

150-
```
150+
```java
151151
startActivityForResult(
152152
AuthUI.getInstance()
153153
.createSignInIntentBuilder()
@@ -164,7 +164,7 @@ Using SmartLock is recommended to provide the best user experience, but in some
164164
to disable SmartLock for testing or development. To disable SmartLock, you can use the
165165
`setIsSmartLockEnabled` method when building your sign-in Intent:
166166

167-
```
167+
```java
168168
startActivityForResult(
169169
AuthUI.getInstance()
170170
.createSignInIntentBuilder()
@@ -176,7 +176,7 @@ startActivityForResult(
176176
It is often desirable to disable SmartLock in development but enable it in production. To achieve
177177
this, you can use the `BuildConfig.DEBUG` flag to control SmartLock:
178178

179-
```
179+
```java
180180
startActivityForResult(
181181
AuthUI.getInstance()
182182
.createSignInIntentBuilder()
@@ -194,7 +194,7 @@ typically useful; the only recourse for most apps if sign in fails is to ask
194194
the user to sign in again later, or proceed with an anonymous account if
195195
supported.
196196

197-
```
197+
```java
198198
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
199199
super.onActivityResult(requestCode, resultCode, data);
200200
if (requestCode == RC_SIGN_IN) {
@@ -234,7 +234,7 @@ In order to make this process easier, AuthUI provides a simple `signOut` method
234234
to encapsulate this behavior. The method returns a `Task` which is marked
235235
completed once all necessary sign-out operations are completed:
236236

237-
```
237+
```java
238238
public void onClick(View v) {
239239
if (v.getId() == R.id.sign_out) {
240240
AuthUI.getInstance()
@@ -265,7 +265,7 @@ the flow, a new theme can be declared. Standard material design color
265265
and typography properties will take effect as expected. For example, to define
266266
a green theme:
267267

268-
```
268+
```xml
269269
<style name="GreenTheme" parent="FirebaseUI">
270270
<item name="colorPrimary">@color/material_green_500</item>
271271
<item name="colorPrimaryDark">@color/material_green_700</item>
@@ -279,7 +279,7 @@ a green theme:
279279

280280
With associated colors:
281281

282-
```
282+
```xml
283283
<color name="material_green_50">#E8F5E9</color>
284284
<color name="material_green_500">#4CAF50</color>
285285
<color name="material_green_700">#388E3C</color>
@@ -290,7 +290,7 @@ With associated colors:
290290

291291
This would then be used in the construction of the sign-in intent:
292292

293-
```
293+
```java
294294
startActivityForResult(
295295
AuthUI.getInstance(this).createSignInIntentBuilder()
296296
// ...
@@ -306,7 +306,7 @@ easily overridden by name in your application. See
306306
[the built-in strings.xml](src/main/res/values/strings.xml) and simply
307307
redefine a string to change it, for example:
308308

309-
```
309+
```java
310310
<resources>
311311
<!-- was "Signing up..." -->
312312
<string name="progress_dialog_signing_up">Creating your shiny new account...</string>
@@ -315,24 +315,37 @@ redefine a string to change it, for example:
315315

316316
### OAuth Scope Customization
317317

318+
#### Google
319+
By default, FirebaseUI requests the `email` and `profile` scopes when using Google Sign In. If you
320+
would like to request additional scopes from the user, add a string array resource named
321+
`google_permissions` to your `strings.xml` file like this:
322+
323+
```xml
324+
<!--
325+
For a list of all scopes, see:
326+
https://developers.google.com/identity/protocols/googlescopes
327+
-->
328+
<string-array name="google_permissions">
329+
<!-- Request permission to read the user's Google Drive files -->
330+
<item>https://www.googleapis.com/auth/drive.readonly</item>
331+
</string-array>
332+
```
333+
334+
318335
#### Facebook
319336

320337
By default, FirebaseUI requests the `email` and `public_profile` permissions when initiating
321-
Facebook Login. If you would like to override these scopes, add a string array resource
322-
to your application like this:
338+
Facebook Login. If you would like to override these scopes, a string array resource named
339+
`facebook_permissions` to your `strings.xml` file like this:
323340

324-
```
341+
```xml
325342
<!--
326343
See:
327344
https://developers.facebook.com/docs/facebook-login/android
328345
https://developers.facebook.com/docs/facebook-login/permissions
329346
-->
330-
<array name="facebook_permissions">
331-
<item>public_profile</item>
332-
<item>email</item>
333-
<!-- ... -->
334-
</array>
347+
<string-array name="facebook_permissions">
348+
<!-- Request permission to know the user's birthday -->
349+
<item>user_birthday</item>
350+
</string-array>
335351
```
336-
337-
Note that if you do not include at least the `email` and `public_profile` scopes, FirebaseUI
338-
will not work properly.

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ public SignInIntentBuilder setProviders(@NonNull String... providers) {
409409

410410
/**
411411
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
412+
*
413+
* <p>SmartLock is enabled by default
412414
*/
413415
public SignInIntentBuilder setIsSmartLockEnabled(boolean enabled) {
414416
mIsSmartLockEnabled = enabled;

auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import org.json.JSONException;
3737
import org.json.JSONObject;
3838

39+
import java.util.ArrayList;
3940
import java.util.Arrays;
41+
import java.util.List;
4042

4143
public class FacebookProvider implements IDPProvider, FacebookCallback<LoginResult> {
4244
public static final String ACCESS_TOKEN = "facebook_access_token";
@@ -46,6 +48,9 @@ public class FacebookProvider implements IDPProvider, FacebookCallback<LoginResu
4648

4749
private static final String TAG = "FacebookProvider";
4850
private static final String APPLICATION_ID = "application_id";
51+
private static final String EMAIL = "email";
52+
private static final String PUBLIC_PROFILE = "public_profile";
53+
4954
private CallbackManager mCallbackManager;
5055
private IDPCallback mCallbackObject;
5156

@@ -79,9 +84,19 @@ public void startLogin(Activity activity) {
7984
loginManager.registerCallback(mCallbackManager, this);
8085

8186
String[] permissions = activity.getResources().getStringArray(R.array.facebook_permissions);
87+
List<String> permissionsList = new ArrayList<>(Arrays.asList(permissions));
88+
89+
// Ensure we have email and public_profile scopes
90+
if (!permissionsList.contains(EMAIL)) {
91+
permissionsList.add(EMAIL);
92+
}
93+
94+
if (!permissionsList.contains(PUBLIC_PROFILE)) {
95+
permissionsList.add(PUBLIC_PROFILE);
96+
}
8297

83-
loginManager.logInWithReadPermissions(
84-
activity, Arrays.asList(permissions));
98+
// Log in with permissions
99+
loginManager.logInWithReadPermissions(activity, permissionsList);
85100
}
86101

87102
@Override

auth/src/main/java/com/firebase/ui/auth/provider/GoogleProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
3434
import com.google.android.gms.common.ConnectionResult;
3535
import com.google.android.gms.common.api.GoogleApiClient;
36+
import com.google.android.gms.common.api.Scope;
3637
import com.google.firebase.auth.AuthCredential;
3738
import com.google.firebase.auth.GoogleAuthProvider;
3839

@@ -60,6 +61,12 @@ public GoogleProvider(FragmentActivity activity, IDPProviderParcel parcel, @Null
6061
.requestEmail()
6162
.requestIdToken(mClientId);
6263

64+
// Add additional scopes
65+
String[] extraScopes = mActivity.getResources().getStringArray(R.array.google_permissions);
66+
for (String scopeString : extraScopes) {
67+
builder.requestScopes(new Scope(scopeString));
68+
}
69+
6370
if (!TextUtils.isEmpty(email)) {
6471
builder.setAccountName(email);
6572
}

auth/src/main/java/com/firebase/ui/auth/ui/AuthCredentialHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.firebase.ui.auth.ui;
1616

17+
import android.support.annotation.Nullable;
18+
1719
import com.firebase.ui.auth.provider.FacebookProvider;
1820
import com.firebase.ui.auth.provider.GoogleProvider;
1921
import com.firebase.ui.auth.provider.IDPResponse;
@@ -22,6 +24,8 @@
2224
import com.google.firebase.auth.GoogleAuthProvider;
2325

2426
public class AuthCredentialHelper {
27+
28+
@Nullable
2529
public static AuthCredential getAuthCredential(IDPResponse idpResponse) {
2630
switch (idpResponse.getProviderType()) {
2731
case GoogleAuthProvider.PROVIDER_ID:
@@ -32,4 +36,5 @@ public static AuthCredential getAuthCredential(IDPResponse idpResponse) {
3236
return null;
3337
}
3438
}
39+
3540
}

auth/src/main/java/com/firebase/ui/auth/ui/ChooseAccountActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.firebase.ui.auth.util.EmailFlowUtil;
3232
import com.firebase.ui.auth.util.PlayServicesHelper;
3333
import com.google.android.gms.auth.api.credentials.Credential;
34+
import com.google.android.gms.auth.api.credentials.CredentialsApi;
3435
import com.google.android.gms.auth.api.credentials.IdentityProviders;
3536
import com.google.android.gms.common.api.Status;
3637
import com.google.android.gms.tasks.OnCompleteListener;
@@ -207,7 +208,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
207208
mCredentialsApi.getPasswordFromCredential(),
208209
mCredentialsApi.getAccountTypeFromCredential()
209210
);
210-
} else if (resultCode == RESULT_CANCELED) {
211+
} else if (resultCode == RESULT_CANCELED
212+
|| resultCode == CredentialsApi.ACTIVITY_RESULT_OTHER_ACCOUNT) {
211213
// Smart lock selector cancelled, go to the AuthMethodPicker screen
212214
startAuthMethodChoice(mActivityHelper);
213215
} else if (resultCode == RESULT_FIRST_USER) {

0 commit comments

Comments
 (0)