예제 #1
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);
 }
예제 #2
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);

            return response.ResponseObject;
        }
        /// <summary>
        /// Create a new Box Enterprise user.
        /// </summary>
        /// <returns></returns>
        public async Task<BoxUser> CreateEnterpriseUserAsync(BoxUserRequest userRequest, List<string> fields = null)
        {
            BoxRequest request = new BoxRequest(_config.UserEndpointUri, userRequest.Id)
                .Param(ParamFields, fields)
                .Payload(_converter.Serialize(userRequest))
                .Method(RequestMethod.Post);

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

            return response.ResponseObject;
        }
예제 #4
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="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, List<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;
        }
예제 #5
0
        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");

            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");
        }
예제 #6
0
        public async Task UpdateUser_ValidResponse_ValidUser()
        {
            /*** Arrange ***/
            string 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}";
            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 ***/
            BoxUserRequest userRequest = new BoxUserRequest()
            {
                Id = "181216415",
                Name = "sean"
            };
            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(userRequest.Name, payload.Name);

            //Response check
            Assert.AreEqual("181216415", user.Id);
            Assert.AreEqual("sean", user.Name);
            Assert.AreEqual("*****@*****.**", user.Login);
            Assert.AreEqual("user", user.Type);
        }
예제 #7
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.Length);
            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);

        }