示例#1
0
        private async Task ExecuteMainAsync()
        {
            var config = ConfigureBoxApi();

            var session = new BoxJWTAuth(config);

            // client with permissions to manage application users
            var adminToken = await session.AdminTokenAsync();

            var client = session.AdminClient(adminToken);

            var user = await CreateNewUser(client);

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

            // user client with access to user's data (folders, files, etc)
            var userToken = await session.UserTokenAsync(user.Id);

            var userClient = session.UserClient(userToken, user.Id);

            // root folder has id = 0
            var newFolder = await CreateNewFolder(userClient);

            Console.WriteLine("New folder created with Id = {0}", newFolder.Id);

            var timer    = Stopwatch.StartNew();
            var file     = File.OpenRead("box_logo.png");
            var uploaded = await UploadFile(newFolder, userClient, file);

            Console.WriteLine("New file uploaded with Id = {0} in {1} ms", uploaded.Id, timer.ElapsedMilliseconds);
        }
        public static async Task AssemblyInitialize(TestContext testContext)
        {
            var jsonConfig = Environment.GetEnvironmentVariable("INTEGRATION_TESTING_CONFIG");

            if (string.IsNullOrEmpty(jsonConfig))
            {
                Debug.WriteLine("No json config found in environment variables Reading from config.json.");
                jsonConfig = ReadFromJson("config.json");
            }

            var config = BoxConfigBuilder.CreateFromJsonString(jsonConfig)
                         .Build();
            var session = new BoxJWTAuth(config);

            var json       = JObject.Parse(jsonConfig);
            var adminToken = await session.AdminTokenAsync();

            AdminClient = session.AdminClient(adminToken);

            if (json["userID"] != null && json["userID"].ToString().Length != 0)
            {
                UserId = json["userID"].ToString();
            }
            else
            {
                var user = await CreateNewUser(AdminClient);

                UserId = user.Id;
            }
            var userToken = await session.UserTokenAsync(UserId);

            UserClient = session.UserClient(userToken, UserId);

            EnterpriseId = config.EnterpriseId;
        }
示例#3
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");
        }