Inheritance: IBoxConfig
示例#1
0
        private async Task ExecuteMainAsync()
        {
            Console.WriteLine("Access token: ");
            var accessToken = Console.ReadLine();

            Console.WriteLine("Remote file name: ");
            var fileName = Console.ReadLine();

            Console.WriteLine("Local file path: ");
            var localFilePath = Console.ReadLine();

            Console.WriteLine("Parent folder Id: ");
            var parentFolderId = Console.ReadLine();

            var timer = Stopwatch.StartNew();

            var auth = new OAuthSession(accessToken, "YOUR_REFRESH_TOKEN", 3600, "bearer");

            var config = new BoxConfig("YOUR_CLIENT_ID", "YOUR_CLIENT_ID", new Uri("http://boxsdk"));
            var client = new BoxClient(config, auth);

            var file = File.OpenRead(localFilePath);
            var fileRequest = new BoxFileRequest
            {
                Name = fileName,
                Parent = new BoxFolderRequest { Id = parentFolderId }
            };

            var bFile = await client.FilesManager.UploadAsync(fileRequest, file);

            Console.WriteLine("{0} uploaded to folder: {1} as file: {2}",localFilePath, parentFolderId, bFile.Id);
            Console.WriteLine("Time spend : {0} ms", timer.ElapsedMilliseconds);
        }
        public MainViewModel()
            : base()
        {
            OAuthSession session = null;

            Config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
            Client = new BoxClient(Config, session);
        }
示例#3
0
        /// <summary>
        /// Create BoxConfigBuilder from json string
        /// </summary>
        /// <param name="jsonString">json string.</param>
        /// <returns>BoxConfigBuilder instance.</returns>
        public static BoxConfigBuilder CreateFromJsonString(string jsonString)
        {
            var config        = BoxConfig.CreateFromJsonString(jsonString);
            var configBuilder = new BoxConfigBuilder();

            RewritePropertiesToBuilder(configBuilder, config);
            return(configBuilder);
        }
示例#4
0
        /// <summary>
        /// Create BoxConfigBuilder from json file.
        /// </summary>
        /// <param name="jsonFile">json file stream.</param>
        /// <returns>BoxConfigBuilder instance.</returns>
        public static BoxConfigBuilder CreateFromJsonFile(Stream jsonFile)
        {
            var config        = BoxConfig.CreateFromJsonFile(jsonFile);
            var configBuilder = new BoxConfigBuilder();

            RewritePropertiesToBuilder(configBuilder, config);
            return(configBuilder);
        }
示例#5
0
        private static BoxClient CreateClientByToken(string token)
        {
            var auth = new OAuthSession(token, "YOUR_REFRESH_TOKEN", 3600, "bearer");

            var config = new BoxConfig(string.Empty, string.Empty, new Uri("http://boxsdk"));
            var client = new BoxClient(config, auth);

            return client;
        }
        public async Task AuthenticateLive_InvalidAuthCode_Exception()
        {
            // Arrange
            IRequestHandler handler = new HttpRequestHandler();
            IBoxService service = new BoxService(handler);
            IBoxConfig config = new BoxConfig(null, null, null);

            IAuthRepository authRepository = new AuthRepository(config, service, _converter);

            // Act
            OAuthSession response = await authRepository.AuthenticateAsync("fakeAuthorizationCode");
        }
示例#7
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");
        }
 public async Task GetFolder_LiveSession_ValidResponse_DeflateCompression()
 {
     var boxConfig = new BoxConfig(ClientId, ClientSecret, RedirectUri) { AcceptEncoding = CompressionType.deflate };
     var boxClient = new BoxClient(boxConfig, _auth);
     await AssertFolderContents(boxClient);
 }
示例#9
0
 static BoxHelper()
 {
     Config = new BoxConfig(BoxClientId, BoxClientSecret, new Uri(RedirectUri));
 }
        public static async Task<BoxClient> Login(string account, string code)
        {
            if (string.IsNullOrEmpty(account))
                throw new ArgumentNullException(nameof(account));

            string refreshToken = LoadRefreshToken(account);

            var client = default(BoxClient);
            var config = new BoxConfig(Secrets.CLIENT_ID, Secrets.CLIENT_SECRET, new Uri(BOX_LOGIN_DESKTOP_URI));

            var response = default(OAuthSession);
            if (!string.IsNullOrEmpty(refreshToken)) {
                client = new BoxClient(config, new OAuthSession(null, refreshToken, 0, "bearer"));
                response = await client.Auth.RefreshAccessTokenAsync(refreshToken);
            }

            if (response == null) {
                client = new BoxClient(config, null);
                if (string.IsNullOrEmpty(code)) {
                    Uri authenticationUri = client.Config.AuthCodeUri;
                    code = GetAuthCode(account, authenticationUri, new Uri(BOX_LOGIN_DESKTOP_URI));
                    if (string.IsNullOrEmpty(code))
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RetrieveAuthenticationCodeFromUri, authenticationUri.ToString()));
                }

                response = await client.Auth.AuthenticateAsync(code);
            }

            SaveRefreshToken(account, response != null ? response.RefreshToken : null);

            return client;
        }