diff --git a/Box.V2.Test/BoxConfigTest.cs b/Box.V2.Test/BoxConfigTest.cs index 9d254872e..3b7a90395 100644 --- a/Box.V2.Test/BoxConfigTest.cs +++ b/Box.V2.Test/BoxConfigTest.cs @@ -63,5 +63,20 @@ public void BoxConfig_CreateFromString() Assert.AreEqual(config.JWTPrivateKey, "DUMMY"); Assert.AreEqual(config.EnterpriseId, "eid-123"); } + + [TestMethod] + [TestCategory("CI-UNIT-TEST")] + public void BoxConfig_SetAuthTokenUriString() + { + var boxConfig = new BoxConfigBuilder("", "", "", "", "", "") + .Build(); + Assert.AreEqual(boxConfig.BoxAuthTokenApiUri, new System.Uri(Constants.BoxAuthTokenApiUriString)); + + var exampleUri = new System.Uri("https://example.com/"); + var newConfig = new BoxConfigBuilder("", "", "", "", "", "") + .SetBoxTokenApiUri(exampleUri) + .Build(); + Assert.AreEqual(newConfig.BoxAuthTokenApiUri, exampleUri); + } } } diff --git a/Box.V2.Test/BoxJWTAuthTest.cs b/Box.V2.Test/BoxJWTAuthTest.cs index 5a823b4a5..1b8a1f29d 100644 --- a/Box.V2.Test/BoxJWTAuthTest.cs +++ b/Box.V2.Test/BoxJWTAuthTest.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Box.V2.Auth; using Box.V2.Config; @@ -25,6 +26,7 @@ public BoxJWTAuthTest() _service = new BoxService(_handler.Object); _boxConfig = new Mock(); _boxConfig.SetupGet(x => x.EnterpriseId).Returns("12345"); + _boxConfig.SetupGet(x => x.BoxAuthTokenApiUri).Returns(new Uri(Constants.BoxAuthTokenApiUriString)); _jwtAuth = new BoxJWTAuth(_boxConfig.Object, _service); } diff --git a/Box.V2/Config/BoxConfig.cs b/Box.V2/Config/BoxConfig.cs index 84c0ca322..7a4a823f7 100644 --- a/Box.V2/Config/BoxConfig.cs +++ b/Box.V2/Config/BoxConfig.cs @@ -59,6 +59,7 @@ public BoxConfig(BoxConfigBuilder builder) BoxAccountApiHostUri = builder.BoxAccountApiHostUri; BoxApiUri = builder.BoxApiUri; BoxUploadApiUri = builder.BoxUploadApiUri; + BoxAuthTokenApiUri = builder.BoxAuthTokenApiUri; RedirectUri = builder.RedirectUri; DeviceId = builder.DeviceId; DeviceName = builder.DeviceName; @@ -147,6 +148,7 @@ public static IBoxConfig CreateFromJsonString(string jsonString) public Uri BoxAccountApiHostUri { get; private set; } = new Uri(Constants.BoxAccountApiHostUriString); public Uri BoxApiUri { get; private set; } = new Uri(Constants.BoxApiUriString); public Uri BoxUploadApiUri { get; private set; } = new Uri(Constants.BoxUploadApiUriString); + public Uri BoxAuthTokenApiUri { get; private set; } = new Uri(Constants.BoxAuthTokenApiUriString); public string ClientId { get; private set; } public string ConsumerKey { get; private set; } diff --git a/Box.V2/Config/BoxConfigBuilder.cs b/Box.V2/Config/BoxConfigBuilder.cs index b9b3d570a..f233469a9 100644 --- a/Box.V2/Config/BoxConfigBuilder.cs +++ b/Box.V2/Config/BoxConfigBuilder.cs @@ -148,6 +148,17 @@ public BoxConfigBuilder SetBoxUploadApiUri(Uri boxUploadApiUri) return this; } + /// + /// Sets BoxAPI auth token uri. + /// + /// BoxAPI auth token uri. + /// this BoxConfigBuilder object for chaining + public BoxConfigBuilder SetBoxTokenApiUri(Uri boxAuthTokenApiUri) + { + BoxAuthTokenApiUri = boxAuthTokenApiUri; + return this; + } + /// /// Sets redirect uri. /// @@ -227,6 +238,7 @@ public BoxConfigBuilder SetTimeout(TimeSpan timeout) public Uri BoxAccountApiHostUri { get; private set; } = new Uri(Constants.BoxAccountApiHostUriString); public Uri BoxApiUri { get; private set; } = new Uri(Constants.BoxApiUriString); public Uri BoxUploadApiUri { get; private set; } = new Uri(Constants.BoxUploadApiUriString); + public Uri BoxAuthTokenApiUri { get; private set; } = new Uri(Constants.BoxAuthTokenApiUriString); public Uri RedirectUri { get; private set; } public string DeviceId { get; private set; } diff --git a/Box.V2/Config/Constants.cs b/Box.V2/Config/Constants.cs index 754584a0a..9c7b4e396 100644 --- a/Box.V2/Config/Constants.cs +++ b/Box.V2/Config/Constants.cs @@ -9,6 +9,7 @@ public static class Constants public const string BoxAccountApiHostUriString = "https://account.box.com/api/"; public const string BoxApiUriString = "https://api.box.com/2.0/"; public const string BoxUploadApiUriString = "https://upload.box.com/api/2.0/"; + public const string BoxAuthTokenApiUriString = "https://api.box.com/oauth2/token"; /*** API Endpoints ***/ diff --git a/Box.V2/Config/IBoxConfig.cs b/Box.V2/Config/IBoxConfig.cs index abe7a5540..c614fd8b5 100644 --- a/Box.V2/Config/IBoxConfig.cs +++ b/Box.V2/Config/IBoxConfig.cs @@ -9,6 +9,7 @@ public interface IBoxConfig Uri BoxAccountApiHostUri { get; } Uri BoxApiUri { get; } Uri BoxUploadApiUri { get; } + Uri BoxAuthTokenApiUri { get; } string ClientId { get; } string ConsumerKey { get; } diff --git a/Box.V2/JWTAuth/BoxJWTAuth.cs b/Box.V2/JWTAuth/BoxJWTAuth.cs index 77b106dda..8713fa9e9 100644 --- a/Box.V2/JWTAuth/BoxJWTAuth.cs +++ b/Box.V2/JWTAuth/BoxJWTAuth.cs @@ -30,7 +30,6 @@ namespace Box.V2.JWTAuth /// public class BoxJWTAuth { - private const string AUTH_URL = "https://api.box.com/oauth2/token"; private const string ENTERPRISE_SUB_TYPE = "enterprise"; private const string USER_SUB_TYPE = "user"; private const string TOKEN_TYPE = "bearer"; @@ -252,7 +251,7 @@ private string ConstructJWTAssertion(string sub, string boxSubType, DateTimeOffs expireTime = nowOverride.Value.AddSeconds(30); } - var payload = new JwtPayload(_boxConfig.ClientId, AUTH_URL, claims, null, expireTime.LocalDateTime); + var payload = new JwtPayload(_boxConfig.ClientId, _boxConfig.BoxAuthTokenApiUri.ToString(), claims, null, expireTime.LocalDateTime); var header = new JwtHeader(signingCredentials: _credentials); if (_boxConfig.JWTPublicKeyId != null)