Skip to content

Commit

Permalink
Merge pull request #284 from samtstern/master
Browse files Browse the repository at this point in the history
Version 0.5.2
  • Loading branch information
samtstern authored Sep 6, 2016
2 parents 4baf672 + 35693d4 commit 4ea4fb5
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 59 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ those separately in your app.
In your `app/build.gradle` file add a dependency on one of the FirebaseUI
libraries.

```
```groovy
dependencies {
// Single target that includes all FirebaseUI libraries
compile 'com.firebaseui:firebase-ui:0.5.1'
compile 'com.firebaseui:firebase-ui:0.5.2'
// FirebaseUI Database only
compile 'com.firebaseui:firebase-ui-database:0.5.1'
compile 'com.firebaseui:firebase-ui-database:0.5.2'
// FirebaseUI Auth only
compile 'com.firebaseui:firebase-ui-auth:0.5.1'
compile 'com.firebaseui:firebase-ui-auth:0.5.2'
}
```

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

| FirebaseUI Version | Firebase/Play Services Version |
|--------------------|--------------------------------|
| 0.5.1 | 9.4.0 |
| 0.5.2 | 9.4.0 |
| 0.4.4 | 9.4.0 |
| 0.4.3 | 9.2.1 |
| 0.4.2 | 9.2.0 |
Expand Down
65 changes: 39 additions & 26 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ Firebase: see the
Then, add the FirebaseUI auth library dependency. If your project uses
Gradle, add:

```
```groovy
dependencies {
// ...
compile 'com.firebaseui:firebase-ui-auth:0.5.1'
compile 'com.firebaseui:firebase-ui-auth:0.5.2'
}
```

If instead your project uses Maven, add:

```
```xml
<dependency>
<groupId>com.firebaseui</groupId>
<artifactId>firebase-ui-auth</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</dependency>
```

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

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

```
```java
FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
// already signed in
Expand Down Expand Up @@ -123,7 +123,7 @@ The builder provides the following customization options for the authentication
If no customization is required, and only email authentication is required, the sign-in flow
can be started as follows:

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

```
```java
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
Expand All @@ -147,7 +147,7 @@ startActivityForResult(

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

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

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

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

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

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

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

With associated colors:

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

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

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

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

### OAuth Scope Customization

#### Google
By default, FirebaseUI requests the `email` and `profile` scopes when using Google Sign In. If you
would like to request additional scopes from the user, add a string array resource named
`google_permissions` to your `strings.xml` file like this:

```xml
<!--
For a list of all scopes, see:
https://developers.google.com/identity/protocols/googlescopes
-->
<array name="google_permissions">
<!-- Request permission to read the user's Google Drive files -->
<item>https://www.googleapis.com/auth/drive.readonly</item>
</array>
```


#### Facebook

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

```
```xml
<!--
See:
https://developers.facebook.com/docs/facebook-login/android
https://developers.facebook.com/docs/facebook-login/permissions
-->
<array name="facebook_permissions">
<item>public_profile</item>
<item>email</item>
<!-- ... -->
<!-- Request permission to know the user's birthday -->
<item>user_birthday</item>
</array>
```

Note that if you do not include at least the `email` and `public_profile` scopes, FirebaseUI
will not work properly.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;

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

private static final String TAG = "FacebookProvider";
private static final String APPLICATION_ID = "application_id";
private static final String EMAIL = "email";
private static final String PUBLIC_PROFILE = "public_profile";

private CallbackManager mCallbackManager;
private IDPCallback mCallbackObject;

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

String[] permissions = activity.getResources().getStringArray(R.array.facebook_permissions);
List<String> permissionsList = Arrays.asList(permissions);

// Ensure we have email and public_profile scopes
if (!permissionsList.contains(EMAIL)) {
permissionsList.add(EMAIL);
}

if (!permissionsList.contains(PUBLIC_PROFILE)) {
permissionsList.add(PUBLIC_PROFILE);
}

loginManager.logInWithReadPermissions(
activity, Arrays.asList(permissions));
// Log in with permissions
loginManager.logInWithReadPermissions(activity, permissionsList);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Scope;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.GoogleAuthProvider;

Expand Down Expand Up @@ -60,6 +61,12 @@ public GoogleProvider(FragmentActivity activity, IDPProviderParcel parcel, @Null
.requestEmail()
.requestIdToken(mClientId);

// Add additional scopes
String[] extraScopes = getExtraScopes();
for (String scopeString : extraScopes) {
builder.requestScopes(new Scope(scopeString));
}

if (!TextUtils.isEmpty(email)) {
builder.setAccountName(email);
}
Expand Down Expand Up @@ -147,5 +154,9 @@ public void onClick(View view) {
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.w(TAG, "onConnectionFailed:" + connectionResult);
}

private String[] getExtraScopes() {
return mActivity.getResources().getStringArray(R.array.google_permissions);
}
}

16 changes: 14 additions & 2 deletions auth/src/main/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@
https://developers.facebook.com/docs/facebook-login/permissions
-->
<array name="facebook_permissions">
<item>public_profile</item>
<item>email</item>
</array>

<!--
The additional Google scopes that this application will request from the user. Users of
FirebaseUI can override this array to customize. Note that the 'email' and 'profile' scopes are
always requested.
For example to add the permission to read the user's files in Google Drive:
<item>https://www.googleapis.com/auth/drive.readonly</item>
For a list of all scopes, see:
https://developers.google.com/identity/protocols/googlescopes
-->
<array name="google_permissions">
</array>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

package com.firebase.ui.auth.test_helpers;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.firebase.ui.auth.provider.GoogleProvider;
import com.firebase.ui.auth.provider.IDPProvider;
Expand All @@ -30,6 +26,9 @@
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


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


@Implementation
@Implementation
public void setAuthenticationCallback(IDPProvider.IDPCallback idpCallback) {
mCallback = idpCallback;
}
Expand All @@ -63,4 +62,9 @@ public void setAuthenticationCallback(IDPProvider.IDPCallback idpCallback) {
public void startLogin(Activity activity) {
mCallback.onSuccess(mMockIdpResponse);
}

@Implementation
public String[] getExtraScopes() {
return new String[]{};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void testAllProvidersArePopulated() {

AuthMethodPickerActivity authMethodPickerActivity =
createActivity(providers);

assertEquals(providers.size(),
((LinearLayout) authMethodPickerActivity.findViewById(R.id.btn_holder))
.getChildCount());
Expand Down
Loading

0 comments on commit 4ea4fb5

Please sign in to comment.