Ejemplo n.º 1
0
        public async Task RolloutUserFromEnterprise_ValidResponse_ValidUser()
        {
            /*** Arrange ***/
            var         responseString = "{\"type\":\"user\",\"id\":\"181216415\",\"name\":\"sean\",\"login\":\"[email protected]\",\"created_at\":\"2012-05-03T21:39:11-07:00\",\"modified_at\":\"2012-12-06T18:17:16-08:00\",\"role\":\"admin\",\"language\":\"en\",\"space_amount\":5368709120,\"space_used\":1237179286,\"max_upload_size\":2147483648,\"tracking_codes\":[],\"can_see_managed_users\":true,\"is_sync_enabled\":true,\"status\":\"active\",\"job_title\":\"\",\"phone\":\"6509241374\",\"address\":\"\",\"avatar_url\":\"https://www.box.com/api/avatar/large/181216415\",\"is_exempt_from_device_limits\":false,\"is_exempt_from_login_verification\":false, \"notification_email\": { \"email\": \"[email protected]\", \"is_confirmed\": true}}";
            IBoxRequest boxRequest     = null;

            Handler.Setup(h => h.ExecuteAsync <BoxUser>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxUser> >(new BoxResponse <BoxUser>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);

            /*** Act ***/
            var userRequest = new BoxUserRollOutRequest()
            {
                Id = "181216415",
            };
            BoxUser user = await _usersManager.UpdateUserInformationAsync(userRequest);

            /*** Assert ***/

            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
            Assert.AreEqual(UserUri + "181216415", boxRequest.AbsoluteUri.AbsoluteUri);
            BoxUserRequest payload = JsonConvert.DeserializeObject <BoxUserRequest>(boxRequest.Payload);

            Assert.AreEqual(userRequest.Id, payload.Id);
            Assert.AreEqual(boxRequest.Payload, "{\"enterprise\":null,\"id\":\"181216415\"}");
        }
        public static async Task <BoxUser> CreateBoxUser(string email)
        {
            BoxUserRequest userRequest = new BoxUserRequest()
            {
                Name = email, IsPlatformAccessOnly = true
            };
            BoxUser appUser = await AdminClient().UsersManager.CreateEnterpriseUserAsync(userRequest);

            return(appUser);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used to edit the settings and information about a user. This method only works for enterprise admins. To roll a user out
        /// of the enterprise (and convert them to a standalone free user), update the special enterprise attribute to be null
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userRequest"></param>
        /// <returns></returns>
        public async Task <BoxUser> UpdateUserInformationAsync(BoxUserRequest userRequest, List <string> fields = null)
        {
            BoxRequest request = new BoxRequest(_config.UserEndpointUri, userRequest.Id)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(userRequest));

            IBoxResponse <BoxUser> response = await ToResponseAsync <BoxUser>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
Ejemplo n.º 4
0
        protected static Task <BoxUser> CreateNewUser(BoxClient client)
        {
            var userRequest = new BoxUserRequest
            {
                Name = "CI App User " + DateTime.Now.ToString("dd-MM-yyyy"), // mark with date
                IsPlatformAccessOnly = true                                  // creating application specific user, not a Box.com user
            };

            return(client.UsersManager.CreateEnterpriseUserAsync(userRequest));
        }
Ejemplo n.º 5
0
        private static Task <BoxUser> CreateNewUser(BoxClient client)
        {
            var userRequest = new BoxUserRequest
            {
                Name = "First user",
                IsPlatformAccessOnly = true // creating application specific user, not a Box.com user
            };

            return(client.UsersManager.CreateEnterpriseUserAsync(userRequest));
        }
Ejemplo n.º 6
0
        private static async Task MainAsync()
        {
            // rename the private_key.pem.example to private_key.pem and put your JWT private key in the file
            var privateKey = File.ReadAllText("private_key.pem.example");

            var boxConfig = new BoxConfigBuilder(_clientId, _clientSecret, _enterpriseId, privateKey, _jwtPrivateKeyPassword, _jwtPublicKeyId)
                            .Build();
            var boxJWT = new BoxJWTAuth(boxConfig);

            var adminToken = await boxJWT.AdminTokenAsync();

            Console.WriteLine("Admin Token: " + adminToken);
            Console.WriteLine();

            var adminClient = boxJWT.AdminClient(adminToken);

            Console.WriteLine("Admin root folder items");
            var items = await adminClient.FoldersManager.GetFolderItemsAsync("0", 500);

            items.Entries.ForEach(i =>
            {
                Console.WriteLine("\t{0}", i.Name);
                //if (i.Type == "file")
                //{
                //    var previewLink = adminClient.FilesManager.GetPreviewLinkAsync(i.Id).Result;
                //    Console.WriteLine("\tPreview Link: {0}", previewLink.ToString());
                //    Console.WriteLine();
                //}
            });
            Console.WriteLine();

            var userRequest = new BoxUserRequest()
            {
                Name = "test appuser", IsPlatformAccessOnly = true
            };
            var appUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            Console.WriteLine("Created App User");

            var userToken = await boxJWT.UserTokenAsync(appUser.Id);

            var userClient = boxJWT.UserClient(userToken, appUser.Id);

            var userDetails = await userClient.UsersManager.GetCurrentUserInformationAsync();

            Console.WriteLine("\nApp User Details:");
            Console.WriteLine("\tId: {0}", userDetails.Id);
            Console.WriteLine("\tName: {0}", userDetails.Name);
            Console.WriteLine("\tStatus: {0}", userDetails.Status);
            Console.WriteLine();

            await adminClient.UsersManager.DeleteEnterpriseUserAsync(appUser.Id, false, true);

            Console.WriteLine("Deleted App User");
        }
Ejemplo n.º 7
0
        private static Task <BoxUser> CreateNewUser(BoxClient client)
        {
            var userRequest = new BoxUserRequest
            {
                Name = "First user",
                IsPlatformAccessOnly = true, // creating application specific user, not a Box.com user
                // ExternalAppUserId = "yhu-au1" // Optional, set unique external app user id
            };

            return(client.UsersManager.CreateEnterpriseUserAsync(userRequest));
        }
Ejemplo n.º 8
0
        protected static Task <BoxUser> CreateNewUser(IBoxClient client)
        {
            var userRequest = new BoxUserRequest
            {
                Name = "IT App User - " + Guid.NewGuid().ToString(),
                IsPlatformAccessOnly = true
            };
            var user = client.UsersManager.CreateEnterpriseUserAsync(userRequest);

            UserCreated = true;
            return(user);
        }
Ejemplo n.º 9
0
        public static async Task PrepareBoxAppUser(ClaimsIdentity externalIdentity)
        {
            var auth0UserId = externalIdentity.Claims.FirstOrDefault(c => c.Type == "user_id").Value;
            var boxId       = GetBoxIdFromAuth0(auth0UserId);

            if (boxId == null)
            {
                //create a new app user in Box
                string email       = externalIdentity.Claims.FirstOrDefault(c => c.Type == "email").Value;
                var    userRequest = new BoxUserRequest()
                {
                    Name = email, IsPlatformAccessOnly = true
                };
                var appUser = await AdminClient().UsersManager.CreateEnterpriseUserAsync(userRequest);

                boxId = appUser.Id;

                //store the boxId in the user's Auth0 metadata
                var meta = new Dictionary <string, object>();
                meta.Add(BOX_USER_ID_KEY, boxId);
                AUTH0_CLIENT.UpdateUserMetadata(auth0UserId, meta);

                //now do the initial box account setup
                var boxClient     = UserClient((string)boxId);
                var folderRequest = new BoxFolderRequest()
                {
                    Name = "Test Folder", Parent = new BoxRequestEntity()
                    {
                        Id = "0"
                    }
                };
                var newFolder = await boxClient.FoldersManager.CreateAsync(folderRequest);

                var pathToFile = HttpContext.Current.Server.MapPath("~/Assets/");
                var fileName   = "test.txt";
                using (FileStream fs = File.Open(pathToFile + fileName, FileMode.Open))
                {
                    // Create request object with name and parent folder the file should be uploaded to
                    BoxFileRequest request = new BoxFileRequest()
                    {
                        Name   = fileName,
                        Parent = new BoxRequestEntity()
                        {
                            Id = "0"
                        }
                    };
                    var boxFile = await boxClient.FilesManager.UploadAsync(request, fs);
                }
            }

            HttpContext.Current.Session[BOX_USER_ID_KEY] = (string)boxId;
        }
Ejemplo n.º 10
0
        static async Task MainAsync()
        {
            var privateKey = File.ReadAllText("private_key.pem");

            var boxConfig = new BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID);
            var boxJWT    = new BoxJWTAuth(boxConfig);

            var adminToken = boxJWT.AdminToken();

            Console.WriteLine("Admin Token: " + adminToken);
            Console.WriteLine();

            var adminClient = boxJWT.AdminClient(adminToken);

            Console.WriteLine("Admin root folder items");
            var items = await adminClient.FoldersManager.GetFolderItemsAsync("0", 500);

            items.Entries.ForEach(i =>
            {
                Console.WriteLine("\t{0}", i.Name);
                //if (i.Type == "file")
                //{
                //    var preview_link = adminClient.FilesManager.GetPreviewLinkAsync(i.Id).Result;
                //    Console.WriteLine("\tPreview Link: {0}", preview_link.ToString());
                //    Console.WriteLine();
                //}
            });
            Console.WriteLine();

            var userRequest = new BoxUserRequest()
            {
                Name = "test appuser", IsPlatformAccessOnly = true
            };
            var appUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            Console.WriteLine("Created App User");

            var userToken  = boxJWT.UserToken(appUser.Id);
            var userClient = boxJWT.UserClient(userToken, appUser.Id);

            var userDetails = await userClient.UsersManager.GetCurrentUserInformationAsync();

            Console.WriteLine("\nApp User Details:");
            Console.WriteLine("\tId: {0}", userDetails.Id);
            Console.WriteLine("\tName: {0}", userDetails.Name);
            Console.WriteLine("\tStatus: {0}", userDetails.Status);
            Console.WriteLine();

            await adminClient.UsersManager.DeleteEnterpriseUserAsync(appUser.Id, false, true);

            Console.WriteLine("Deleted App User");
        }
        /// <summary>
        /// Used to edit the settings and information about a user. This method only works for enterprise admins. To roll a user out
        /// of the enterprise (and convert them to a standalone free user), update the special enterprise attribute to be null.
        /// </summary>
        /// <param name="userRequest">BoxUserRequest object.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <returns>Returns the user object for the updated user. Errors may be thrown when the fields are invalid or this API call is made from a non-admin account.</returns>
        public async Task <BoxUser> UpdateUserInformationAsync(BoxUserRequest userRequest, IEnumerable <string> fields = null)
        {
            userRequest.ThrowIfNull("userRequest")
            .Id.ThrowIfNullOrWhiteSpace("userRequest.Id");
            BoxRequest request = new BoxRequest(_config.UserEndpointUri, userRequest.Id)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(userRequest))
                                 .Method(RequestMethod.Put);

            IBoxResponse <BoxUser> response = await ToResponseAsync <BoxUser>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
        /// <summary>
        /// Used to provision a new user in an enterprise. This method only works for enterprise admins.
        /// </summary>
        /// <param name="userRequest">BoxUserRequest object.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <returns>Returns the user object for the newly created user.</returns>
        public async Task <BoxUser> CreateEnterpriseUserAsync(BoxUserRequest userRequest, IEnumerable <string> fields = null)
        {
            userRequest.ThrowIfNull("userRequest");
            userRequest.Name.ThrowIfNull("userRequest.Name");

            BoxRequest request = new BoxRequest(_config.UserEndpointUri, "")
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(userRequest))
                                 .Method(RequestMethod.Post);

            IBoxResponse <BoxUser> response = await ToResponseAsync <BoxUser>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
Ejemplo n.º 13
0
        private static async Task <BoxUser> CreateSearchUser(BoxClient saClient, TimeLimiter throttle)
        {
            // 検索ユーザーを作成
            var userParams = new BoxUserRequest()
            {
                Name = "ST_APP_USER_SEARCH",
                IsPlatformAccessOnly = true
            };

            await throttle;
            var   searchUser = await saClient.UsersManager.CreateEnterpriseUserAsync(userParams);

            return(searchUser);
        }
Ejemplo n.º 14
0
        private static async Task <BoxUser> CreateAppUserAsync(int number, BoxClient saClient, TimeLimiter throttle)
        {
            // Console.WriteLine("execute API to create appUser No.{0}", number);

            var userParams = new BoxUserRequest()
            {
                Name = "ST_APP_USER_" + number,
                IsPlatformAccessOnly = true
            };
            await throttle;
            var   newUser = await saClient.UsersManager.CreateEnterpriseUserAsync(userParams);

            return(newUser);
        }
Ejemplo n.º 15
0
        public async Task UpdateUserInformationAsync_ForNewExternalAppId_ShouldUpdateExistingUser()
        {
            var user = await CreateEnterpriseUser();

            var newName           = GetUniqueName("username");
            var updateUserRequest = new BoxUserRequest
            {
                Id   = user.Id,
                Name = newName
            };

            var updatedUser = await AdminClient.UsersManager.UpdateUserInformationAsync(updateUserRequest);

            Assert.AreEqual(updatedUser.Name, newName);
        }
Ejemplo n.º 16
0
        public async Task <string> Execute(IBoxClient client)
        {
            var userRequest = new BoxUserRequest
            {
                Name = _name,
                IsPlatformAccessOnly = true,
                ExternalAppUserId    = _externalAppUserId
            };

            BoxUser = await client.UsersManager.CreateEnterpriseUserAsync(userRequest);

            _id = BoxUser.Id;

            return(BoxUser.Id);
        }
Ejemplo n.º 17
0
        public async Task CreateEnterpriseUserAsync_ForCorrectUserRequest_ShouldCreateNewApplicationUser()
        {
            var name        = GetUniqueName("user");
            var userRequest = new BoxUserRequest
            {
                Name = name,
                IsPlatformAccessOnly = true,
                ExternalAppUserId    = GetUniqueName("user-id")
            };

            var newUser = await AdminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            Assert.AreEqual(newUser.Name, name);

            await AdminClient.UsersManager.DeleteEnterpriseUserAsync(newUser.Id, false, true);
        }
Ejemplo n.º 18
0
        public async Task DeleteEnterpriseUserAsync_ForExistingUser_ShouldDeleteThisUserFromBox()
        {
            var userRequest = new BoxUserRequest
            {
                Name = GetUniqueName("user"),
                IsPlatformAccessOnly = true,
                ExternalAppUserId    = GetUniqueName("user-id")
            };
            var newUser = await AdminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            await AdminClient.UsersManager.DeleteEnterpriseUserAsync(newUser.Id, false, true);

            var appUsers = await AdminClient.UsersManager.GetEnterpriseUsersAsync();

            Assert.IsFalse(appUsers.Entries.Any(item => item.Id == newUser.Id));
        }
Ejemplo n.º 19
0
        static async Task MainAsync()
        {
            string CLIENT_ID                = Configuration["Config:ClientID"];
            string CLIENT_SECRET            = Configuration["Config:ClientSecret"];
            string ENTERPRISE_ID            = Configuration["Config:EnterpriseID"];
            string JWT_PRIVATE_KEY_PATH     = Configuration["Config:PrivateKeyPath"];
            string JWT_PRIVATE_KEY_PASSWORD = Configuration["Config:PrivateKeyPass"];
            string JWT_PUBLIC_KEY_ID        = Configuration["Config:PublicKeyID"];

            var privateKey = File.ReadAllText(JWT_PRIVATE_KEY_PATH);

            var boxConfig = new BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID);
            var boxJWT    = new BoxJWTAuth(boxConfig);

            var adminToken = boxJWT.AdminToken();

            Console.WriteLine("Admin Token: " + adminToken);

            var adminClient = boxJWT.AdminClient(adminToken);

            var userRequest = new BoxUserRequest
            {
                Name = "John Smith",
                IsPlatformAccessOnly = true
            };
            var user = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            Console.Write("New app user created with Id = {0}", user.Id);

            /*BoxFile newFile;
             *
             * // Create request object with name and parent folder the file should be uploaded to
             * using (FileStream stream = new FileStream(@"/Users/jleblanc/localhost/box/net-jwt/tax.txt", FileMode.Open))
             * {
             *  BoxFileRequest req = new BoxFileRequest()
             *  {
             *      Name = "tax.txt",
             *      Parent = new BoxRequestEntity() { Id = "0" }
             *  };
             *  newFile = await adminClient.FilesManager.UploadAsync(req, stream);
             * }*/
        }
