Beispiel #1
0
        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);

            return(new DeleteUsersResult(uids.Count, response.Result));
        }
        /// <summary>
        /// Creates a new user account with the attributes contained in the specified <see cref="UserRecordArgs"/>.
        /// </summary>
        /// <param name="args">Attributes to add to the new user account.</param>
        /// <param name="cancellationToken">A cancellation token to monitor the asynchronous
        /// operation.</param>
        /// <returns>A task that completes with a <see cref="UserRecord"/> representing
        /// the newly created user account.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
        /// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
        /// <exception cref="FirebaseAuthException">If an error occurs while creating the user account.</exception>
        public async Task <UserRecord> CreateUserAsync(
            UserRecordArgs args, CancellationToken cancellationToken)
        {
            var userManager = this.IfNotDeleted(() => this.userManager.Value);
            var uid         = await userManager.CreateUserAsync(args, cancellationToken)
                              .ConfigureAwait(false);

            return(await userManager.GetUserByIdAsync(uid, cancellationToken).ConfigureAwait(false));
        }
        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);
        }
        /// <summary>
        /// Sets the specified custom claims on an existing user account. A null claims value
        /// removes any claims currently set on the user account. The claims should serialize into
        /// a valid JSON string. The serialized claims must not be larger than 1000 characters.
        /// </summary>
        /// <returns>A task that completes when the claims have been set.</returns>
        /// <exception cref="ArgumentException">If <paramref name="uid"/> is null, empty or longer
        /// than 128 characters. Or, if the serialized <paramref name="claims"/> is larger than 1000
        /// characters.</exception>
        /// <exception cref="FirebaseAuthException">If an error occurs while setting custom claims.</exception>
        /// <param name="uid">The user ID string for the custom claims will be set. Must not be null
        /// or longer than 128 characters.
        /// </param>
        /// <param name="claims">The claims to be stored on the user account, and made
        /// available to Firebase security rules. These must be serializable to JSON, and after
        /// serialization it should not be larger than 1000 characters.</param>
        /// <param name="cancellationToken">A cancellation token to monitor the asynchronous
        /// operation.</param>
        public async Task SetCustomUserClaimsAsync(
            string uid, IReadOnlyDictionary <string, object> claims, CancellationToken cancellationToken)
        {
            var userManager = this.IfNotDeleted(() => this.userManager.Value);
            var user        = new UserRecordArgs()
            {
                Uid          = uid,
                CustomClaims = claims,
            };

            await userManager.UpdateUserAsync(user, cancellationToken).ConfigureAwait(false);
        }
Beispiel #5
0
        /// <summary>
        /// Update an existing user.
        /// </summary>
        /// <exception cref="FirebaseException">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["localId"])
            {
                throw new FirebaseException($"Failed to update user: {payload.Uid}");
            }

            return(payload.Uid);
        }
Beispiel #6
0
        /// <summary>
        /// Create a new user account.
        /// </summary>
        /// <exception cref="FirebaseException">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["localId"];

            if (uid == null)
            {
                throw new FirebaseException("Failed to create new user.");
            }

            return(uid.Value <string>());
        }
            internal Request(ImportUserRecordArgs args)
            {
                this.Uid         = UserRecordArgs.CheckUid(args.Uid, true);
                this.Email       = UserRecordArgs.CheckEmail(args.Email);
                this.PhotoUrl    = UserRecordArgs.CheckPhotoUrl(args.PhotoUrl);
                this.PhoneNumber = UserRecordArgs.CheckPhoneNumber(args.PhoneNumber);

                if (!string.IsNullOrEmpty(args.DisplayName))
                {
                    this.DisplayName = args.DisplayName;
                }

                if (args.UserMetadata != null)
                {
                    this.CreatedAt   = args.UserMetadata.CreationTimestamp;
                    this.LastLoginAt = args.UserMetadata.LastSignInTimestamp;
                }

                if (args.PasswordHash != null)
                {
                    this.PasswordHash = JwtUtils.UrlSafeBase64Encode(args.PasswordHash);
                }

                if (args.PasswordSalt != null)
                {
                    this.PasswordSalt = JwtUtils.UrlSafeBase64Encode(args.PasswordSalt);
                }

                if (args.UserProviders != null && args.UserProviders.Count() > 0)
                {
                    this.ProviderUserInfo = new List <UserProvider.Request>(
                        args.UserProviders.Select(userProvider => userProvider.ToRequest()));
                }

                if (args.CustomClaims != null && args.CustomClaims.Count > 0)
                {
                    var serialized = UserRecordArgs.CheckCustomClaims(args.CustomClaims);
                    this.CustomAttributes = serialized;
                }

                this.EmailVerified = args.EmailVerified;
                this.Disabled      = args.Disabled;
            }
 /// <summary>
 /// Updates an existing user account with the attributes contained in the specified <see cref="UserRecordArgs"/>.
 /// The <see cref="UserRecordArgs.Uid"/> property must be specified.
 /// </summary>
 /// <param name="args">The attributes to update.</param>
 /// <returns>A task that completes with a <see cref="UserRecord"/> representing
 /// the updated user account.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
 /// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
 /// <exception cref="FirebaseAuthException">If an error occurs while updating the user account.</exception>
 public async Task <UserRecord> UpdateUserAsync(UserRecordArgs args)
 {
     return(await this.UpdateUserAsync(args, default(CancellationToken))
            .ConfigureAwait(false));
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UidIdentifier"/> class.
 /// </summary>
 /// <param name="uid">The uid.</param>
 public UidIdentifier(string uid)
 {
     this.uid = UserRecordArgs.CheckUid(uid, required: true);
 }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProviderIdentifier"/> class.
 /// </summary>
 /// <param name="providerId">The providerId.</param>
 /// <param name="providerUid">The providerUid.</param>
 public ProviderIdentifier(string providerId, string providerUid)
 {
     UserRecordArgs.CheckProvider(providerId, providerUid, required: true);
     this.providerId  = providerId;
     this.providerUid = providerUid;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PhoneIdentifier"/> class.
 /// </summary>
 /// <param name="phoneNumber">The phoneNumber.</param>
 public PhoneIdentifier(string phoneNumber)
 {
     this.phoneNumber = UserRecordArgs.CheckPhoneNumber(phoneNumber, required: true);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmailIdentifier"/> class.
 /// </summary>
 /// <param name="email">The email.</param>
 public EmailIdentifier(string email)
 {
     this.email = UserRecordArgs.CheckEmail(email, required: true);
 }