Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Oleson committed Sep 9, 2021
2 parents 2027b7b + 29dadbd commit abd4c12
Show file tree
Hide file tree
Showing 32 changed files with 742 additions and 185 deletions.
8 changes: 4 additions & 4 deletions Box.V2.Samples.Core.AppUser.Create/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Config;
using Box.V2.Config;
using Box.V2.JWTAuth;
using Box.V2.Models;
using System;
Expand Down Expand Up @@ -29,14 +29,14 @@ private async Task ExecuteMainAsync()
var session = new BoxJWTAuth(config);

// client with permissions to manage application users
var adminToken = session.AdminToken();
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 = session.UserToken(user.Id);
var userToken = await session.UserTokenAsync(user.Id);
var userClient = session.UserClient(userToken, user.Id);

// root folder has id = 0
Expand Down Expand Up @@ -86,7 +86,7 @@ private static IBoxConfig ConfigureBoxApi()
IBoxConfig config = null;
using (FileStream fs = new FileStream(@"YOUR_JSON_FILE_HERE", FileMode.Open))
{
config = BoxConfig.CreateFromJsonFile(fs);
config = BoxConfigBuilder.CreateFromJsonFile(fs).Build();
}

return config;
Expand Down
5 changes: 3 additions & 2 deletions Box.V2.Samples.Core.File.Upload/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using Box.V2.Config;
Expand Down Expand Up @@ -41,7 +41,8 @@ private async Task ExecuteMainAsync()

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

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

var file = File.OpenRead(localFilePath);
Expand Down
10 changes: 5 additions & 5 deletions Box.V2.Samples.Core.HttpProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class Program
{
static void Main(string[] args)
{
var boxConfig = BoxConfig.CreateFromJsonString(GetConfigJson());

// Set web proxy
boxConfig.WebProxy = new BoxHttpProxy();
var boxConfig = BoxConfigBuilder.CreateFromJsonString(GetConfigJson())
// Set web proxy
.SetWebProxy(new BoxHttpProxy())
.Build();

var boxJWT = new BoxJWTAuth(boxConfig);

var adminToken = boxJWT.AdminToken();
var adminToken = boxJWT.AdminTokenAsync().Result;
var adminClient = boxJWT.AdminClient(adminToken);

var items = adminClient.FoldersManager.GetFolderItemsAsync("0", 500).Result;
Expand Down
7 changes: 4 additions & 3 deletions Box.V2.Samples.JWTAuth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ 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 BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID);
var boxConfig = new BoxConfigBuilder(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID)
.Build();
var boxJWT = new BoxJWTAuth(boxConfig);

var adminToken = boxJWT.AdminToken();
var adminToken = await boxJWT.AdminTokenAsync();
Console.WriteLine("Admin Token: " + adminToken);
Console.WriteLine();

Expand All @@ -60,7 +61,7 @@ static async Task MainAsync()
var appUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest);
Console.WriteLine("Created App User");

var userToken = boxJWT.UserToken(appUser.Id);
var userToken = await boxJWT.UserTokenAsync(appUser.Id);
var userClient = boxJWT.UserClient(userToken, appUser.Id);

var userDetails = await userClient.UsersManager.GetCurrentUserInformationAsync();
Expand Down
9 changes: 5 additions & 4 deletions Box.V2.Samples.TransactionalAuth/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using Box.V2.Auth;
using Box.V2.Auth.Token;
Expand Down Expand Up @@ -39,7 +39,8 @@ 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 config = new BoxConfigBuilder(string.Empty, string.Empty, new Uri("http://boxsdk"))
.Build();
var client = new BoxClient(config, auth);