Ejemplo n.º 20
0
    static async Task validateUser(string name, string sub)
    {
        // Configure Box SDK instance
        var       reader = new StreamReader("config.json");
        var       json   = reader.ReadToEnd();
        var       config = BoxConfig.CreateFromJsonString(json);
        var       sdk    = new BoxJWTAuth(config);
        var       token  = sdk.AdminToken();
        BoxClient client = sdk.AdminClient(token);

        // Search for matching Box app user for Okta ID
        BoxCollection <BoxUser> users = await client.UsersManager.GetEnterpriseUsersAsync(externalAppUserId : sub);

        System.Diagnostics.Debug.WriteLine(users.TotalCount);

        if (users.TotalCount > 0)
        {
            // Box user found, get token
            var       userId     = users.Entries[0].Id;
            var       userToken  = sdk.UserToken(userId);
            BoxClient userClient = sdk.UserClient(userToken, userId);

            // Get current user
            BoxUser currentUser = await userClient.UsersManager.GetCurrentUserInformationAsync();

            System.Diagnostics.Debug.WriteLine("Current user name: " + currentUser.Name);
        }
        else
        {
            // No associated user found, create app user
            var userRequest = new BoxUserRequest()
            {
                Name = name,
                ExternalAppUserId    = sub,
                IsPlatformAccessOnly = true
            };
            var user = await client.UsersManager.CreateEnterpriseUserAsync(userRequest);

            System.Diagnostics.Debug.WriteLine("New user created: " + user.Name);
        }
    }
        public async Task ExternalAppUserId_LiveSession_ValidResponse()
        {
            // Works only on adminClient
            if (adminClient == null)
            {
                return;
            }

            // Create
            var userRequest = new BoxUserRequest
            {
                Name = "AppUser ExtId Test",
                IsPlatformAccessOnly = true, // creating application specific user, not a Box.com user
                ExternalAppUserId    = "yhu-au" + RandomString(3)
            };

            var newUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);

            // Update
            var updateUserRequest = new BoxUserRequest
            {
                Id = newUser.Id,
                ExternalAppUserId = "yhu-au" + RandomString(3)
            };

            var updatedUser = await adminClient.UsersManager.UpdateUserInformationAsync(updateUserRequest);

            Assert.AreEqual(newUser.Id, updatedUser.Id);

            // Get
            var appUsers = await adminClient.UsersManager.GetEnterpriseUsersAsync(null, 0, 100, null, null, updateUserRequest.ExternalAppUserId);

            Assert.AreEqual(appUsers.Entries.Count, 1);

            // Delete
            await adminClient.UsersManager.DeleteEnterpriseUserAsync(appUsers.Entries[0].Id, false, true);
        }
