本文整理汇总了Java中com.google.firebase.auth.EmailAuthProvider类的典型用法代码示例。如果您正苦于以下问题:Java EmailAuthProvider类的具体用法?Java EmailAuthProvider怎么用?Java EmailAuthProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmailAuthProvider类属于com.google.firebase.auth包,在下文中一共展示了EmailAuthProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reauthenticate
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void reauthenticate() {
// [START reauthenticate]
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
.getCredential("[email protected]", "password1234");
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "User re-authenticated.");
}
});
// [END reauthenticate]
}
示例2: getCredential
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
public static AuthCredential getCredential(final JSONObject credential) throws Exception {
final String providerId = credential.getString("provider");
AuthCredential authCredential;
if (providerId.equals(EmailAuthProvider.PROVIDER_ID)) {
authCredential = getEmailAuthCredential(credential);
} else if (providerId.equals(FacebookAuthProvider.PROVIDER_ID)) {
authCredential = getFacebookAuthCredential(credential);
} else if (providerId.equals(GithubAuthProvider.PROVIDER_ID)) {
authCredential = getGithubAuthCredential(credential);
} else if (providerId.equals(GoogleAuthProvider.PROVIDER_ID)) {
authCredential = getGoogleAuthCredential(credential);
} else if (providerId.equals(TwitterAuthProvider.PROVIDER_ID)) {
authCredential = getTwitterAuthCredential(credential);
} else {
throw new Exception("Unknown provider ID: " + providerId);
}
return authCredential;
}
示例3: validate
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void validate() {
String passwordText = passwordEntry.getText().toString();
if (TextUtils.isEmpty(passwordText)) {
passwordEntry.setError(getString(R.string.error_field_required));
return;
}
if (user.getEmail() != null) {
AuthCredential credential = EmailAuthProvider.getCredential(user.getEmail(), passwordText);
user.reauthenticate(credential).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("Re-authenticated");
user.delete();
dismiss();
}
});
}
}
示例4: onSuccess
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
@Override
public void onSuccess(String provider) {
mActivity.getDialogHolder().dismissDialog();
if (provider == null) {
throw new IllegalStateException(
"No provider even though we received a FirebaseAuthUserCollisionException");
} else if (provider.equals(EmailAuthProvider.PROVIDER_ID)) {
// Start email welcome back flow
mActivity.startActivityForResult(
WelcomeBackPasswordPrompt.createIntent(
mActivity,
mActivity.getFlowParams(),
mResponse),
mAccountLinkRequestCode);
} else {
// Start Idp welcome back flow
mActivity.startActivityForResult(
WelcomeBackIdpPrompt.createIntent(
mActivity,
mActivity.getFlowParams(),
new User.Builder(provider, mResponse.getEmail()).build(),
mResponse),
mAccountLinkRequestCode);
}
}
示例5: providerIdToAccountType
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
/**
* Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to a
* Credentials API account type (such as {@link IdentityProviders#GOOGLE}).
*/
public static String providerIdToAccountType(@AuthUI.SupportedProvider @NonNull String providerId) {
switch (providerId) {
case GoogleAuthProvider.PROVIDER_ID:
return IdentityProviders.GOOGLE;
case FacebookAuthProvider.PROVIDER_ID:
return IdentityProviders.FACEBOOK;
case TwitterAuthProvider.PROVIDER_ID:
return IdentityProviders.TWITTER;
case PhoneAuthProvider.PROVIDER_ID:
return PHONE_IDENTITY;
// The account type for email/password creds is null
case EmailAuthProvider.PROVIDER_ID:
default:
return null;
}
}
示例6: reauthenticateUser
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
@Override
public Completable reauthenticateUser(final String password) {
return Completable.create(new CompletableOnSubscribe() {
@Override
public void subscribe(final CompletableEmitter e) throws Exception {
if (auth == null) {
auth = FirebaseAuth.getInstance();
}
final FirebaseUser user = auth.getCurrentUser();
AuthCredential credential = EmailAuthProvider
.getCredential(user.getEmail(), password);
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
e.onComplete();
} else {
e.onError(task.getException());
}
}
});
}
});
}
示例7: validate
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void validate() {
final String oldPasswordText = oldPasswordEntry.getText().toString();
final String newPasswordText = newPasswordEntry.getText().toString();
final String confirmPasswordText = confirmPasswordEntry.getText().toString();
if (TextUtils.isEmpty(oldPasswordText)) {
oldPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (TextUtils.isEmpty(newPasswordText)) {
newPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (TextUtils.isEmpty(confirmPasswordText)) {
confirmPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (!newPasswordText.equals(confirmPasswordText)) {
confirmPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (user.getEmail() != null) {
AuthCredential credential = EmailAuthProvider.getCredential(user.getEmail(), oldPasswordText);
user.reauthenticate(credential).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("Re-authenticated");
updatePassword(newPasswordText);
}
});
}
}
示例8: linkAccount
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "linkWithCredential:success");
FirebaseUser user = task.getResult().getUser();
updateUI(user);
} else {
Log.w(TAG, "linkWithCredential:failure", task.getException());
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
示例9: linkAccount
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "linkWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
示例10: invalidateEditAccountPref
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
/**
* Update the visibility of the edit account preference based on whether the current user
* is authenticated using the email provider.
*/
private void invalidateEditAccountPref() {
mPrefEditAccount.setVisible(false);
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null) {
for(UserInfo info : user.getProviderData()) {
if(info.getProviderId().equals(EmailAuthProvider.PROVIDER_ID)) {
mPrefEditAccount.setVisible(true);
return;
}
}
}
}
示例11: linkCredentials
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
@Override
public Observable<User> linkCredentials(Credentials credentials) {
AuthCredential emailCredentials = EmailAuthProvider.getCredential(credentials.getEmail(), credentials.getPassword());
return firebaseWrapper.linkAccount(emailCredentials)
.map(authResult -> authResult.getUser())
.map(firebaseUser -> UserAdapter.fromFirebaseUser(firebaseUser));
}
示例12: onSaveInstanceState
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelable(ExtraConstants.EXTRA_USER,
new User.Builder(EmailAuthProvider.PROVIDER_ID, mEmailEditText.getText().toString())
.setName(mNameEditText.getText().toString())
.setPhotoUri(mUser.getPhotoUri())
.build());
super.onSaveInstanceState(outState);
}
示例13: startAuthMethodChoice
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
private void startAuthMethodChoice() {
FlowParameters flowParams = getFlowParams();
List<AuthUI.IdpConfig> idpConfigs = flowParams.providerInfo;
// If there is only one provider selected, launch the flow directly
if (idpConfigs.size() == 1) {
AuthUI.IdpConfig firstIdpConfig = idpConfigs.get(0);
String firstProvider = firstIdpConfig.getProviderId();
switch (firstProvider) {
case EmailAuthProvider.PROVIDER_ID:
// Go directly to email flow
startActivityForResult(
EmailActivity.createIntent(getContext(), flowParams),
RC_EMAIL_FLOW);
break;
case PhoneAuthProvider.PROVIDER_ID:
// Go directly to phone flow
Bundle params = firstIdpConfig.getParams();
Intent phoneActivityIntent = PhoneActivity
.createIntent(getContext(), flowParams, params);
startActivityForResult(
phoneActivityIntent,
RC_PHONE_FLOW);
break;
default:
// Launch IDP flow
redirectToIdpSignIn(null, ProviderUtils.providerIdToAccountType(firstProvider));
break;
}
} else {
startActivityForResult(
AuthMethodPickerActivity.createIntent(
getContext(),
flowParams),
RC_AUTH_METHOD_PICKER);
}
getDialogHolder().dismissDialog();
}
示例14: signInWithEmailAndPassword
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
/**
* Begin sign in process with email and password from a SmartLock credential. On success, finish
* with {@link Activity#RESULT_OK}. On failure, delete the credential from SmartLock (if
* applicable) and then launch the auth method picker flow.
*/
private void signInWithEmailAndPassword(String email, String password) {
final IdpResponse response =
new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID, email).build())
.build();
getAuthHelper().getFirebaseAuth()
.signInWithEmailAndPassword(email, password)
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
finish(Activity.RESULT_OK, response.toIntent());
}
})
.addOnFailureListener(new TaskFailureLogger(
TAG, "Error signing in with email and password"))
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseAuthInvalidUserException
|| e instanceof FirebaseAuthInvalidCredentialsException) {
// In this case the credential saved in SmartLock was not
// a valid credential, we should delete it from SmartLock
// before continuing.
deleteCredentialAndRedirect();
} else {
startAuthMethodChoice();
}
}
});
}
示例15: testSignUpButton_validatesFields
import com.google.firebase.auth.EmailAuthProvider; //导入依赖的package包/类
@Test
public void testSignUpButton_validatesFields() {
EmailActivity emailActivity = createActivity();
// Trigger RegisterEmailFragment (bypass check email)
emailActivity.onNewUser(
new User.Builder(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build());
Button button = emailActivity.findViewById(R.id.button_create);
button.performClick();
TextInputLayout nameLayout = emailActivity.findViewById(R.id.name_layout);
TextInputLayout passwordLayout = emailActivity.findViewById(R.id.password_layout);
assertEquals(
emailActivity.getString(R.string.fui_required_field),
nameLayout.getError().toString());
assertEquals(
String.format(
emailActivity.getResources().getQuantityString(
R.plurals.fui_error_weak_password,
R.integer.fui_min_password_length),
emailActivity.getResources()
.getInteger(R.integer.fui_min_password_length)
),
passwordLayout.getError().toString());
}