public ActionResult InitiateAuthorization(string clientId, string clientSecret)
 {
     Session[ClientId] = clientId;
     Session[ClientSecret] = clientSecret;
     var boxAuthenticator = new TokenProvider(clientId, clientSecret);
     return new RedirectResult(boxAuthenticator.GetAuthorizationUrl());
 }
 private void RefreshAccessToken()
 {
     var testConfigInfo = TestConfigInfo.Get();
         var authenticator = new TokenProvider(testConfigInfo.ClientId, testConfigInfo.ClientSecret);
         var refreshAccessToken = authenticator.RefreshAccessToken(testConfigInfo.RefreshToken);
         TestConfigInfo.Update(refreshAccessToken);
 }
Beispiel #3
0
        private static void ExecuteAPIMethods(string clientId, string clientSecret, string accessToken, string refreshToken)
        {
            try
            {
                // Optionally refresh the user's access token
                var authenticator = new TokenProvider(clientId, clientSecret);
                var oAuthToken = authenticator.RefreshAccessToken(refreshToken);
                accessToken = oAuthToken.AccessToken;

                // Instantiate a BoxManager with your api key and a user's auth token
                var boxManager = new BoxManager(accessToken);

                // Create a new file in the root folder
                boxManager.CreateFile(Folder.Root, "a new file.txt", Encoding.UTF8.GetBytes("hello, world!"));

                // Fetch the root folder
                Folder folder = boxManager.GetFolder(Folder.Root);

                // Find a 'mini' representation of the created file among the root folder's contents
                File file = folder.Files.Single(f => f.Name.Equals("a new file.txt"));

                // Get the file with all properties populated.
                file = boxManager.Get(file);

                // Rename the file
                file = boxManager.Rename(file, "the new name.txt");

                // Create a new subfolder
                Folder subfolder = boxManager.CreateFolder(Folder.Root, "my subfolder");

                // Move the file to the subfolder
                file = boxManager.Move(file, subfolder);

                // Write some content to the file
                using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("goodbye, world!")))
                {
                    file = boxManager.Write(file, stream);
                }

                // Read the contents to a stream
                using (var stream = new MemoryStream())
                {
                    boxManager.Read(file, stream);
                    using (var reader = new StreamReader(stream))
                    {
                        stream.Position = 0;
                        Console.Out.WriteLine("File content: '{0}'", reader.ReadToEnd());
                    }
                }

                // Delete the folder and its contents
                boxManager.Delete(subfolder, recursive: true);

            }
            catch (BoxException e)
            {
                Console.Out.WriteLine(e);
            }
        }
Beispiel #4
0
 public void RefreshAccessToken()
 {
     var testConfigInfo = TestConfigInfo.Get();
     var authenticator = new TokenProvider(testConfigInfo.ClientId, testConfigInfo.ClientSecret);
     var refreshAccessToken = authenticator.RefreshAccessToken(testConfigInfo.RefreshToken);
     Assert.That(refreshAccessToken.AccessToken, Is.Not.Null);
     Assert.That(refreshAccessToken.AccessToken, Is.Not.EqualTo(testConfigInfo.AccessToken));
     Assert.That(refreshAccessToken.RefreshToken, Is.Not.Null);
     Assert.That(refreshAccessToken.RefreshToken, Is.Not.EqualTo(testConfigInfo.RefreshToken));
     TestConfigInfo.Update(refreshAccessToken);
 }
 private ActionResult Token(string arg1)
 {
     try
     {
         var boxAuthenticator = new TokenProvider(Session[ClientId] as string, Session[ClientSecret] as string);
         OAuthToken accessToken = boxAuthenticator.GetAccessToken(arg1);
         Session[AccessToken] = accessToken.AccessToken;
         Session[RefreshToken] = accessToken.RefreshToken;
         return View("Authorize", accessToken);
     }
     catch (BoxException e)
     {
         return Error(e.Error.Status, e.Message);
     }
     catch (Exception e)
     {
         return Error(e.Message, e.StackTrace);
     }
 }
Beispiel #6
0
 public void GetAuthorizationUrl()
 {
     var authenticator = new TokenProvider("clientId", "clientSecret");
     var authorizationUrl = authenticator.GetAuthorizationUrl("http://foo.com");
     Assert.That(authorizationUrl, Is.EqualTo("https://api.box.com/oauth2/authorize?response_type=code&client_id=clientId&state=authenticated&redirect_uri=http%3A%2F%2Ffoo.com"));
 }
Beispiel #7
0
        /// <summary>
        /// Authorizes an AccessToken and recieves the Bearer Token.
        /// </summary>
        /// <param name="AccessToken">String that will be displayed on the Dropbox site after authorizating an application with user account</param>
        /// <returns>True if Token was authroized successfully, False elsewhere</returns>
        public bool AuthorizeToken(string AccessToken)
        {
            if (authProvider == null)
            {
                authProvider = new TokenProvider(CLIENT_ID, CLIENT_SECRET);
            }
            this.Token = authProvider.GetAccessToken(AccessToken, CLIENT_RETURN_URL);

            return true;
        }