Ejemplo n.º 22
0
        public async Task CreateEnterpriseUser_ValidReponse()
        {
            /*** Arrange ***/
            string      responseString = "{\"type\": \"user\", \"id\": \"187273718\", \"name\": \"Ned Stark\",  \"login\": \"[email protected]\",  \"created_at\": \"2012-11-15T16:34:28-08:00\", \"modified_at\": \"2012-11-15T16:34:29-08:00\", \"role\": \"user\", \"language\": \"en\", \"space_amount\": 5368709120, \"space_used\": 0, \"max_upload_size\": 2147483648, \"tracking_codes\": [], \"can_see_managed_users\": true, \"is_sync_enabled\": true, \"status\": \"active\", \"job_title\": \"\", \"phone\": \"555-555-5555\", \"address\": \"555 Box Lane\", \"avatar_url\": \"https://www.box.com/api/avatar/large/187273718\", \"is_exempt_from_device_limits\": false,\"is_exempt_from_login_verification\": false }";
            IBoxRequest boxRequest     = null;

            Handler.Setup(h => h.ExecuteAsync <BoxUser>(It.IsAny <IBoxRequest>()))
            .Returns(() => Task.FromResult <IBoxResponse <BoxUser> >(new BoxResponse <BoxUser>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }))
            .Callback <IBoxRequest>(r => boxRequest = r);

            BoxUserRequest userRequest = new BoxUserRequest()
            {
                Login         = "******",
                Name          = "Ned Stark",
                Role          = "user",
                Language      = "en",
                IsSyncEnabled = true,
                Phone         = "555-555-5555",
                Address       = "555 Box Lane",
            };

            /*** Act ***/
            BoxUser result = await _usersManager.CreateEnterpriseUserAsync(userRequest);

            /*** Assert ***/

            // Request check
            Assert.IsNotNull(boxRequest);
            Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
            Assert.AreEqual(UserUri, boxRequest.AbsoluteUri.AbsoluteUri);
            Assert.IsNotNull(boxRequest.Payload);
            BoxUserRequest payload = JsonConvert.DeserializeObject <BoxUserRequest>(boxRequest.Payload);

            Assert.AreEqual(userRequest.Login, payload.Login);
            Assert.AreEqual(userRequest.Name, payload.Name);
            Assert.AreEqual(userRequest.IsSyncEnabled, payload.IsSyncEnabled);
            Assert.AreEqual(userRequest.Phone, payload.Phone);
            Assert.AreEqual(userRequest.Address, payload.Address);

            // Response check
            Assert.AreEqual("user", result.Type);
            Assert.AreEqual("187273718", result.Id);
            Assert.AreEqual("Ned Stark", result.Name);
            Assert.AreEqual("*****@*****.**", result.Login);
            Assert.AreEqual(DateTime.Parse("2012-11-15T16:34:28-08:00"), result.CreatedAt);
            Assert.AreEqual("user", result.Role);
            Assert.AreEqual("en", result.Language);
            Assert.AreEqual(5368709120, result.SpaceAmount);
            Assert.AreEqual(0, result.SpaceUsed);
            Assert.AreEqual(2147483648, result.MaxUploadSize);
            Assert.AreEqual(0, result.TrackingCodes.Count);
            Assert.AreEqual(true, result.CanSeeManagedUsers);
            Assert.AreEqual(true, result.IsSyncEnabled);
            Assert.AreEqual("active", result.Status);
            Assert.IsTrue(string.IsNullOrEmpty(result.JobTitle));
            Assert.AreEqual("555-555-5555", result.Phone);
            Assert.AreEqual("555 Box Lane", result.Address);
            Assert.AreEqual("https://www.box.com/api/avatar/large/187273718", result.AvatarUrl);
        }
