diff --git a/.codegen.json b/.codegen.json new file mode 100644 index 00000000..359dd7af --- /dev/null +++ b/.codegen.json @@ -0,0 +1 @@ +{ "engineHash": "905c6a0", "specHash": "b2f7568", "version": "0.1.0" } diff --git a/Box.Sdk.Gen.Tests.Integration/Test/Auth/AuthManagerTests.cs b/Box.Sdk.Gen.Tests.Integration/Test/Auth/AuthManagerTests.cs index 6a5bdf68..27eafc25 100644 --- a/Box.Sdk.Gen.Tests.Integration/Test/Auth/AuthManagerTests.cs +++ b/Box.Sdk.Gen.Tests.Integration/Test/Auth/AuthManagerTests.cs @@ -134,13 +134,12 @@ public async System.Threading.Tasks.Task TestDeveloperTokenAuth() { public async System.Threading.Tasks.Task TestOauthAuthRevoke() { OAuthConfig config = new OAuthConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET")); BoxOAuth auth = new BoxOAuth(config: config); + BoxClient client = new BoxClient(auth: auth); AccessToken token = await GetAccessTokenAsync().ConfigureAwait(false); await auth.TokenStorage.StoreAsync(token: token).ConfigureAwait(false); - AccessToken? tokenBeforeRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false); + await client.Users.GetUserMeAsync().ConfigureAwait(false); await auth.RevokeTokenAsync().ConfigureAwait(false); - AccessToken? tokenAfterRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false); - Assert.IsTrue(tokenBeforeRevoke != null); - Assert.IsTrue(tokenAfterRevoke == null); + await Assert.That.IsExceptionAsync(async() => await client.Users.GetUserMeAsync().ConfigureAwait(false)); } [TestMethod] diff --git a/Box.Sdk.Gen/Box/CcgAuth/BoxCcgAuth.cs b/Box.Sdk.Gen/Box/CcgAuth/BoxCcgAuth.cs index 66ad7629..cde63ddf 100644 --- a/Box.Sdk.Gen/Box/CcgAuth/BoxCcgAuth.cs +++ b/Box.Sdk.Gen/Box/CcgAuth/BoxCcgAuth.cs @@ -63,6 +63,11 @@ public async System.Threading.Tasks.Task RetrieveTokenAsync(Network return oldToken; } + public async System.Threading.Tasks.Task RetrieveAuthorizationHeaderAsync(NetworkSession? networkSession = null) { + AccessToken token = await this.RetrieveTokenAsync(networkSession: networkSession).ConfigureAwait(false); + return string.Concat("Bearer ", token.AccessTokenField); + } + /// /// Create a new BoxCCGAuth instance that uses the provided user ID as the subject ID. /// May be one of this application's created App User. Depending on the configured User Access Level, may also be any other App User or Managed User in the enterprise. diff --git a/Box.Sdk.Gen/Box/DeveloperTokenAuth/BoxDeveloperTokenAuth.cs b/Box.Sdk.Gen/Box/DeveloperTokenAuth/BoxDeveloperTokenAuth.cs index 9941c48e..fa5d9104 100644 --- a/Box.Sdk.Gen/Box/DeveloperTokenAuth/BoxDeveloperTokenAuth.cs +++ b/Box.Sdk.Gen/Box/DeveloperTokenAuth/BoxDeveloperTokenAuth.cs @@ -30,5 +30,10 @@ public async System.Threading.Tasks.Task RefreshTokenAsync(NetworkS throw new BoxSdkError(message: "Developer token has expired. Please provide a new one."); } + public async System.Threading.Tasks.Task RetrieveAuthorizationHeaderAsync(NetworkSession? networkSession = null) { + AccessToken token = await this.RetrieveTokenAsync(networkSession: networkSession).ConfigureAwait(false); + return string.Concat("Bearer ", token.AccessTokenField); + } + } } \ No newline at end of file diff --git a/Box.Sdk.Gen/Box/JwtAuth/BoxJwtAuth.cs b/Box.Sdk.Gen/Box/JwtAuth/BoxJwtAuth.cs index 254de8bb..3cf734df 100644 --- a/Box.Sdk.Gen/Box/JwtAuth/BoxJwtAuth.cs +++ b/Box.Sdk.Gen/Box/JwtAuth/BoxJwtAuth.cs @@ -74,6 +74,11 @@ public async System.Threading.Tasks.Task RetrieveTokenAsync(Network return oldToken; } + public async System.Threading.Tasks.Task RetrieveAuthorizationHeaderAsync(NetworkSession? networkSession = null) { + AccessToken token = await this.RetrieveTokenAsync(networkSession: networkSession).ConfigureAwait(false); + return string.Concat("Bearer ", token.AccessTokenField); + } + /// /// Create a new BoxJWTAuth instance that uses the provided user ID as the subject of the JWT assertion. /// May be one of this application's created App User. Depending on the configured User Access Level, may also be any other App User or Managed User in the enterprise. diff --git a/Box.Sdk.Gen/Box/Oauth/BoxOAuth.cs b/Box.Sdk.Gen/Box/Oauth/BoxOAuth.cs index 1a42db2c..41b3c8b1 100644 --- a/Box.Sdk.Gen/Box/Oauth/BoxOAuth.cs +++ b/Box.Sdk.Gen/Box/Oauth/BoxOAuth.cs @@ -81,6 +81,11 @@ public async System.Threading.Tasks.Task RefreshTokenAsync(NetworkS return token; } + public async System.Threading.Tasks.Task RetrieveAuthorizationHeaderAsync(NetworkSession? networkSession = null) { + AccessToken token = await this.RetrieveTokenAsync(networkSession: networkSession).ConfigureAwait(false); + return string.Concat("Bearer ", token.AccessTokenField); + } + /// /// Revoke an active Access Token, effectively logging a user out that has been previously authenticated. /// @@ -94,7 +99,6 @@ public async System.Threading.Tasks.Task RevokeTokenAsync(NetworkSession? networ } AuthorizationManager authManager = networkSession != null ? new AuthorizationManager(networkSession: networkSession) : new AuthorizationManager(); await authManager.RevokeAccessTokenAsync(requestBody: new PostOAuth2Revoke() { ClientId = this.Config.ClientId, ClientSecret = this.Config.ClientSecret, Token = token.AccessTokenField }).ConfigureAwait(false); - await this.TokenStorage.ClearAsync().ConfigureAwait(false); } /// diff --git a/Box.Sdk.Gen/Networking/Auth/IAuthentication.cs b/Box.Sdk.Gen/Networking/Auth/IAuthentication.cs index 95c5e451..8d9b99ae 100644 --- a/Box.Sdk.Gen/Networking/Auth/IAuthentication.cs +++ b/Box.Sdk.Gen/Networking/Auth/IAuthentication.cs @@ -6,7 +6,9 @@ namespace Box.Sdk.Gen { public interface IAuthentication { public System.Threading.Tasks.Task RetrieveTokenAsync(NetworkSession? networkSession = null); - public System.Threading.Tasks.Task RefreshTokenAsync(NetworkSession networkSession); + public System.Threading.Tasks.Task RefreshTokenAsync(NetworkSession? networkSession = null); + + public System.Threading.Tasks.Task RetrieveAuthorizationHeaderAsync(NetworkSession? networkSession = null); } } \ No newline at end of file diff --git a/Box.Sdk.Gen/Networking/Fetch.cs b/Box.Sdk.Gen/Networking/Fetch.cs index 786ec671..f989d249 100644 --- a/Box.Sdk.Gen/Networking/Fetch.cs +++ b/Box.Sdk.Gen/Networking/Fetch.cs @@ -148,8 +148,8 @@ private static async Task BuildHttpRequest(string resource, if (options.Auth != null) { - var token = await options.Auth.RetrieveTokenAsync().ConfigureAwait(false); - httpRequest.Headers.Add("Authorization", $"Bearer {token.AccessTokenField}"); + var authHeaderValue = await options.Auth.RetrieveAuthorizationHeaderAsync(options.NetworkSession).ConfigureAwait(false); + httpRequest.Headers.Add("Authorization", authHeaderValue); } return httpRequest;