public static Task CreateAsync(this IUserManager userManager, string username, string password, IEnumerable <UserRole> roles, Action <CreateUserOptions> configureOptions)
        {
            var options = new CreateUserOptions();

            configureOptions(options);

            return(userManager.CreateAsync(username, password, roles, options));
        }
        public async Task CreateAsync(string username, string password, IEnumerable <UserRole> roles, CreateUserOptions options)
        {
            var uri = GetUserManagementUri(options.AuthenticationDomain, username);

            Logger.LogInformation($"Attempting to create user with username {username} - {uri}");

            try
            {
                try
                {
                    // throw UserAlreadyExitsException if user already exists
                    await GetAsync(username, GetUserOptions.Default);

                    throw new UserAlreadyExistsException(username);
                }
                catch (UserNotFoundException)
                {
                    // expected
                }

                // create user
                var content = new FormUrlEncodedContent(GetUserFormValues(password, username, roles));
                var result  = await _client.PutAsync(uri, content, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
            }
            catch (UserAlreadyExistsException)
            {
                Logger.LogError($"Failed to create user with username {username} as it already exists");
                throw;
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Error trying to upsert user - {uri}");
                throw;
            }
        }