Ejemplo n.º 23
0
        protected BoxUserRequest CreateUserRequest(string name      = "", string userId      = "", string role = "", bool removeFromEnterprise = false,
                                                   string language  = "", string jobTitle    = "", string phoneNumber = "", string address     = "", string spaceAmount = "", string status = "",
                                                   bool syncDisable = false, bool syncEnable = false, bool isExemptFromDeviceLimits = false, bool notExemptFromDeviceLimits = false,
                                                   bool isExemptFromLoginVerificaton = false, bool notExemptFromLoginVerification = false, bool isPasswordResetRequired = false, string login = "")
        {
            if (syncDisable && syncEnable)
            {
                throw new Exception("--sync-disable and --sync-enable cannot be passed in a single call");
            }
            if (isExemptFromDeviceLimits && notExemptFromDeviceLimits)
            {
                throw new Exception("--is-exempt-from-device-limits and --not-exempt-from-device-limits cannot be passed in a single call");
            }
            if (isExemptFromLoginVerificaton && notExemptFromLoginVerification)
            {
                throw new Exception("--is-exempt-login-verification and --not-exempt-login-verification cannot be passed in a single call");
            }

            BoxUserRequest userRequest = new BoxUserRequest();

            if (!string.IsNullOrEmpty(login))
            {
                userRequest.Login = login;
            }
            if (!string.IsNullOrEmpty(userId))
            {
                userRequest.Id = userId;
            }
            if (removeFromEnterprise)
            {
                userRequest.Enterprise = "null";
            }
            if (!string.IsNullOrEmpty(name))
            {
                userRequest.Name = name;
            }
            if (!string.IsNullOrEmpty(role))
            {
                if (!(role == "user" || role == "coadmin"))
                {
                    throw new Exception("Role must be coadmin or user.");
                }
                userRequest.Role = role;
            }
            if (!string.IsNullOrEmpty(language))
            {
                userRequest.Language = language;
            }
            if (syncEnable)
            {
                userRequest.IsSyncEnabled = true;
            }
            if (syncDisable)
            {
                userRequest.IsSyncEnabled = false;
            }
            if (!string.IsNullOrEmpty(jobTitle))
            {
                userRequest.JobTitle = jobTitle;
            }
            if (!string.IsNullOrEmpty(phoneNumber))
            {
                userRequest.Phone = phoneNumber;
            }
            if (!string.IsNullOrEmpty(address))
            {
                userRequest.Address = address;
            }
            if (!string.IsNullOrEmpty(spaceAmount))
            {
                userRequest.SpaceAmount = double.Parse(spaceAmount);
            }
            if (!string.IsNullOrEmpty(status))
            {
                userRequest.Status = status;
            }
            if (isExemptFromDeviceLimits)
            {
                userRequest.IsExemptFromDeviceLimits = true;
            }
            if (notExemptFromDeviceLimits)
            {
                userRequest.IsExemptFromDeviceLimits = false;
            }
            if (isExemptFromLoginVerificaton)
            {
                userRequest.IsExemptFromLoginVerification = true;
            }
            if (notExemptFromLoginVerification)
            {
                userRequest.IsExemptFromLoginVerification = false;
            }
            if (isPasswordResetRequired)
            {
                userRequest.IsPasswordResetRequired = true;
            }

            return(userRequest);
        }