// Link the current user with an email / password credential. protected Task LinkWithEmailCredentialAsync() { if (auth.CurrentUser == null) { DebugLog("Not signed in, unable to link credential to user."); TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); tcs.SetException(new Exception("Not signed in")); return(tcs.Task); } DebugLog("Attempting to link credential to user..."); Credential cred = EmailAuthProvider.GetCredential(email, password); if (signInAndFetchProfile) { return(auth.CurrentUser.LinkAndRetrieveDataWithCredentialAsync(cred).ContinueWith( task => { if (LogTaskCompletion(task, "Link Credential")) { DisplaySignInResult(task.Result, 1); } })); } return(auth.CurrentUser.LinkWithCredentialAsync(cred).ContinueWith(task => { if (LogTaskCompletion(task, "Link Credential")) { DisplayDetailedUserInfo(task.Result, 1); } })); }
public void LoginUser() { string emailInput = email.text; string passwordInput = password.text; Credential credential = EmailAuthProvider.GetCredential(emailInput, passwordInput); auth.SignInWithCredentialAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); }); }
public void sendSmsCode(int registerOrreset) { try{ VerifyCodeSettings settings = new VerifyCodeSettings.Builder() .action(registerOrreset) .sendInterval(30) .locale(Locale.CHINA) .build(); HuaweiService.Task task = EmailAuthProvider.requestVerifyCode(email.text.Trim(), settings); task.addOnSuccessListener(TaskExecutors.uiThread(), new HuaweiOnsuccessListener <VerifyCodeResult>((codeResult) => { PanelController.popupinstance.ShowInfo("code send successfully!"); })) .addOnFailureListener(TaskExecutors.uiThread(), new HuaweiOnFailureListener((e) => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); })); }catch (System.Exception e) { Error error = new Error(); error.message = e.Message; PanelController.popupinstance.ShowError(error); } }
public async void VincularUsuarioAnonimo() { if (auth.CurrentUser.IsAnonymous == true) { PreCadastro(); Credential credential = EmailAuthProvider.GetCredential(email.text, senha.text); await auth.CurrentUser.LinkWithCredentialAsync(credential).ContinueWith(task => { }); await auth.SignInWithCredentialAsync(credential).ContinueWith(task => { }); if (auth.CurrentUser.IsAnonymous == false) { ReenviarEmailVerificacaoAnonimo(); } else { Debug.Log("Verifique se o email digitado já não possui cadastro ou a senha está fora dos requisitos."); PosCadastro(); } } }
async System.Threading.Tasks.Task LinkAccount() { // Make sure form is valid if (!ValidateLinkForm()) { return; } // Get email and password from form var email = mEmailField.Text; var password = mPasswordField.Text; // Create EmailAuthCredential with email and password AuthCredential credential = EmailAuthProvider.GetCredential(email, password); // Link the anonymous user to the email credential ShowProgressDialog(); // [START link_credential] try { var result = await mAuth.CurrentUser.LinkWithCredentialAsync(credential); } catch (Exception ex) { Toast.MakeText(this, "Authentication failed.", ToastLength.Short).Show(); } // [START_EXCLUDE] HideProgressDialog(); // [END_EXCLUDE] // [END link_credential] }
public void verify(int resetOrregister) { VerifyCodeSettings settings = new VerifyCodeSettings.Builder() .action(resetOrregister) .sendInterval(30) .locale(Locale.CHINA) .build(); if (isPhoneOrEmail) { task = EmailAuthProvider.requestVerifyCode(isModifyPassword?emailorPhone.text.Trim():newemailorPhoneorpassword.text.Trim(), settings); } else { task = PhoneAuthProvider.requestVerifyCode("+86", isModifyPassword?emailorPhone.text.Trim():newemailorPhoneorpassword.text.Trim(), settings); } task.addOnSuccessListener(TaskExecutors.uiThread(), new HuaweiOnsuccessListener <VerifyCodeResult>( (codeResult) => { showMessage.text = "code send successfully!"; PanelController.popupinstance.ShowInfo("code send successfully!"); })) .addOnFailureListener(TaskExecutors.uiThread(), new HuaweiOnFailureListener((e) => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); showMessage.text = e.toString(); })); }
public void verify() { bool result = false; VerifyCodeSettings settings = new VerifyCodeSettings.Builder() .action(VerifyCodeSettings.ACTION_REGISTER_LOGIN) .sendInterval(30) .locale(Locale.CHINA) .build(); HuaweiService.Task task = EmailAuthProvider.requestVerifyCode(emailorPhone.text, settings); task.addOnSuccessListener(TaskExecutors.uiThread(), new HuaweiOnsuccessListener <VerifyCodeResult>( (codeResult) => { result = true; UnityMainThread.instance.AddJob(() => { PanelController.popupinstance.ShowInfo("sms code send successfully!"); }); })) .addOnFailureListener(TaskExecutors.uiThread(), new HuaweiOnFailureListener((e) => { UnityMainThread.instance.AddJob(() => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); }); })); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); // To use this you have to set up a project in the Firebase console and add the google-services.json file var baseOptions = FirebaseOptions.FromResource(Application.Context); var options = new FirebaseOptions.Builder(baseOptions) .SetProjectId(baseOptions.StorageBucket.Split('.')[0]) .Build(); var fa = FirebaseApp.InitializeApp(Application.Context, options, "Xamarin"); //FirebaseApp fa = FirebaseApp.InitializeApp(Application.Context); mAuth = FirebaseAuth.GetInstance(fa); if (mAuth == null) { Console.WriteLine("mAuth is null"); } AuthCredential credential = EmailAuthProvider.GetCredential("*****@*****.**", "password"); var creds = mAuth.SignInWithEmailAndPassword("*****@*****.**", "password"); // Here the program crashes due to a null mAuth }
void signIn() { var email = $"{DisplayName}@blestx.local"; var password = $"{email}{email.GetHashCode()}"; Debug.Log($"[EmailAuth::signIn] Signing in {DisplayName} / {email}"); var credential = EmailAuthProvider.GetCredential(email, password); _auth.SignInWithCredentialAsync(credential) .ContinueWithOnMainThread(handleSignInWithUser); }
void createUser() { var email = $"{DisplayName}@reticle.local"; var password = $"{email}{email.GetHashCode()}"; Debug.Log($"[EmailAuth::createUser] Creating {DisplayName} / {email}"); var credential = EmailAuthProvider.GetCredential(email, password); _auth.CreateUserWithEmailAndPasswordAsync(email, password) .ContinueWithOnMainThread(handleSignInWithUser); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteAccount_Click(object sender, EventArgs e) { LayoutInflater inflater = LayoutInflater.From(this); View view = inflater.Inflate(Resource.Layout.dialog_delete_account, null); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetView(view); var email = view.FindViewById <EditText>(Resource.Id.dialog_delete_email); var password = view.FindViewById <EditText>(Resource.Id.dialog_delete_password); alertBuilder.SetTitle("Delete Account") .SetPositiveButton("Submit", delegate { try { //update current user var user = auth.CurrentUser; if (user != null) { uid = user.Uid; //delete from auth var reauth = auth.CurrentUser.ReauthenticateAsync(EmailAuthProvider .GetCredential(email.Text, password.Text)).ContinueWith(task => { if (task.IsCompletedSuccessfully) { Task result = user.Delete().AddOnCompleteListener(this); Toast.MakeText(this, "Yeah!", ToastLength.Short).Show(); } else { Toast.MakeText(this, "Failed to reauthenticate account.", ToastLength.Short).Show(); } }); } } catch (Exception ex) { Toast.MakeText(this, "Sorry, an error occured during delete", ToastLength.Short).Show(); } }) .SetNegativeButton("No", delegate { alertBuilder.Dispose(); }); AlertDialog alertDialog = alertBuilder.Create(); alertDialog.Show(); }
// Sign-in with an email and password. public Task SigninWithEmailAsync() { DebugLog(string.Format("Attempting to sign in as {0}...", email)); DisableUI(); if (signInAndFetchProfile) { return(auth.SignInAndRetrieveDataWithCredentialAsync( EmailAuthProvider.GetCredential(email, password)).ContinueWith( HandleSignInWithSignInResult)); } return(auth.SignInWithEmailAndPasswordAsync(email, password) .ContinueWith(HandleSignInWithUser)); }
public void SignInWithGoogle() { var editorSignInCompleted = new TaskCompletionSource <FirebaseUser> (); auth.SignInWithCredentialAsync(EmailAuthProvider.GetCredential("*****@*****.**", "password")).ContinueWith(authTask => { if (authTask.IsCanceled) { editorSignInCompleted.SetCanceled(); } else if (authTask.IsFaulted) { editorSignInCompleted.SetException(authTask.Exception); } else { editorSignInCompleted.SetResult(authTask.Result); } }); if (auth.CurrentUser == null || auth.CurrentUser.Email != "debug code") { return; } /*GoogleSignIn.Configuration = new GoogleSignInConfiguration { * RequestIdToken = true, * WebClientId = "796549363210-pn3ob20k5772fma8moj25kt3ur9dtpn1.apps.googleusercontent.com" * }; * * var signIn = GoogleSignIn.DefaultInstance.SignIn (); * * var signInCompleted = new TaskCompletionSource<FirebaseUser> (); * signIn.ContinueWith (task => { * if (task.IsCanceled) { * signInCompleted.SetCanceled (); * } else if (task.IsFaulted) { * signInCompleted.SetException (task.Exception); * } else { * var credential = GoogleAuthProvider.GetCredential (task.Result.IdToken, null); * auth.SignInWithCredentialAsync(credential).ContinueWith(authTask => { * if (authTask.IsCanceled) { * signInCompleted.SetCanceled(); * } else if (authTask.IsFaulted) { * signInCompleted.SetException(authTask.Exception); * } else { * signInCompleted.SetResult(authTask.Result); * } * }); * } * });*/ }
public void RequestVerifyCodeWithEmail() { VerifyCodeSettings verifyCodeSettings = new VerifyCodeSettings.Builder() .Action(VerifyCodeSettings.ACTION_REGISTER_LOGIN) .Locale(Locale.GetDefault()) .SendInterval(30).Build(); EmailAuthProvider.RequestVerifyCode(EmailAddress.text, verifyCodeSettings) .AddOnSuccessListener(result => { verifyCodeEmail.SetActive(true); }) .AddOnFailureListener(error => { loggedInUser.text = error.WrappedExceptionMessage; }); }
public async void ReautenticarUsuario() { Credential credential = EmailAuthProvider.GetCredential(email.text, senha.text); if (auth.CurrentUser != null) { PreCadastro(); await auth.CurrentUser.ReauthenticateAsync(credential).ContinueWith(task => { }); PosCadastro(); Debug.Log("Sua conta foi reautenticada!"); } }
public async Task <string> EditPassword(string oldPassword, string newPassword) { try { string current_email = FirebaseAuth.Instance.CurrentUser.Email; AuthCredential credential = EmailAuthProvider.GetCredential(current_email, oldPassword); await FirebaseAuth.Instance.CurrentUser.Reauthenticate(credential); //per cambiare password bisogna riautenticare await FirebaseAuth.Instance.CurrentUser.UpdatePasswordAsync(newPassword); return("ok"); } catch { return(null); } }
public void OnLoginClicked() { try { if (verifyCode.text.Trim() != "") { credential = EmailAuthProvider.credentialWithVerifyCode(email.text.Trim(), password.text.Trim(), verifyCode.text.Trim()); } else { credential = EmailAuthProvider.credentialWithPassword(email.text, password.text); } if (credential.getProvider() == AGConnectAuthCredential.Email_Provider) { AGConnectAuth.getInstance().signIn(credential) .addOnSuccessListener(new HuaweiOnsuccessListener <SignInResult>((signresult) => { UnityMainThread.instance.AddJob(() => { PanelController.popupinstance.ShowInfo("Login in successfully"); PanelController.userInfo.ParentPanel = this; PanelController.getInstance().OpenPanel(PanelController.userInfo); }); })).addOnFailureListener(new HuaweiOnFailureListener((e ) => { UnityMainThread.instance.AddJob(() => { Error error = new Error(); error.message = e.toString(); PanelController.popupinstance.ShowError(error); }); })); } } catch (System.Exception e) { Error error = new Error(); error.message = e.Message; PanelController.popupinstance.ShowError(error); } }
public async Task <bool> DeleteUser(string password) { var user = FirebaseAuth.Instance.CurrentUser; try { var credential = EmailAuthProvider.GetCredential(user.Email, password); await user.ReauthenticateAsync(credential); await user.DeleteAsync(); } catch (Exception) { return(await Task.FromResult(false)); } return(await Task.FromResult(true)); }
public void SignInWithCredential(string email, string password) { Credential credential = EmailAuthProvider.GetCredential(email, password); _auth.SignInWithCredentialAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Log.Error("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { Log.Error("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; Log.Debug(string.Format("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId)); }); }
// Unlink the email credential from the currently logged in user. protected Task UnlinkEmailAsync() { if (auth.CurrentUser == null) { DebugLog("Not signed in, unable to unlink"); TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); tcs.SetException(new Exception("Not signed in")); return(tcs.Task); } DebugLog("Unlinking email credential"); DisableUI(); return(auth.CurrentUser.UnlinkAsync( EmailAuthProvider.GetCredential(email, password).Provider) .ContinueWith(task => { EnableUI(); LogTaskCompletion(task, "Unlinking"); })); }
private void SendVerificationCode() { VerifyCodeSettings settings = VerifyCodeSettings.NewBuilder() .Action(VerifyCodeSettings.ActionRegisterLogin) .SendInterval(30) .Locale(Locale.English) .Build(); if (type == Type.Email) { string email = edtAccount.Text.ToString().Trim(); try { EmailAuthProvider.RequestVerifyCode(email, settings); Log.Info(TAG, "RequestVerifyCode called successfully."); } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Long).Show(); } } else { string countryCode = edtCountryCode.Text.ToString().Trim(); string phoneNumber = edtAccount.Text.ToString().Trim(); try { PhoneAuthProvider.RequestVerifyCode(countryCode, phoneNumber, settings); Log.Info(TAG, "RequestVerifyCode function called successfully."); } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Long).Show(); } } }
// 사용자 재인증 private void ReAuth() { user = AuthManager.firebaseAuth.CurrentUser; Credential credential = EmailAuthProvider.GetCredential(user.Email, currentPW); if (user != null) { user.ReauthenticateAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("ReauthenticateAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("ReauthenticateAsync encountered an error: " + task.Exception); return; } Debug.Log("Successfully reauthenticated."); IsSuccessOnReAuth = true; }); } }
private void BtnLogin_Click(object sender, EventArgs e) { if (type == Type.Email) { string email = edtAccount.Text.ToString().Trim(); string password = edtPassword.Text.ToString().Trim(); string verifyCode = edtVerifyCode.Text.ToString().Trim(); IAGConnectAuthCredential credential; if (TextUtils.IsEmpty(verifyCode)) { credential = EmailAuthProvider.CredentialWithPassword(email, password); } else { credential = EmailAuthProvider.CredentialWithVerifyCode(email, password, verifyCode); } SignIn(credential); } else { string countryCode = edtCountryCode.Text.ToString().Trim(); string phoneNumber = edtAccount.Text.ToString().Trim(); string password = edtPassword.Text.ToString().Trim(); string verifyCode = edtVerifyCode.Text.ToString().Trim(); IAGConnectAuthCredential credential; if (TextUtils.IsEmpty(verifyCode)) { credential = PhoneAuthProvider.CredentialWithPassword(countryCode, phoneNumber, password); } else { credential = PhoneAuthProvider.CredentialWithVerifyCode(countryCode, phoneNumber, password, verifyCode); } SignIn(credential); } }
// Reauthenticate the user with the current email / password. protected Task ReauthenticateAsync() { FirebaseUser user = auth.CurrentUser; if (user == null) { DebugLog("Not signed in, unable to reauthenticate user."); TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); tcs.SetException(new Exception("Not signed in")); return(tcs.Task); } DebugLog("Reauthenticating..."); DisableUI(); Credential cred = EmailAuthProvider.GetCredential(email, password); if (signInAndFetchProfile) { return(user.ReauthenticateAndRetrieveDataAsync(cred).ContinueWith(task => { EnableUI(); if (LogTaskCompletion(task, "Reauthentication")) { DisplaySignInResult(task.Result, 1); } })); } return(user.ReauthenticateAsync(cred).ContinueWith(task => { EnableUI(); if (LogTaskCompletion(task, "Reauthentication")) { DisplayDetailedUserInfo(auth.CurrentUser, 1); } })); }
/// <summary> /// Resets the password with firebase authentication. /// </summary> /// <param name="old_password">The old password.</param> /// <param name="new_password">The new password.</param> /// <returns> /// return updated password /// </returns> public async Task ResetPasswordwithFirebaseAuth(string old_password, string new_password) { try { ////Get the current logged in user's details var currentUser = FirebaseAuth.Instance.CurrentUser; ////Get current user credentials to reauthenticate the user AuthCredential credential = EmailAuthProvider.GetCredential(currentUser.Email, old_password); ////Reauthenticate the user with credentials var result = await currentUser.ReauthenticateAndRetrieveDataAsync(credential); ////If authentication succeeded then update the password if (result != null) { await currentUser.UpdatePasswordAsync(new_password); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Attaches the given email credentials to the user. This allows the user to sign in to this account in the future with credentials for such provider. /// </summary> /// <param name="email">The user’s email address.</param> /// <param name="password">The user’s password.</param> /// <returns>Updated current account</returns> public IObservable <IFirebaseAuthResult> LinkWithEmail(string email, string password) { AuthCredential credential = EmailAuthProvider.GetCredential(email, password); return(LinkWithCredentialAsync(credential).ToObservable()); }
public IAuthCredential GetCredentialWithLink(string email, string emailLink) { var credential = EmailAuthProvider.GetCredentialWithLink(email, emailLink); return(new AuthCredentialWrapper(credential)); }
public IAuthCredential GetCredential(string email, string password) { var credential = EmailAuthProvider.GetCredential(email, password); return(new AuthCredentialWrapper(credential)); }
public Task <FirebaseUser> SignInUserWithEmail(string email, string password) { return(SignInWithCredentials(EmailAuthProvider.GetCredential(email, password))); }
/// <summary> /// Attaches the given email credentials to the user. This allows the user to sign in to this account in the future with credentials for such provider. /// </summary> /// <param name="email">The user’s email address.</param> /// <param name="password">The user’s password.</param> /// <returns>Task of IUserWrapper</returns> public async Task <IFirebaseAuthResult> LinkWithEmailAsync(string email, string password) { AuthCredential credential = EmailAuthProvider.GetCredential(email, password); return(await LinkWithCredentialAsync(credential)); }