public async Task ImportUsers()
        {
            var randomUser = TemporaryUserBuilder.RandomUserRecordArgs();
            var args       = new ImportUserRecordArgs()
            {
                Uid           = randomUser.Uid,
                Email         = randomUser.Email,
                DisplayName   = "Random User",
                PhotoUrl      = "https://example.com/photo.png",
                EmailVerified = true,
            };
            var usersLst = new List <ImportUserRecordArgs>()
            {
                args
            };

            var resp = await this.Auth.ImportUsersAsync(usersLst);

            this.userBuilder.AddUid(randomUser.Uid);

            Assert.Equal(1, resp.SuccessCount);
            Assert.Equal(0, resp.FailureCount);

            var user = await this.Auth.GetUserAsync(randomUser.Uid);

            Assert.Equal(randomUser.Email, user.Email);
        }
Exemple #2
0
        private async Task <string> ImportUserWithProviderAsync()
        {
            var randomArgs = TemporaryUserBuilder.RandomUserRecordArgs();
            var importUser = new ImportUserRecordArgs()
            {
                Uid           = randomArgs.Uid,
                Email         = randomArgs.Email,
                PhoneNumber   = randomArgs.PhoneNumber,
                UserProviders = new List <UserProvider>()
                {
                    new UserProvider()
                    {
                        Uid        = $"google_{randomArgs.Uid}",
                        ProviderId = "google.com",
                    },
                },
            };

            var result = await FirebaseAuth.DefaultInstance.ImportUsersAsync(
                new List <ImportUserRecordArgs>()
            {
                importUser,
            });

            Assert.Equal(1, result.SuccessCount);
            this.userBuilder.AddUid(randomArgs.Uid);
            return(randomArgs.Uid);
        }
 public GetUsersFixture()
 {
     IntegrationTestUtils.EnsureDefaultApp();
     this.userBuilder   = new TemporaryUserBuilder(FirebaseAuth.DefaultInstance);
     this.TestUser1     = this.userBuilder.CreateRandomUserAsync().Result;
     this.TestUser2     = this.userBuilder.CreateRandomUserAsync().Result;
     this.TestUser3     = this.userBuilder.CreateRandomUserAsync().Result;
     this.ImportUserUid = this.ImportUserWithProviderAsync().Result;
 }
        public async Task CreateUserWithParams()
        {
            var args = TemporaryUserBuilder.RandomUserRecordArgs();

            args.EmailVerified = true;
            var user = await this.userBuilder.CreateUserAsync(args);

            Assert.Equal(args.Uid, user.Uid);
            Assert.Equal(args.Email, user.Email);
            Assert.Equal(args.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.
            var exception = await Assert.ThrowsAsync <FirebaseAuthException>(
                () => this.Auth.CreateUserAsync(args));

            Assert.Equal(AuthErrorCode.UidAlreadyExists, exception.AuthErrorCode);
        }
        public async Task UpdateUser()
        {
            var original = await this.userBuilder.CreateUserAsync(new UserRecordArgs());

            var updateArgs = TemporaryUserBuilder.RandomUserRecordArgs();

            updateArgs.Uid           = original.Uid;
            updateArgs.EmailVerified = true;

            var user = await this.Auth.UpdateUserAsync(updateArgs);

            Assert.Equal(updateArgs.Uid, user.Uid);
            Assert.Equal(updateArgs.Email, user.Email);
            Assert.Equal(updateArgs.PhoneNumber, user.PhoneNumber);
            Assert.Equal("Random User", user.DisplayName);
            Assert.Equal("https://example.com/photo.png", user.PhotoUrl);
            Assert.True(user.EmailVerified);
            Assert.False(user.Disabled);
            Assert.NotNull(user.UserMetaData.CreationTimestamp);
            Assert.Null(user.UserMetaData.LastSignInTimestamp);
            Assert.Equal(2, user.ProviderData.Length);
            Assert.Empty(user.CustomClaims);
        }
        public async Task ImportUsersWithPassword()
        {
            var randomUser = TemporaryUserBuilder.RandomUserRecordArgs();
            var args       = new ImportUserRecordArgs()
            {
                Uid           = randomUser.Uid,
                Email         = randomUser.Email,
                DisplayName   = "Random User",
                PhotoUrl      = "https://example.com/photo.png",
                EmailVerified = true,
                PasswordSalt  = Encoding.ASCII.GetBytes("NaCl"),
                PasswordHash  = Convert.FromBase64String("V358E8LdWJXAO7muq0CufVpEOXaj8aFiC7"
                                                         + "T/rcaGieN04q/ZPJ08WhJEHGjj9lz/2TT+/86N5VjVoc5DdBhBiw=="),
                CustomClaims = new Dictionary <string, object>()
                {
                    { "admin", true },
                },
                UserProviders = new List <UserProvider>
                {
                    new UserProvider()
                    {
                        Uid         = randomUser.Uid,
                        Email       = randomUser.Email,
                        DisplayName = "John Doe",
                        PhotoUrl    = "http://example.com/123/photo.png",
                        ProviderId  = "google.com",
                    },
                    new UserProvider()
                    {
                        Uid         = "fb.uid",
                        Email       = "*****@*****.**",
                        DisplayName = "John Doe",
                        PhotoUrl    = "http://example.com/123/photo.png",
                        ProviderId  = "facebook.com",
                    },
                },
            };

            var options = new UserImportOptions()
            {
                Hash = new Scrypt()
                {
                    Key = Convert.FromBase64String("jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC"
                                                   + "8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA=="),
                    SaltSeparator = Convert.FromBase64String("Bw=="),
                    Rounds        = 8,
                    MemoryCost    = 14,
                },
            };
            var usersLst = new List <ImportUserRecordArgs>()
            {
                args
            };

            var resp = await this.Auth.ImportUsersAsync(usersLst, options);

            this.userBuilder.AddUid(randomUser.Uid);

            Assert.Equal(1, resp.SuccessCount);
            Assert.Equal(0, resp.FailureCount);

            var user = await this.Auth.GetUserAsync(randomUser.Uid);

            Assert.Equal(randomUser.Email, user.Email);
            var idToken = await AuthIntegrationUtils.SignInWithPasswordAsync(
                randomUser.Email, "password", this.fixture.TenantId);

            Assert.False(string.IsNullOrEmpty(idToken));
        }
 public AbstractFirebaseAuthTest(AbstractAuthFixture <T> fixture)
 {
     this.fixture     = fixture;
     this.userBuilder = fixture.UserBuilder;
     this.Auth        = fixture.Auth;
 }