Skip to content

Commit dc44c2d

Browse files
committed
Merge branch 'master' into version-1.0.0-dev
Change-Id: I7bcb4660aa7c69ba36fd1d36df73fb457ac56c56
2 parents 2ccaa0b + 9fb5779 commit dc44c2d

33 files changed

+490
-247
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ need to be sure of various other things—for instance that you'll tell us if yo
1212
know that your code infringes on other people's patents. You don't have to sign
1313
the CLA until after you've submitted your code for review and a member has
1414
approved it, but you must do it before we can put your code into our codebase.
15+
16+
### Adding new features
17+
1518
Before you start working on a larger contribution, you should get in touch with
1619
us first through the issue tracker with your idea so that we can help out and
1720
possibly guide you. Coordinating up front makes it much easier to avoid
1821
frustration later on.
1922

23+
If this has been discussed in an issue, make sure to mention the issue number.
24+
If not, go file an issue about this to make sure this is a desirable change.
25+
26+
If this is a new feature please co-ordinate with someone on [FirebaseUI-iOS](https://github.com/firebase/FirebaseUI-iOS)
27+
to make sure that we can implement this on both platforms and maintain feature parity.
28+
Feature parity (where it makes sense) is a strict requirement for feature development in FirebaseUI.
29+
2030
### Code reviews
2131

2232
All submissions, including submissions by project members, require review. We
23-
use GitHub pull requests for this purpose.
33+
use Github pull requests for this purpose. We adhere to the
34+
[Google Java style guide](https://google.github.io/styleguide/javaguide.html).
2435

2536
### The small print
2637

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>
@@ -95,7 +95,7 @@ Before invoking the FirebaseUI authentication flow, your app should check
9595
whether a
9696
[user is already signed in](https://firebase.google.com/docs/auth/android/manage-users#get_the_currently_signed-in_user) from a previous session:
9797

98-
```
98+
```java
9999
FirebaseAuth auth = FirebaseAuth.getInstance();
100100
if (auth.getCurrentUser() != null) {
101101
// already signed in
@@ -127,15 +127,15 @@ The builder provides the following customization options for the authentication
127127
a link in the small-print of the account creation step for new users. If no
128128
terms of service URL is provided, the associated small-print is omitted.
129129

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

133133
#### Sign-in examples
134134

135135
If no customization is required, and only email authentication is required, the sign-in flow
136136
can be started as follows:
137137

138-
```
138+
```java
139139
startActivityForResult(
140140
// Get an instance of AuthUI based on the default app
141141
AuthUI.getInstance().createSignInIntentBuilder().build(),
@@ -145,7 +145,7 @@ startActivityForResult(
145145
You can enable sign-in providers like Google Sign-In or Facebook Log In by calling the
146146
`setProviders` method:
147147

148-
```
148+
```java
149149
startActivityForResult(
150150
AuthUI.getInstance()
151151
.createSignInIntentBuilder()
@@ -159,7 +159,7 @@ startActivityForResult(
159159

160160
If a terms of service URL and a custom theme are required:
161161

162-
```
162+
```java
163163
startActivityForResult(
164164
AuthUI.getInstance()
165165
.createSignInIntentBuilder()
@@ -176,7 +176,7 @@ Using SmartLock is recommended to provide the best user experience, but in some
176176
to disable SmartLock for testing or development. To disable SmartLock, you can use the
177177
`setIsSmartLockEnabled` method when building your sign-in Intent:
178178

179-
```
179+
```java
180180
startActivityForResult(
181181
AuthUI.getInstance()
182182
.createSignInIntentBuilder()
@@ -188,7 +188,7 @@ startActivityForResult(
188188
It is often desirable to disable SmartLock in development but enable it in production. To achieve
189189
this, you can use the `BuildConfig.DEBUG` flag to control SmartLock:
190190

191-
```
191+
```java
192192
startActivityForResult(
193193
AuthUI.getInstance()
194194
.createSignInIntentBuilder()
@@ -206,7 +206,7 @@ typically useful; the only recourse for most apps if sign in fails is to ask
206206
the user to sign in again later, or proceed with an anonymous account if
207207
supported.
208208

209-
```
209+
```java
210210
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
211211
super.onActivityResult(requestCode, resultCode, data);
212212
if (requestCode == RC_SIGN_IN) {
@@ -246,7 +246,7 @@ In order to make this process easier, AuthUI provides a simple `signOut` method
246246
to encapsulate this behavior. The method returns a `Task` which is marked
247247
completed once all necessary sign-out operations are completed:
248248

249-
```
249+
```java
250250
public void onClick(View v) {
251251
if (v.getId() == R.id.sign_out) {
252252
AuthUI.getInstance()
@@ -303,7 +303,7 @@ the flow, a new theme can be declared. Standard material design color
303303
and typography properties will take effect as expected. For example, to define
304304
a green theme:
305305

306-
```
306+
```xml
307307
<style name="GreenTheme" parent="FirebaseUI">
308308
<item name="colorPrimary">@color/material_green_500</item>
309309
<item name="colorPrimaryDark">@color/material_green_700</item>
@@ -317,7 +317,7 @@ a green theme:
317317

318318
With associated colors:
319319

320-
```
320+
```xml
321321
<color name="material_green_50">#E8F5E9</color>
322322
<color name="material_green_500">#4CAF50</color>
323323
<color name="material_green_700">#388E3C</color>
@@ -328,7 +328,7 @@ With associated colors:
328328

329329
This would then be used in the construction of the sign-in intent:
330330

331-
```
331+
```java
332332
startActivityForResult(
333333
AuthUI.getInstance(this).createSignInIntentBuilder()
334334
// ...
@@ -344,7 +344,7 @@ easily overridden by name in your application. See
344344
[the built-in strings.xml](src/main/res/values/strings.xml) and simply
345345
redefine a string to change it, for example:
346346

347-
```
347+
```java
348348
<resources>
349349
<!-- was "Signing up..." -->
350350
<string name="progress_dialog_signing_up">Creating your shiny new account...</string>
@@ -353,24 +353,37 @@ redefine a string to change it, for example:
353353

354354
### OAuth Scope Customization
355355

356+
#### Google
357+
By default, FirebaseUI requests the `email` and `profile` scopes when using Google Sign In. If you
358+
would like to request additional scopes from the user, add a string array resource named
359+
`google_permissions` to your `strings.xml` file like this:
360+
361+
```xml
362+
<!--
363+
For a list of all scopes, see:
364+
https://developers.google.com/identity/protocols/googlescopes
365+
-->
366+
<string-array name="google_permissions">
367+
<!-- Request permission to read the user's Google Drive files -->
368+
<item>https://www.googleapis.com/auth/drive.readonly</item>
369+
</string-array>
370+
```
371+
372+
356373
#### Facebook
357374

358375
By default, FirebaseUI requests the `email` and `public_profile` permissions when initiating
359-
Facebook Login. If you would like to override these scopes, add a string array resource
360-
to your application like this:
376+
Facebook Login. If you would like to override these scopes, a string array resource named
377+
`facebook_permissions` to your `strings.xml` file like this:
361378

362-
```
379+
```xml
363380
<!--
364381
See:
365382
https://developers.facebook.com/docs/facebook-login/android
366383
https://developers.facebook.com/docs/facebook-login/permissions
367384
-->
368-
<array name="facebook_permissions">
369-
<item>public_profile</item>
370-
<item>email</item>
371-
<!-- ... -->
372-
</array>
385+
<string-array name="facebook_permissions">
386+
<!-- Request permission to know the user's birthday -->
387+
<item>user_birthday</item>
388+
</string-array>
373389
```
374-
375-
Note that if you do not include at least the `email` and `public_profile` scopes, FirebaseUI
376-
will not work properly.

auth/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
android:name="com.firebase.ui.auth.ui.account_link.SaveCredentialsActivity"
3737
android:label="@string/default_toolbar_title"
3838
android:theme="@style/FirebaseUI.Translucent" />
39-
<activity
40-
android:name="com.firebase.ui.auth.ui.account_link.AccountLinkInitActivity"
41-
android:theme="@style/FirebaseUI" />
4239
<activity
4340
android:name="com.firebase.ui.auth.ui.account_link.WelcomeBackIDPPrompt"
4441
android:label="@string/title_welcome_back_idp_prompt"

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

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

470470
/**
471471
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
472+
*
473+
* <p>SmartLock is enabled by default
472474
*/
473475
public SignInIntentBuilder setIsSmartLockEnabled(boolean enabled) {
474476
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)