private async Task ExecuteMainAsync() { var config = ConfigureBoxApi(); var session = new BoxJWTAuth(config); // client with permissions to manage application users var adminToken = session.AdminToken(); 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 = session.UserToken(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); }
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"); }