Skip to content

Commit 4ea4fb5

Browse files
authored
Merge pull request #284 from samtstern/master
Version 0.5.2
2 parents 4baf672 + 35693d4 commit 4ea4fb5

File tree

10 files changed

+125
-59
lines changed

10 files changed

+125
-59
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.2'
3232
3333
// FirebaseUI Database only
34-
compile 'com.firebaseui:firebase-ui-database:0.5.1'
34+
compile 'com.firebaseui:firebase-ui-database:0.5.2'
3535
3636
// FirebaseUI Auth only
37-
compile 'com.firebaseui:firebase-ui-auth:0.5.1'
37+
compile 'com.firebaseui:firebase-ui-auth:0.5.2'
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.2 | 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: 39 additions & 26 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.2'
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.2</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
@@ -123,7 +123,7 @@ The builder provides the following customization options for the authentication
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+
<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+
</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
-->
330347
<array name="facebook_permissions">
331-
<item>public_profile</item>
332-
<item>email</item>
333-
<!-- ... -->
348+
<!-- Request permission to know the user's birthday -->
349+
<item>user_birthday</item>
334350
</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/provider/FacebookProvider.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.json.JSONObject;
3838

3939
import java.util.Arrays;
40+
import java.util.List;
4041

4142
public class FacebookProvider implements IDPProvider, FacebookCallback<LoginResult> {
4243
public static final String ACCESS_TOKEN = "facebook_access_token";
@@ -46,6 +47,9 @@ public class FacebookProvider implements IDPProvider, FacebookCallback<LoginResu
4647

4748
private static final String TAG = "FacebookProvider";
4849
private static final String APPLICATION_ID = "application_id";
50+
private static final String EMAIL = "email";
51+
private static final String PUBLIC_PROFILE = "public_profile";
52+
4953
private CallbackManager mCallbackManager;
5054
private IDPCallback mCallbackObject;
5155

@@ -79,9 +83,19 @@ public void startLogin(Activity activity) {
7983
loginManager.registerCallback(mCallbackManager, this);
8084

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

83-
loginManager.logInWithReadPermissions(
84-
activity, Arrays.asList(permissions));
97+
// Log in with permissions
98+
loginManager.logInWithReadPermissions(activity, permissionsList);
8599
}
86100

87101
@Override

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

Lines changed: 11 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 = getExtraScopes();
66+
for (String scopeString : extraScopes) {
67+
builder.requestScopes(new Scope(scopeString));
68+
}
69+
6370
if (!TextUtils.isEmpty(email)) {
6471
builder.setAccountName(email);
6572
}
@@ -147,5 +154,9 @@ public void onClick(View view) {
147154
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
148155
Log.w(TAG, "onConnectionFailed:" + connectionResult);
149156
}
157+
158+
private String[] getExtraScopes() {
159+
return mActivity.getResources().getStringArray(R.array.google_permissions);
160+
}
150161
}
151162

auth/src/main/res/values/config.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@
3030
https://developers.facebook.com/docs/facebook-login/permissions
3131
-->
3232
<array name="facebook_permissions">
33-
<item>public_profile</item>
34-
<item>email</item>
33+
</array>
34+
35+
<!--
36+
The additional Google scopes that this application will request from the user. Users of
37+
FirebaseUI can override this array to customize. Note that the 'email' and 'profile' scopes are
38+
always requested.
39+
40+
For example to add the permission to read the user's files in Google Drive:
41+
<item>https://www.googleapis.com/auth/drive.readonly</item>
42+
43+
For a list of all scopes, see:
44+
https://developers.google.com/identity/protocols/googlescopes
45+
-->
46+
<array name="google_permissions">
3547
</array>
3648

3749

auth/src/test/java/com/firebase/ui/auth/test_helpers/GoogleProviderShadow.java

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

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

17-
import static org.mockito.Mockito.mock;
18-
import static org.mockito.Mockito.when;
19-
2017
import android.app.Activity;
2118
import android.os.Bundle;
22-
import android.util.Log;
2319

2420
import com.firebase.ui.auth.provider.GoogleProvider;
2521
import com.firebase.ui.auth.provider.IDPProvider;
@@ -30,6 +26,9 @@
3026
import org.robolectric.annotation.Implementation;
3127
import org.robolectric.annotation.Implements;
3228

29+
import static org.mockito.Mockito.mock;
30+
import static org.mockito.Mockito.when;
31+
3332

3433
@Implements(GoogleProvider.class)
3534
public class GoogleProviderShadow {
@@ -54,7 +53,7 @@ public GoogleProviderShadow() {
5453
public void __constructor__(Activity activity, IDPProviderParcel parcel, String email) {}
5554

5655

57-
@Implementation
56+
@Implementation
5857
public void setAuthenticationCallback(IDPProvider.IDPCallback idpCallback) {
5958
mCallback = idpCallback;
6059
}
@@ -63,4 +62,9 @@ public void setAuthenticationCallback(IDPProvider.IDPCallback idpCallback) {
6362
public void startLogin(Activity activity) {
6463
mCallback.onSuccess(mMockIdpResponse);
6564
}
65+
66+
@Implementation
67+
public String[] getExtraScopes() {
68+
return new String[]{};
69+
}
6670
}

auth/src/test/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivityTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void testAllProvidersArePopulated() {
8181

8282
AuthMethodPickerActivity authMethodPickerActivity =
8383
createActivity(providers);
84+
8485
assertEquals(providers.size(),
8586
((LinearLayout) authMethodPickerActivity.findViewById(R.id.btn_holder))
8687
.getChildCount());

0 commit comments

Comments
 (0)