Skip to content

Default phone #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void signIn(View view) {
.setTosUrl(getSelectedTosUrl())
.setPrivacyPolicyUrl(getSelectedPrivacyPolicyUrl())
.setIsSmartLockEnabled(mEnableCredentialSelector.isChecked(),
mEnableHintSelector.isChecked())
mEnableHintSelector.isChecked())
.setAllowNewEmailAccounts(mAllowNewEmailAccounts.isChecked())
.build(),
RC_SIGN_IN);
Expand Down
14 changes: 14 additions & 0 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ startActivityForResult(
RC_SIGN_IN);
```

When using the phone verification provider and the number is known in advance, it is possible to
provide a default phone number (in international format) that will be used to prepopulate the
country code and phone number input fields. The user is still able to edit the number if desired.

```java
// Use a Bundle to hold the default number, and pass it to the Builder via setParams:
Bundle params = new Bundle();
params.putString(AuthUI.EXTRA_DEFAULT_PHONE, "+12345678901");
IdpConfig phoneConfigWithDefaultNumber =
new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
.setParams(params)
.build();
```

#### Handling the sign-in response

##### Response codes
Expand Down
33 changes: 29 additions & 4 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.CallSuper;
Expand All @@ -28,6 +29,7 @@

import com.facebook.login.LoginManager;
import com.firebase.ui.auth.provider.TwitterProvider;
import com.firebase.ui.auth.ui.ExtraConstants;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
import com.firebase.ui.auth.util.GoogleSignInHelper;
Expand Down Expand Up @@ -104,6 +106,11 @@ public class AuthUI {
*/
public static final String PHONE_VERIFICATION_PROVIDER = PhoneAuthProvider.PROVIDER_ID;

/**
* Bundle key for the default phone number parameter
*/
public static final String EXTRA_DEFAULT_PHONE = ExtraConstants.EXTRA_PHONE;

/**
* Default value for logo resource, omits the logo from the {@link AuthMethodPickerActivity}.
*/
Expand Down Expand Up @@ -269,15 +276,21 @@ public SignInIntentBuilder createSignInIntentBuilder() {
public static class IdpConfig implements Parcelable {
private final String mProviderId;
private final List<String> mScopes;
private final Bundle mParams;

private IdpConfig(@SupportedProvider @NonNull String providerId, List<String> scopes) {
private IdpConfig(
@SupportedProvider @NonNull String providerId,
List<String> scopes,
Bundle params) {
mProviderId = providerId;
mScopes = Collections.unmodifiableList(scopes);
mParams = params;
}

private IdpConfig(Parcel in) {
mProviderId = in.readString();
mScopes = Collections.unmodifiableList(in.createStringArrayList());
mParams = in.readBundle(getClass().getClassLoader());
}

@SupportedProvider
Expand All @@ -289,6 +302,10 @@ public List<String> getScopes() {
return mScopes;
}

public Bundle getParams() {
return mParams;
}

public static final Creator<IdpConfig> CREATOR = new Creator<IdpConfig>() {
@Override
public IdpConfig createFromParcel(Parcel in) {
Expand All @@ -310,6 +327,7 @@ public int describeContents() {
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(mProviderId);
parcel.writeStringList(mScopes);
parcel.writeBundle(mParams);
}

@Override
Expand All @@ -332,12 +350,14 @@ public String toString() {
return "IdpConfig{" +
"mProviderId='" + mProviderId + '\'' +
", mScopes=" + mScopes +
", mParams=" + mParams +
'}';
}

public static class Builder {
@SupportedProvider private String mProviderId;
private List<String> mScopes = new ArrayList<>();
private Bundle mParams = new Bundle();

/**
* Builds the configuration parameters for an identity provider.
Expand Down Expand Up @@ -372,8 +392,13 @@ public Builder setPermissions(List<String> permissions) {
return this;
}

public Builder setParams(Bundle params) {
mParams = params;
return this;
}

public IdpConfig build() {
return new IdpConfig(mProviderId, mScopes);
return new IdpConfig(mProviderId, mScopes, mParams);
}
}
}
Expand Down Expand Up @@ -448,8 +473,8 @@ public T setAvailableProviders(@NonNull List<IdpConfig> idpConfigs) {
for (IdpConfig config : idpConfigs) {
if (mProviders.contains(config)) {
throw new IllegalArgumentException("Each provider can only be set once. "
+ config.getProviderId()
+ " was set twice.");
+ config.getProviderId()
+ " was set twice.");
} else {
mProviders.add(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.support.annotation.LayoutRes;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.phone.PhoneVerificationActivity;
Expand Down Expand Up @@ -34,8 +35,16 @@ public int getButtonLayout() {

@Override
public void startLogin(Activity activity) {

String phone = null;
for (AuthUI.IdpConfig idpConfig : mFlowParameters.providerInfo) {
if (idpConfig.getProviderId().equals(AuthUI.PHONE_VERIFICATION_PROVIDER)) {
phone = idpConfig.getParams().getString(AuthUI.EXTRA_DEFAULT_PHONE);
}
}

activity.startActivityForResult(
PhoneVerificationActivity.createIntent(activity, mFlowParameters, null),
PhoneVerificationActivity.createIntent(activity, mFlowParameters, phone),
RC_PHONE_FLOW);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ private void startAuthMethodChoice() {

// If there is only one provider selected, launch the flow directly
if (idpConfigs.size() == 1) {
String firstProvider = idpConfigs.get(0).getProviderId();
AuthUI.IdpConfig firstIdpConfig = idpConfigs.get(0);
String firstProvider = firstIdpConfig.getProviderId();
switch (firstProvider) {
case EmailAuthProvider.PROVIDER_ID:
// Go directly to email flow
Expand All @@ -248,8 +249,9 @@ private void startAuthMethodChoice() {
break;
case PhoneAuthProvider.PROVIDER_ID:
// Go directly to phone flow
String phone = firstIdpConfig.getParams().getString(AuthUI.EXTRA_DEFAULT_PHONE);
startActivityForResult(
PhoneVerificationActivity.createIntent(getContext(), flowParams, null),
PhoneVerificationActivity.createIntent(getContext(), flowParams, phone),
RC_PHONE_FLOW);
break;
default:
Expand Down