internal async Task <DeleteUsersResult> DeleteUsersAsync( IReadOnlyList <string> uids, CancellationToken cancellationToken = default(CancellationToken)) { if (uids.Count > MaxDeleteAccountsBatchSize) { throw new ArgumentException( "`uids` parameter must have <= " + MaxDeleteAccountsBatchSize + " entries."); } foreach (string uid in uids) { UserRecordArgs.CheckUid(uid, required: true); } var payload = new Dictionary <string, object>() { { "localIds", uids }, { "force", true }, }; var response = await this.PostAndDeserializeAsync <BatchDeleteResponse>( "accounts:batchDelete", payload, cancellationToken).ConfigureAwait(false); var errors = response.Result.Errors? .Select((error) => new ErrorInfo(error.Index, error.Message)) .ToList(); return(new DeleteUsersResult(uids.Count, errors)); }
private async void Register_Execute(System.Windows.Window window) { RegisterWindow registerWindow = window as RegisterWindow; string password = registerWindow.PassPB.Password; try { UserRecordArgs args = new UserRecordArgs() { DisplayName = Name, Email = Email, Password = password, PhoneNumber = Number, }; User = await _model.RegisterUser(args); window.Close(); } catch (Exception e) { MessageBox.Show(e.Message); User = null; } }
public async Task DisableUser() { var original = await this.userBuilder.CreateRandomUserAsync(); var disableArgs = new UserRecordArgs { Uid = original.Uid, Disabled = true, DisplayName = null, PhoneNumber = null, PhotoUrl = null, }; var user = await this.Auth.UpdateUserAsync(disableArgs); Assert.Equal(original.Uid, user.Uid); Assert.Equal(original.Email, user.Email); Assert.Null(user.PhoneNumber); Assert.Null(user.DisplayName); Assert.Null(user.PhotoUrl); Assert.False(user.EmailVerified); Assert.True(user.Disabled); Assert.NotNull(user.UserMetaData.CreationTimestamp); Assert.Null(user.UserMetaData.LastSignInTimestamp); Assert.Single(user.ProviderData); Assert.Empty(user.CustomClaims); }
public async Task <string> UpdateUser(User user) { try { UserRecordArgs userRecordArgs = new UserRecordArgs(); if (!string.IsNullOrEmpty(user.Password)) { userRecordArgs.Uid = user.Id; userRecordArgs.Email = user.Email; userRecordArgs.Password = user.Password; userRecordArgs.DisplayName = user.FirstName + " " + user.LastName; } else { userRecordArgs.Uid = user.Id; userRecordArgs.Email = user.Email; userRecordArgs.DisplayName = user.FirstName + " " + user.LastName; }; var userRecord = await FirebaseAuth.DefaultInstance.UpdateUserAsync(userRecordArgs); if (!string.IsNullOrEmpty(userRecord.Uid)) { return("Användare uppdaterad"); } else { return("Något gick fel. Uppdatering misslyckades"); } } catch (FirebaseAuthException) { return("Något gick fel. Uppdatering misslyckades"); } }
public async Task Add(CityHall cityHall) { if (!ExecuteValidation(new CityHallValidation(), cityHall)) { return; } bool userExists = await _userService.FirebaseUserExistsByEmail(cityHall.Email); if (userExists) { Notify("Endereço de e-mail já cadastrado no sistema."); return; } await _repository.Add(cityHall); CityHall newCityHall = await _repository.GetById(cityHall.Id); if (newCityHall != null) { UserRecordArgs args = new UserRecordArgs() { DisplayName = newCityHall.Name, Email = newCityHall.Email, Password = newCityHall.CNPJ }; UserRecord fbUser = await _firebaseAuth.CreateUserAsync(args); if (fbUser != null) { User newUser = new User() { FirebaseUserId = fbUser.Uid, Email = fbUser.Email, CreationDate = DateTime.Now, FirstName = fbUser.DisplayName, CityHallId = newCityHall.Id }; await _userService.Add(newUser); // await _relationHandler.UpdateRelationAsync(newUser.Id, newCityHall.Id, true); var claims = new Dictionary <string, object>() { { "app_user_id", newUser.Id }, { "user", true }, { "city_hall", true } }; await _roleService.UpdateUserRole("user", newUser.Id, true); await _roleService.UpdateUserRole("city_hall", newUser.Id, true); await _roleService.UpdateUserClaims(newUser.Id, claims); } } }
private async Task CreateUserMethod() { try { UserRecordArgs args = new UserRecordArgs() { Email = Email, EmailVerified = false, PhoneNumber = $"+{PhoneNumber}", Password = Password, DisplayName = FullName, Disabled = false, Uid = Guid.NewGuid().ToString() }; UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); StandardMessagesDisplay.UserAdded(); Uid = args.Uid; StandardMessagesDisplay.InputToast("User added"); } catch (Exception ex) { Crashes.TrackError(ex); StandardMessagesDisplay.InputToast(ex.Message); } }
public async Task<IActionResult> SignUp([FromBody] SignUpRequest request) { try { UserRecordArgs args = new UserRecordArgs() { Email = request.Email, EmailVerified = true, Password = request.Password, DisplayName = request.UserName, Disabled = false, }; var claims = new Dictionary<string, object>() { { "student", true } }; Log.Information("Sign up(1/2): Created a new student-role Firebase user."); UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(userRecord.Uid, claims); BaseResponse<int> result = (BaseResponse<int>)await Mediator.Send(new RegisterStudentCommand { UserName = request.UserName, Email = request.Email }); Log.Information("Sign up(2/2): completed."); return Ok(new { Successful = true }); // IsCached = false } catch (Exception e) { Log.Error($"401 Error in Auth Controller: SignUp(). {e.Message}"); return StatusCode(401, new { Error = e.Message }); } }
public async Task CreateUserWithParams() { var randomUser = RandomUser.Create(); var args = new UserRecordArgs() { Uid = randomUser.Uid, Email = randomUser.Email, PhoneNumber = randomUser.PhoneNumber, DisplayName = "Random User", PhotoUrl = "https://example.com/photo.png", EmailVerified = true, Password = "******", }; var user = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); try { Assert.Equal(randomUser.Uid, user.Uid); Assert.Equal(randomUser.Email, user.Email); Assert.Equal(randomUser.PhoneNumber, user.PhoneNumber); Assert.Equal(args.DisplayName, user.DisplayName); Assert.Equal(args.PhotoUrl, user.PhotoUrl); Assert.True(user.EmailVerified); Assert.False(user.Disabled); // Cannot recreate the same user. await Assert.ThrowsAsync <FirebaseException>( async() => await FirebaseAuth.DefaultInstance.CreateUserAsync(args)); } finally { await FirebaseAuth.DefaultInstance.DeleteUserAsync(user.Uid); } }
public async Task <User> AddFirebaseUser(UserCreateDto user) { User newUser = null; if (await this.FirebaseUserExistsByEmail(user.Email)) { Notify($"O usuário {user.Email} já existe"); return(newUser); } if (!user.Roles.Any()) { Notify("Não é possível criar um usuário sem as definições de níveis de acesso"); return(newUser); } UserRecordArgs args = new UserRecordArgs() { Email = user.Email, EmailVerified = user.EmailVerified, PhoneNumber = user.PhoneNumber, Password = user.Password, DisplayName = user.DisplayName, PhotoUrl = user.PhotoUrl, Disabled = false, }; var fbUser = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); if (fbUser != null) { newUser = new User() { FirebaseUserId = fbUser.Uid, Email = fbUser.Email, CreationDate = DateTime.Now, FirstName = fbUser.DisplayName, ProfileUrl = fbUser.PhotoUrl, CityHallId = user.CityHallId }; await Add(newUser); var claims = new Dictionary <string, object>() { { "app_user_id", newUser.Id }, { "user", true }, { user.Roles[0], true } }; await _userRoleService.UpdateUserRole("user", newUser.Id, true); await _userRoleService.UpdateUserRole(user.Roles[0], newUser.Id, true); await _userRoleService.UpdateUserClaims(newUser.Id, claims); } return(newUser); }
public async Task UpdateUserNonExistingUid() { var args = new UserRecordArgs() { Uid = "non.existing", }; await Assert.ThrowsAsync <FirebaseException>( async() => await FirebaseAuth.DefaultInstance.UpdateUserAsync(args)); }
public async Task <bool> UpdateUserData(string firebaseUserId, string firstName, string lastName) { UserRecordArgs args = new UserRecordArgs() { Uid = firebaseUserId, DisplayName = $"{firstName} {lastName}" }; return(await _firebaseAuth.UpdateUserAsync(args) != null); }
internal async Task RevokeRefreshTokensAsync(string uid, CancellationToken cancellationToken) { var args = new UserRecordArgs() { Uid = uid, ValidSince = this.clock.UnixTimestamp(), }; await this.UpdateUserAsync(args, cancellationToken).ConfigureAwait(false); }
public async Task <bool> UpdateUserPhotoUrl(string firebaseUserId, string photoUrl) { var photo = photoUrl == "" ? null : photoUrl; UserRecordArgs args = new UserRecordArgs() { Uid = firebaseUserId, PhotoUrl = photo }; return(await _firebaseAuth.UpdateUserAsync(args) != null); }
public async Task UpdateUserNonExistingUid() { var args = new UserRecordArgs() { Uid = "non.existing", }; var exception = await Assert.ThrowsAsync <FirebaseAuthException>( async() => await FirebaseAuth.DefaultInstance.UpdateUserAsync(args)); Assert.Equal(AuthErrorCode.UserNotFound, exception.AuthErrorCode); }
public Task <UserRecord> CreateUserAsync(string email, string password) { var args = new UserRecordArgs() { Email = email, EmailVerified = false, Password = password, Disabled = false }; return(FirebaseAuth.DefaultInstance.CreateUserAsync(args)); }
public async Task <UserRecord> Register(UserRecordArgs userOrgs) { try { UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(userOrgs).ConfigureAwait(false); return(userRecord); } catch (Exception e) { throw e; } }
public async Task UpdateUser([FromBody] UserData userModifications) { Console.WriteLine(userModifications.Uid); var args = new UserRecordArgs() { Uid = userModifications.Uid, Email = userModifications.Email, DisplayName = userModifications.DisplayName, }; await FirebaseAuth.DefaultInstance.UpdateUserAsync(args); await FirebaseAdmin.Auth.FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(userModifications.Uid, userModifications.Claims.ToDictionary(x => x.Key, x => x.Value as object)); }
internal static async Task CreateUserWithUidAsync() { // [START create_user_with_uid] UserRecordArgs args = new UserRecordArgs() { Uid = "some-uid", Email = "*****@*****.**", PhoneNumber = "+11234567890", }; UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); // See the UserRecord reference doc for the contents of userRecord. Console.WriteLine($"Successfully created new user: {userRecord.Uid}"); // [END create_user_with_uid] }
public async Task CreateUser(Guid userId, string userName, string email) { UserRecordArgs args = new UserRecordArgs() { Email = email, EmailVerified = false, PhoneNumber = null, Password = Guid.NewGuid().ToString(), // Create a random password. Doesn't matter as we'll use a service account to manage users. DisplayName = userName, PhotoUrl = null, Disabled = false, Uid = userId.ToString(), }; UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); }
public async Task <UserRecord> CreateFirebaseAccount(string email, string password, IReadOnlyDictionary <string, object> claims) { UserRecordArgs newAccount = new UserRecordArgs() { Email = email, EmailVerified = false, Password = password, Disabled = false, }; UserRecord newAccountResult = await FirebaseAuth.DefaultInstance.CreateUserAsync(newAccount); await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(newAccountResult.Uid, claims); return(newAccountResult); }
/// <summary> /// Update an existing user. /// </summary> /// <exception cref="FirebaseAuthException">If the server responds that cannot update the /// user.</exception> /// <param name="args">The user account data to be updated.</param> /// <param name="cancellationToken">A cancellation token to monitor the asynchronous /// operation.</param> internal async Task <string> UpdateUserAsync( UserRecordArgs args, CancellationToken cancellationToken = default(CancellationToken)) { var payload = args.ToUpdateUserRequest(); var response = await this.PostAndDeserializeAsync <JObject>( "accounts:update", payload, cancellationToken).ConfigureAwait(false); if (payload.Uid != (string)response.Result["localId"]) { throw UnexpectedResponseException( $"Failed to update user: {payload.Uid}", resp: response.HttpResponse); } return(payload.Uid); }
public async Task <UserRecord> CreateUserAsync(UserRecordArgs args) { // Make sure we never create more than 1000 users in a single instance. // This allows us to delete all user accounts with a single call to DeleteUsers(). // Should not ever occur in practice. if (this.userIds.Count() >= 1000) { throw new InvalidOperationException("Maximum number of users reached."); } var user = await FirebaseAuth.DefaultInstance.CreateUserAsync(args); this.AddUid(user.Uid); return(user); }
public async Task <ActionResult <User> > PostUser(User user) { var phoneNumberUtil = PhoneNumberUtil.GetInstance(); string formattedPhoneNumber = phoneNumberUtil.Format(phoneNumberUtil.Parse(user.Phone, "VN"), PhoneNumberFormat.E164); bool existEmail = await _context.User.AnyAsync(x => x.Email == user.Email); bool existPhoneNumber = await _context.User.AnyAsync(x => x.Phone == formattedPhoneNumber); if (existEmail && existPhoneNumber) { return(Conflict(2)); } else if (existEmail) { return(Conflict(0)); } else if (existPhoneNumber) { return(Conflict(1)); } string avatarUrl = await blobService.UploadFile("avatars", DateTime.Now.Ticks + ".jpg", user.Avatar); UserRecordArgs userRecordArgs = new UserRecordArgs { DisplayName = user.Name, Email = user.Email, PhoneNumber = formattedPhoneNumber, Password = user.Password, PhotoUrl = avatarUrl, Disabled = false }; UserRecord cloudUser = await FirebaseAuth.DefaultInstance.CreateUserAsync(userRecordArgs); user.Role = Role.Customer; user.CreatedDate = DateTime.Now; user.Avatar = avatarUrl; _context.User.Add(user); await _context.SaveChangesAsync(); await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(cloudUser.Uid, new Dictionary <string, object> { { "gazeId", user.Id }, { ClaimTypes.Role, Role.Customer }, { ClaimTypes.Email, user.Email } }); return(CreatedAtAction(nameof(PostUser), new { id = user.Id }, user)); }
public async void UpdateUser(UserInfo user, EditUserBindingModel editUser) { if (editUser != null) { UserRecord userToUpdate = await FirebaseAuth.DefaultInstance .GetUserByEmailAsync(user.Email); UserRecordArgs newUserData = new UserRecordArgs() { DisplayName = editUser.Username, Password = editUser.Password }; await FirebaseAuth.DefaultInstance.UpdateUserAsync(newUserData); } }
public async Task <IActionResult> CreateUserAsync(UserRecordArgs userInfo) { try { UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(userInfo); var email = userRecord.Email; var link = await FirebaseAuth.DefaultInstance.GeneratePasswordResetLinkAsync(email); return(Ok(userRecord)); } catch (FirebaseException fireExc) { return(StatusCode(500, fireExc)); } }
private static async Task <UserRecord> NewUserWithParamsAsync() { // TODO(rsgowman): This function could be used throughout this file // (similar to the other ports). RandomUser randomUser = RandomUser.Create(); var args = new UserRecordArgs() { Uid = randomUser.Uid, Email = randomUser.Email, PhoneNumber = randomUser.PhoneNumber, DisplayName = "Random User", PhotoUrl = "https://example.com/photo.png", Password = "******", }; return(await FirebaseAuth.DefaultInstance.CreateUserAsync(args)); }
/// <summary> /// Create a new user account. /// </summary> /// <exception cref="FirebaseAuthException">If an error occurs while creating the user /// account.</exception> /// <param name="args">The data to create the user account with.</param> /// <param name="cancellationToken">A cancellation token to monitor the asynchronous /// operation.</param> /// <returns>The unique uid assigned to the newly created user account.</returns> internal async Task <string> CreateUserAsync( UserRecordArgs args, CancellationToken cancellationToken = default(CancellationToken)) { var payload = args.ThrowIfNull(nameof(args)).ToCreateUserRequest(); var response = await this.PostAndDeserializeAsync <JObject>( "accounts", payload, cancellationToken).ConfigureAwait(false); var uid = response.Result["localId"]; if (uid == null) { throw UnexpectedResponseException( "Failed to create new user.", resp: response.HttpResponse); } return(uid.Value <string>()); }
public async Task <IResult> CreateUser(User entity) { UserRecordArgs args = new UserRecordArgs() { Email = entity.Email, EmailVerified = false, Password = entity.Password, DisplayName = entity.FirstName + " " + entity.LastName, Disabled = false, }; UserRecord userRecord = await FirebaseAdmin.Auth.FirebaseAuth.DefaultInstance.CreateUserAsync(args); if (userRecord != null) { return(new SuccessResult()); } return(new ErrorResult()); }
public async Task <Users> UpdateUser(Users user) { UserRecordArgs args = new UserRecordArgs() { Uid = user.UserId, Email = user.Email, EmailVerified = false, PhoneNumber = user.PhoneNumber, Password = user.Password, DisplayName = user.DisplayName, PhotoUrl = user.PhotoUrl, Disabled = false, }; UserRecord userRecord = await FirebaseAuth.DefaultInstance.UpdateUserAsync(args).ConfigureAwait(false); user.UserId = userRecord.Uid; return(user); }
public async Task <FirebaseAdmin.Auth.UserRecord> crearUsuario(UserDTOs usuario) { //Crear un nuevo usuario para firebas --------> UserRecordArgs NewUser = new UserRecordArgs() { Email = usuario.Email, EmailVerified = false, PhoneNumber = usuario.Telefono, Password = usuario.Password, DisplayName = usuario.Nombre, PhotoUrl = "http://www.example.com/12345678/photo.png", Disabled = false, }; UserRecord userRecord = await FirebaseAuth.DefaultInstance.CreateUserAsync(NewUser); //Creo un nuevo usuario para mi database local ------> return(userRecord); }