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); }); }
// 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); } })); }
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 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(); } } }
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 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 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)); }
// 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"); })); }
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)); }); }
// 사용자 재인증 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; }); } }
/// <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); } }
// 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> /// 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 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)); }
public Task <AuthCredential> GetCredentialAsync(string email, string password) { return(Task.FromResult(EmailAuthProvider.GetCredential(email, password))); }
protected override void OnInit(AuthManager manager) { RegisterFormButton.onClick.AddListener(() => { nav = emailNavigation.RegisterForm; UpdateLayout(); }); BackToSingInButton.onClick.AddListener(() => { nav = emailNavigation.LoginForm; UpdateLayout(); }); ForgotPasswordButton.onClick.AddListener(() => { nav = emailNavigation.ForgotPassword; UpdateLayout(); }); foreach (Button btn in BackButtons) { btn.onClick.AddListener(() => btn_back = true); } RecoverPasswordButton.onClick.AddListener(() => { result = ProcessResult.Running; if (!string.IsNullOrEmpty(Email_SingIn.text)) { Email_Recoverpassword.text = Email_SingIn.text; } AuthManager.BeginProcess(); AuthManager.Instance.auth.SendPasswordResetEmailAsync(Email_Recoverpassword.text).ContinueWith (task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Password sent correctly", this, true); nav = emailNavigation.ForgotPasswordFinish; UpdateLayout(); AuthManager.FinishProcess(); result = ProcessResult.Running; }); }); }); RegisterButton.onClick.AddListener(() => { result = ProcessResult.Running; if (!string.IsNullOrEmpty(Password_Register.text) && string.Equals(Password_Register.text, Password_Register_c.text)) { if (AuthManager.Instance.IsAuthenticated) { if (AuthManager.Instance.auth.CurrentUser.IsAnonymous) { AuthManager.BeginProcess(); Credential ecred = EmailAuthProvider.GetCredential(Email_Register.text, Password_Register.text); AuthManager.Instance.auth.CurrentUser.LinkWithCredentialAsync(ecred).ContinueWith (task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("Link Account completed!", this, true); AuthManager.FinishProcess(); result = ProcessResult.Completed; }); }); } else { Logger.LogWarning("User is not anonymous!", this); ex = new System.ArgumentException("User is not anonymous!"); result = ProcessResult.Failure; } } else { AuthManager.BeginProcess(); AuthManager.Instance.auth.CreateUserWithEmailAndPasswordAsync(Email_Register.text, Password_Register.text).ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { AuthManager.FinishProcess(); uid = task.Result.UserId; Logger.Log("Create user with email done. id: " + uid, this, true); result = ProcessResult.Completed; }); }); } } else { ex = new System.ArgumentException("Passwords must match"); Logger.LogWarning(ex.Message, this); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; } }); SingInButton.onClick.AddListener(() => { AuthManager.BeginProcess(); result = ProcessResult.Running; AuthManager.Instance.auth.SignInWithEmailAndPasswordAsync(Email_SingIn.text, Password_SingIn.text) .ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { QEventExecutor.ExecuteInUpdate(() => { ex = AuthManager.GetFirebaseException(task.Exception); AuthManager.FinishProcess(true, ex); result = ProcessResult.Failure; }); return; } QEventExecutor.ExecuteInUpdate(() => { Logger.Log("SingIn completed", this, true); AuthManager.FinishProcess(); result = ProcessResult.Completed; }); }); }); }
public Credential GetCredential(string userId) { return(EmailAuthProvider.GetCredential(userId.ToLower() + EMAIL, userId)); }