return client;
Expand All @@ -58,12 +59,12 @@ private static async Task MainAsync(string token, string fileId, string folderId
var tokenExchange = new TokenExchange(token, scope);

// Check resource to be optional
var token1 = tokenExchange.Exchange();
var token1 = await tokenExchange.ExchangeAsync();
var client1 = CreateClientByToken(token1);

// Set resource
tokenExchange.SetResource(resource);
var token2 = tokenExchange.Exchange();
var token2 = await tokenExchange .ExchangeAsync();
var client2 = CreateClientByToken(token2);
try
{
Expand Down
7 changes: 4 additions & 3 deletions Box.V2.Test.Integration/BoxAuthTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public class BoxAuthTestIntegration : BoxResourceManagerTestIntegration
public const string passphrase = "YOUR_PASSPHRASE";

[TestMethod]
public void retriesWithNewJWTAssertionOnErrorResponseAndSucceeds()
public async Task retriesWithNewJWTAssertionOnErrorResponseAndSucceeds()
{
var config = new BoxConfig(ClientId, ClientSecret, EnterpriseId, privateKey, passphrase, publicKeyID);
var config = new BoxConfigBuilder(ClientId, ClientSecret, EnterpriseId, privateKey, passphrase, publicKeyID)
.Build();
var session = new BoxJWTAuth(config);
var adminToken = session.AdminToken();
var adminToken = await session.AdminTokenAsync();
adminClient = session.AdminClient(adminToken);
}
}
Expand Down
13 changes: 9 additions & 4 deletions Box.V2.Test.Integration/BoxConfigTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Config;
using Box.V2.Config;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;

Expand All @@ -24,11 +24,15 @@ public async Task BoxConfig_SetUriString()
'webhooks': {},
'enterpriseID': 'eid-123'
}";
var config = BoxConfig.CreateFromJsonString(jsonString);
var config = BoxConfigBuilder
.CreateFromJsonString(jsonString)
.Build();
Assert.AreEqual(config.BoxApiUri, new System.Uri(Constants.BoxApiUriString));

System.Uri exampleUri = new System.Uri("https://example.com/");
config.BoxApiUri = exampleUri;
config = BoxConfigBuilder.CreateFromJsonString(jsonString)
.SetBoxApiUri(exampleUri)
.Build();
Assert.AreEqual(config.BoxApiUri, exampleUri);
}

Expand All @@ -49,7 +53,8 @@ public async Task BoxConfig_CreateFromString()
'webhooks': {},
'enterpriseID': 'eid-123'
}";
var config = BoxConfig.CreateFromJsonString(jsonString);
var config = BoxConfigBuilder.CreateFromJsonString(jsonString)
.Build();

Assert.AreEqual(config.ClientId, "cid-123");
Assert.AreEqual(config.ClientSecret, "cre-123");
Expand Down
8 changes: 6 additions & 2 deletions Box.V2.Test.Integration/BoxFoldersManagerTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ public async Task GetFolder_LiveSession_ValidResponse()
[TestMethod]
public async Task GetFolder_LiveSession_ValidResponse_GzipCompression()
{
var boxConfig = new BoxConfig(ClientId, ClientSecret, RedirectUri){AcceptEncoding = CompressionType.gzip};
var boxConfig = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.SetAcceptEncoding(CompressionType.gzip)
.Build();
var boxClient = new BoxClient(boxConfig, _auth);
await AssertFolderContents(boxClient);
}

[TestMethod]
public async Task GetFolder_LiveSession_ValidResponse_DeflateCompression()
{
var boxConfig = new BoxConfig(ClientId, ClientSecret, RedirectUri) { AcceptEncoding = CompressionType.deflate };
var boxConfig = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.SetAcceptEncoding(CompressionType.deflate)
.Build();
var boxClient = new BoxClient(boxConfig, _auth);
await AssertFolderContents(boxClient);
}
Expand Down
15 changes: 9 additions & 6 deletions Box.V2.Test.Integration/BoxResourceManagerTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using System.Diagnostics;
using Box.V2.Auth;
Expand Down Expand Up @@ -44,12 +44,13 @@ public static void Initialize(TestContext testContext)
{
Debug.WriteLine("json config content length : " + jsonConfig.Length);

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

// create a new app user
// client with permissions to manage application users
var adminToken = session.AdminToken();
var adminToken = session.AdminTokenAsync().Result;
adminClient = session.AdminClient(adminToken);

var user = CreateNewUser(adminClient).Result;
Expand All @@ -59,7 +60,7 @@ public static void Initialize(TestContext testContext)
Debug.WriteLine("New app user created : " + userId);

// user client with access to user's data (folders, files, etc)
userToken = session.UserToken(userId);
userToken = session.UserTokenAsync(userId).Result;
userClient = session.UserClient(userToken, userId);
}
}
Expand Down Expand Up @@ -99,12 +100,14 @@ public BoxResourceManagerTestIntegration()
// Legacy way of getting the token
_auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

