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);
            }
        }
Exemplo n.º 2
0
        public async Task ImportUsers()
        {
            var randomUser = RandomUser.Create();
            var args       = new ImportUserRecordArgs()
            {
                Uid           = randomUser.Uid,
                Email         = randomUser.Email,
                DisplayName   = "Random User",
                PhotoUrl      = "https://example.com/photo.png",
                EmailVerified = true,
            };

            IEnumerable <ImportUserRecordArgs> usersLst = new List <ImportUserRecordArgs>();

            usersLst = usersLst.Append(args);

            var resp = await FirebaseAuth.DefaultInstance.ImportUsersAsync(usersLst);

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

                var user = await FirebaseAuth.DefaultInstance.GetUserAsync(randomUser.Uid);

                Assert.Equal(randomUser.Email, user.Email);
            }
            finally
            {
                await FirebaseAuth.DefaultInstance.DeleteUserAsync(randomUser.Uid);
            }
        }
        private static async Task <UserRecord> CreateUserForActionLinksAsync()
        {
            var randomUser = RandomUser.Create();

            return(await FirebaseAuth.DefaultInstance.CreateUserAsync(new UserRecordArgs()
            {
                Uid = randomUser.Uid,
                Email = randomUser.Email,
                EmailVerified = false,
                Password = "******",
            }));
        }
Exemplo n.º 4
0
        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));
        }
        public async Task UserLifecycle()
        {
            // Create user
            var user = await FirebaseAuth.DefaultInstance.CreateUserAsync(new UserRecordArgs());

            var uid = user.Uid;

            try
            {
                Assert.Null(user.Email);
                Assert.Null(user.PhoneNumber);
                Assert.Null(user.DisplayName);
                Assert.Null(user.PhotoUrl);
                Assert.False(user.EmailVerified);
                Assert.False(user.Disabled);
                Assert.NotNull(user.UserMetaData.CreationTimestamp);
                Assert.Null(user.UserMetaData.LastSignInTimestamp);
                Assert.Empty(user.ProviderData);
                Assert.Empty(user.CustomClaims);

                // Get user by ID
                user = await FirebaseAuth.DefaultInstance.GetUserAsync(uid);

                Assert.Equal(uid, user.Uid);
                Assert.Null(user.Email);
                Assert.Null(user.PhoneNumber);
                Assert.Null(user.DisplayName);
                Assert.Null(user.PhotoUrl);
                Assert.False(user.EmailVerified);
                Assert.False(user.Disabled);
                Assert.NotNull(user.UserMetaData.CreationTimestamp);
                Assert.Null(user.UserMetaData.LastSignInTimestamp);
                Assert.Empty(user.ProviderData);
                Assert.Empty(user.CustomClaims);

                // Update user
                var randomUser = RandomUser.Create();
                var updateArgs = new UserRecordArgs()
                {
                    Uid           = uid,
                    DisplayName   = "Updated Name",
                    Email         = randomUser.Email,
                    PhoneNumber   = randomUser.PhoneNumber,
                    PhotoUrl      = "https://example.com/photo.png",
                    EmailVerified = true,
                    Password      = "******",
                };
                user = await FirebaseAuth.DefaultInstance.UpdateUserAsync(updateArgs);

                Assert.Equal(uid, user.Uid);
                Assert.Equal(randomUser.Email, user.Email);
                Assert.Equal(randomUser.PhoneNumber, user.PhoneNumber);
                Assert.Equal("Updated Name", 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);

                // Get user by email
                user = await FirebaseAuth.DefaultInstance.GetUserByEmailAsync(randomUser.Email);

                Assert.Equal(uid, user.Uid);

                // Disable user and remove properties
                var disableArgs = new UserRecordArgs()
                {
                    Uid         = uid,
                    Disabled    = true,
                    DisplayName = null,
                    PhoneNumber = null,
                    PhotoUrl    = null,
                };
                user = await FirebaseAuth.DefaultInstance.UpdateUserAsync(disableArgs);

                Assert.Equal(uid, user.Uid);
                Assert.Equal(randomUser.Email, user.Email);
                Assert.Null(user.PhoneNumber);
                Assert.Null(user.DisplayName);
                Assert.Null(user.PhotoUrl);
                Assert.True(user.EmailVerified);
                Assert.True(user.Disabled);
                Assert.NotNull(user.UserMetaData.CreationTimestamp);
                Assert.Null(user.UserMetaData.LastSignInTimestamp);
                Assert.Single(user.ProviderData);
                Assert.Empty(user.CustomClaims);
            }
            finally
            {
                // Delete user
                await FirebaseAuth.DefaultInstance.DeleteUserAsync(uid);

                var exception = await Assert.ThrowsAsync <FirebaseAuthException>(
                    async() => await FirebaseAuth.DefaultInstance.GetUserAsync(uid));

                Assert.Equal(AuthErrorCode.UserNotFound, exception.AuthErrorCode);
            }
        }
Exemplo n.º 6
0
        public async Task ImportUsersWithPassword()
        {
            var randomUser = RandomUser.Create();
            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,
                },
            };
            IEnumerable <ImportUserRecordArgs> usersLst = new List <ImportUserRecordArgs>();

            usersLst = usersLst.Append(args);
            var resp = await FirebaseAuth.DefaultInstance.ImportUsersAsync(usersLst, options);

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

                var user = await FirebaseAuth.DefaultInstance.GetUserAsync(randomUser.Uid);

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

                Assert.False(string.IsNullOrEmpty(idToken));
            }
            finally
            {
                await FirebaseAuth.DefaultInstance.DeleteUserAsync(randomUser.Uid);
            }
        }