_config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
_config = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.Build();
_client = new BoxClient(_config, _auth);
}
else
{
_config = BoxConfig.CreateFromJsonString(jsonConfig);
_config = BoxConfigBuilder.CreateFromJsonString(jsonConfig)
.Build();

_client = userClient;
_auth = new OAuthSession(userToken, "", 3600, "bearer");
Expand Down
9 changes: 5 additions & 4 deletions Box.V2.Test.Integration/BoxTokenExchangeTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Auth;
using Box.V2.Auth;
using Box.V2.Auth.Token;
using Box.V2.Config;
using Box.V2.Exceptions;
Expand All @@ -16,7 +16,8 @@ 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 config = new BoxConfigBuilder(string.Empty, string.Empty, new Uri("http://boxsdk"))
.Build();
var client = new BoxClient(config, auth);

return client;
Expand All @@ -39,7 +40,7 @@ public async Task TokenExchange_LiveSession()
var tokenExchange = new TokenExchange(token, scopes);

// Check resource to be optional
var token1 = tokenExchange.Exchange();
var token1 = tokenExchange.ExchangeAsync().Result;
var client1 = CreateClientByToken(token1);

// Should be able to access the file
Expand All @@ -48,7 +49,7 @@ public async Task TokenExchange_LiveSession()

// Set resource
tokenExchange.SetResource(resource);
var token2 = tokenExchange.Exchange();
var token2 = tokenExchange.ExchangeAsync().Result;
var client2 = CreateClientByToken(token2);
try
{
Expand Down
4 changes: 2 additions & 2 deletions Box.V2.Test/AuthRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Box.V2.Services;
using System.Threading.Tasks;
Expand All @@ -23,7 +23,7 @@ public async Task AuthenticateLive_InvalidAuthCode_Exception()
// Arrange
IRequestHandler handler = new HttpRequestHandler();
IBoxService service = new BoxService(handler);
IBoxConfig config = new BoxConfig(null, null, null);
IBoxConfig config = new BoxConfigBuilder(null, null, null).Build();

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

Expand Down
1 change: 1 addition & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="BoxSearchManagerTest.cs" />
<Compile Include="BoxStoragePoliciesManagerTest.cs" />
<Compile Include="BoxTasksManagerTest.cs" />
<Compile Include="BoxTermsOfServiceManagerTest.cs" />
<Compile Include="BoxUsersManagerTest.cs" />
<Compile Include="BoxCollaborationsManagerTest.cs" />
<Compile Include="BoxLegalHoldPoliciesManagerTest.cs" />
Expand Down
12 changes: 6 additions & 6 deletions Box.V2.Test/BoxJWTAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BoxJWTAuthTest()

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public void GetToken_ValidSession()
public async Task GetToken_ValidSession()
{
// Arrange
_handler.Setup(h => h.ExecuteAsyncWithoutRetry<OAuthSession>(It.IsAny<BoxRequest>()))
Expand All @@ -47,7 +47,7 @@ public void GetToken_ValidSession()
})); ;

// Act
String accessToken = _jwtAuth.AdminToken();
String accessToken = await _jwtAuth.AdminTokenAsync();

// Assert
Assert.AreEqual(accessToken, "T9cE5asGnuyYCCqIZFoWjFHvNbvVqHjl");
Expand All @@ -56,7 +56,7 @@ public void GetToken_ValidSession()
[TestMethod]
[TestCategory("CI-UNIT-TEST")]
[ExpectedException(typeof(BoxException))]
public void GetToken_MaxRetries_Exception()
public async Task GetToken_MaxRetries_Exception()
{
// Arrange
_handler.SetupSequence(h => h.ExecuteAsyncWithoutRetry<OAuthSession>(It.IsAny<BoxRequest>()))
Expand Down Expand Up @@ -97,12 +97,12 @@ public void GetToken_MaxRetries_Exception()
}));

// Act
String accessToken = _jwtAuth.AdminToken();
String accessToken = await _jwtAuth.AdminTokenAsync();
}

[TestMethod]
[TestCategory("CI-UNIT-TEST")]
public void GetToken_Retries_ValidSession()
public async Task GetToken_Retries_ValidSession()
{
// Arrange
_handler.SetupSequence(h => h.ExecuteAsyncWithoutRetry<OAuthSession>(It.IsAny<BoxRequest>()))
Expand All @@ -123,7 +123,7 @@ public void GetToken_Retries_ValidSession()
}));

// Act
String accessToken = _jwtAuth.AdminToken();
String accessToken = await _jwtAuth.AdminTokenAsync();

// Assert
Assert.AreEqual(accessToken, "T9cE5asGnuyYCCqIZFoWjFHvNbvVqHjl");
Expand Down
Loading

0 comments on commit abd4c12

Please sign in to comment.