diff --git a/APSToolkit/APSToolkit.csproj b/APSToolkit/APSToolkit.csproj index 013f68c..5a1036e 100644 --- a/APSToolkit/APSToolkit.csproj +++ b/APSToolkit/APSToolkit.csproj @@ -1,7 +1,7 @@ enable - disable + enable APSToolkit net6 latest diff --git a/APSToolkit/Auth.cs b/APSToolkit/Auth.cs new file mode 100644 index 0000000..894fc12 --- /dev/null +++ b/APSToolkit/Auth.cs @@ -0,0 +1,279 @@ +// Copyright (c) chuongmep.com. All rights reserved + +using System.Diagnostics; +using System.Net; +using System.Text; +using Autodesk.Forge; +using Newtonsoft.Json; + +namespace APSToolkit; + +public class Auth +{ + private string? ClientId { get; set; } + private string? ClientSecret { get; set; } + + private Token Token { get; set; } + public Auth(string? clientId, string? clientSecret) + { + this.ClientId = clientId; + this.ClientSecret = clientSecret; + this.Token = new Token(); + } + + public Auth() + { + this.ClientId = Environment.GetEnvironmentVariable("APS_CLIENT_ID",EnvironmentVariableTarget.User); + this.ClientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); + this.Token = new Token(); + } + + /// + /// Sets the Autodesk Forge Design Automation environment variables required for authentication. + /// + /// The client ID for Autodesk Forge. + /// The client secret for Autodesk Forge. + /// The callback URL for Autodesk Forge authentication. + public static void SetEnvironmentVariables(string clientId, string clientSecret, string callbackUrl) + { + Environment.SetEnvironmentVariable("APS_CLIENT_ID", clientId); + Environment.SetEnvironmentVariable("APS_CLIENT_SECRET", clientSecret); + Environment.SetEnvironmentVariable("APS_CALLBACK_URL", callbackUrl); + } + + /// + /// Retrieves the Autodesk Forge Design Automation client ID from the environment variables. + /// Throws an exception if the environment variable is missing or empty. + /// + /// The Autodesk Forge Design Automation client ID. + public string GetClientId() + { + var clientId = Environment.GetEnvironmentVariable("APS_CLIENT_ID"); + if (string.IsNullOrEmpty(clientId)) + { + throw new Exception("Missing APS_CLIENT_ID environment variable."); + } + + return clientId; + } + + /// + /// Retrieves the Autodesk Forge Design Automation client secret from the environment variables. + /// Throws an exception if the environment variable is missing or empty. + /// + /// The Autodesk Forge Design Automation client secret. + public string GetClientSecret() + { + var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET"); + if (string.IsNullOrEmpty(clientSecret)) + { + throw new Exception("Missing APS_CLIENT_SECRET environment variable."); + } + + return clientSecret; + } + + /// + /// Retrieves the Autodesk Forge Design Automation callback URL from the environment variables. + /// Throws an exception if the environment variable is missing or empty. + /// + /// The Autodesk Forge Design Automation callback URL. + public static string GetCallbackUrl() + { + var CallbackUrl = Environment.GetEnvironmentVariable("APS_CALLBACK_URL"); + if (string.IsNullOrEmpty(CallbackUrl)) + { + throw new Exception("Missing APS_CALLBACK_URL environment variable."); + } + + return CallbackUrl; + } + + /// + /// Retrieves a 2-legged access token from the Autodesk Forge API using client credentials. + /// + /// The 2-legged access token. + /// Thrown when APS_CLIENT_ID or APS_CLIENT_SECRET environment variables are missing. + public async Task Get2LeggedToken() + { + Autodesk.Forge.TwoLeggedApi twoLeggedApi = new Autodesk.Forge.TwoLeggedApi(); + if (string.IsNullOrEmpty(ClientId) || string.IsNullOrEmpty(ClientSecret)) + { + throw new Exception("Missing APS_CLIENT_ID or APS_CLIENT_SECRET environment variables."); + } + dynamic token = await twoLeggedApi.AuthenticateAsync(ClientId, ClientSecret, "client_credentials", + new Scope[] + { + Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.DataSearch, Scope.BucketCreate, + Scope.BucketRead, Scope.CodeAll, + Scope.BucketUpdate, Scope.BucketDelete + }).ConfigureAwait(false); + this.Token.AccessToken = token.access_token; + this.Token.TokenType = token.token_type; + this.Token.ExpiresIn = token.expires_in; + if (string.IsNullOrEmpty(this.Token.AccessToken)) + { + throw new Exception("can't get access_token, please check again value APS_CLIENT_ID and APS_CLIENT_SECRET"); + } + return Token; + } + public async Task Get3LeggedToken(string? callbackUrl = null, string? scopes = null) + { + if (string.IsNullOrEmpty(scopes)) + { + scopes = + "data:read data:write data:create data:search bucket:create bucket:read bucket:update bucket:delete code:all"; + } + + if (string.IsNullOrEmpty(callbackUrl)) + { + callbackUrl = "http://localhost:8080/api/auth/callback"; + } + + var authUrl = $"https://developer.api.autodesk.com/authentication/v2/authorize?response_type=code&client_id={ClientId}&redirect_uri={callbackUrl}&scope={scopes}"; + + OpenDefaultBrowser(authUrl); + + // Start listening for the callback URL + using var listener = new HttpListener(); + listener.Prefixes.Add(callbackUrl + "/"); + listener.Start(); + + Console.WriteLine($"Listening for callback at: {callbackUrl}"); + + while (true) + { + var context = await listener.GetContextAsync(); + var request = context.Request; + var response = context.Response; + + // Extract code from callback URL + var query = request.Url?.Query; + var queryParams = System.Web.HttpUtility.ParseQueryString(query!); + var code = queryParams["code"]; + + var token = await HandleCallback(callbackUrl, code); + + this.Token.AccessToken = token!.AccessToken; + this.Token.TokenType = token.TokenType; + this.Token.ExpiresIn = token.ExpiresIn; + this.Token.RefreshToken = token.RefreshToken; + + var responseString = "Authentication successful. You can close this window now."; + var buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + response.ContentLength64 = buffer.Length; + await response.OutputStream.WriteAsync(buffer, 0, buffer.Length); + response.Close(); + + break; + } + listener.Stop(); + Environment.SetEnvironmentVariable("APS_REFRESH_TOKEN", Token.RefreshToken, EnvironmentVariableTarget.User); + return Token; + } + + private async Task HandleCallback(string callbackUrl, string? code) + { + var tokenUrl = "https://developer.api.autodesk.com/authentication/v2/token"; + var payload = $"grant_type=authorization_code&code={code}&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri={callbackUrl}"; + + using var client = new HttpClient(); + var content = new StringContent(payload, Encoding.UTF8, "application/x-www-form-urlencoded"); + var response = await client.PostAsync(tokenUrl, content); + + if (!response.IsSuccessStatusCode) + { + var errorMessage = await response.Content.ReadAsStringAsync(); + throw new Exception($"Failed to retrieve token: {errorMessage}"); + } + + var jsonResponse = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(jsonResponse); + } + + private void OpenDefaultBrowser(string url) + { + try + { + // Use the default browser on the system to open the URL + Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + } + catch (Exception ex) + { + // Handle any exceptions, such as if there's no default browser set + Console.WriteLine($"Error opening default browser: {ex.Message}"); + } + } + + /// + /// Refreshes a 3-legged access token from the Autodesk Forge API using the refresh token grant type. + /// + /// The refresh token obtained during the initial authentication. + /// The array of scopes specifying the access permissions for the refreshed token. + /// The refreshed 3-legged access token. + /// Thrown when clientId, clientSecret, or refreshToken is null or empty. + public async Task Refresh3LeggedToken(string refreshToken, + Scope[] scope) + { + Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); + if (string.IsNullOrEmpty(ClientId) || string.IsNullOrEmpty(ClientSecret) || string.IsNullOrEmpty(refreshToken)) + { + throw new Exception("Missing required parameters: clientId, clientSecret, or refreshToken."); + } + + threeLeggedApi.Configuration.AccessToken = Get2LeggedToken().Result.AccessToken; + dynamic token = await threeLeggedApi + .RefreshtokenAsync(ClientId, ClientSecret, "refresh_token", refreshToken, scope).ConfigureAwait(false); + var accessToken = token.access_token; + // set refresh token + var newRefreshToken = token.refresh_token; + // set value to environment variable + Environment.SetEnvironmentVariable("APS_REFRESH_TOKEN", newRefreshToken, EnvironmentVariableTarget.User); + this.Token.AccessToken = accessToken; + this.Token.TokenType = token.token_type; + this.Token.ExpiresIn = token.expires_in; + this.Token.RefreshToken = newRefreshToken; + return Token; + } + + /// + /// Refreshes a 3-legged access token from the Autodesk Forge API using the refresh token grant type. + /// + /// The client ID associated with the Forge application. + /// The client secret associated with the Forge application. + /// The array of scopes specifying the access permissions for the refreshed token. + /// The refreshed 3-legged access token. + /// Thrown when clientId, clientSecret, or APS_REFRESH_TOKEN is null or empty. + public async Task Refresh3LeggedToken(string clientId, string clientSecret, Scope[] scope) + { + var refreshToken = Environment.GetEnvironmentVariable("APS_REFRESH_TOKEN", EnvironmentVariableTarget.User); + if (string.IsNullOrEmpty(refreshToken)) throw new Exception("Missing APS_REFRESH_TOKEN environment variable."); + Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); + if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret)) + throw new Exception("Missing required parameters: clientId, clientSecret."); + threeLeggedApi.Configuration.AccessToken = Get2LeggedToken().Result.AccessToken; + dynamic token = await threeLeggedApi + .RefreshtokenAsync(clientId, clientSecret, "refresh_token", refreshToken, scope).ConfigureAwait(false); + var accessToken = token.access_token; + // set refresh token + var newRefreshToken = token.refresh_token; + // set value to environment variable + Environment.SetEnvironmentVariable("APS_REFRESH_TOKEN", newRefreshToken, EnvironmentVariableTarget.User); + Token newToken = new Token() + { + AccessToken = accessToken, + TokenType = token.token_type, + ExpiresIn = token.expires_in, + RefreshToken = newRefreshToken + }; + return newToken; + } + + public static Task Refresh3LeggedToken(Scope[] scope) + { + var clientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID", EnvironmentVariableTarget.User); + var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); + var Leg3Token = new Auth().Refresh3LeggedToken(clientID, clientSecret, scope).Result; + return Task.FromResult(Leg3Token); + } +} \ No newline at end of file diff --git a/APSToolkit/Auth/Authentication.cs b/APSToolkit/Auth/Authentication.cs deleted file mode 100644 index 8a74c36..0000000 --- a/APSToolkit/Auth/Authentication.cs +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (c) chuongmep.com. All rights reserved - -using Autodesk.Forge; - -namespace APSToolkit.Auth; - -public static class Authentication -{ - /// - /// Sets the Autodesk Forge Design Automation environment variables required for authentication. - /// - /// The client ID for Autodesk Forge. - /// The client secret for Autodesk Forge. - /// The callback URL for Autodesk Forge authentication. - public static void SetEnvironmentVariables(string ClientID, string ClientSecret, string CallbackUrl) - { - Environment.SetEnvironmentVariable("APS_CLIENT_ID", ClientID); - Environment.SetEnvironmentVariable("APS_CLIENT_SECRET", ClientSecret); - Environment.SetEnvironmentVariable("APS_CALLBACK_URL", CallbackUrl); - } - - /// - /// Retrieves the Autodesk Forge Design Automation client ID from the environment variables. - /// Throws an exception if the environment variable is missing or empty. - /// - /// The Autodesk Forge Design Automation client ID. - public static string GetClientId() - { - var ClientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID"); - if (string.IsNullOrEmpty(ClientID)) - { - throw new Exception("Missing APS_CLIENT_ID environment variable."); - } - - return ClientID; - } - - /// - /// Retrieves the Autodesk Forge Design Automation client secret from the environment variables. - /// Throws an exception if the environment variable is missing or empty. - /// - /// The Autodesk Forge Design Automation client secret. - public static string GetClientSecret() - { - var ClientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET"); - if (string.IsNullOrEmpty(ClientSecret)) - { - throw new Exception("Missing APS_CLIENT_SECRET environment variable."); - } - - return ClientSecret; - } - - /// - /// Retrieves the Autodesk Forge Design Automation callback URL from the environment variables. - /// Throws an exception if the environment variable is missing or empty. - /// - /// The Autodesk Forge Design Automation callback URL. - public static string GetCallbackUrl() - { - var CallbackUrl = Environment.GetEnvironmentVariable("APS_CALLBACK_URL"); - if (string.IsNullOrEmpty(CallbackUrl)) - { - throw new Exception("Missing APS_CALLBACK_URL environment variable."); - } - - return CallbackUrl; - } - - /// - /// Retrieves a 2-legged access token from the Autodesk Forge API using client credentials. - /// - /// The 2-legged access token. - /// Thrown when APS_CLIENT_ID or APS_CLIENT_SECRET environment variables are missing. - public static async Task Get2LeggedToken() - { - Autodesk.Forge.TwoLeggedApi twoLeggedApi = new Autodesk.Forge.TwoLeggedApi(); - var ClientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID"); - var ClientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET"); - if (string.IsNullOrEmpty(ClientID) || string.IsNullOrEmpty(ClientSecret)) - { - throw new Exception("Missing APS_CLIENT_ID or APS_CLIENT_SECRET environment variables."); - } - - dynamic token = await twoLeggedApi.AuthenticateAsync(ClientID, ClientSecret, "client_credentials", - new Scope[] - { - Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.DataSearch, Scope.BucketCreate, - Scope.BucketRead, Scope.CodeAll, - Scope.BucketUpdate, Scope.BucketDelete - }).ConfigureAwait(false); - Token newToken = new Token() - { - access_token = token.access_token, - token_type = token.token_type, - expires_in = token.expires_in - }; - if (string.IsNullOrEmpty(newToken.access_token)) - { - throw new Exception("can't get access_token, please check again value APS_CLIENT_ID and APS_CLIENT_SECRET"); - } - - return newToken; - } - - /// - /// Retrieves a 2-legged access token from the Autodesk Forge API using client credentials. - /// - /// The client ID for authentication. - /// The client secret for authentication. - /// The 2-legged access token. - /// Thrown when clientId or clientSecret is null or empty. - public static async Task Get2LeggedToken(string clientId, string clientSecret) - { - Autodesk.Forge.TwoLeggedApi twoLeggedApi = new Autodesk.Forge.TwoLeggedApi(); - if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret)) - { - throw new Exception("Missing APS_CLIENT_ID or APS_CLIENT_SECRET environment variables."); - } - - dynamic token = await twoLeggedApi.AuthenticateAsync(clientId, clientSecret, "client_credentials", - new Scope[] - { - Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.DataSearch, Scope.BucketCreate, - Scope.BucketRead, - Scope.BucketUpdate, Scope.BucketDelete - }).ConfigureAwait(false); - Token newToken = new Token() - { - access_token = token.access_token, - token_type = token.token_type, - expires_in = token.expires_in - }; - return newToken; - } - - /// - /// Retrieves a 3-legged access token from the Autodesk Forge API using the authorization code flow. - /// - /// The authorization code received from the Forge authentication callback. - /// The callback URL used during the initial authentication request. - /// The 3-legged access token. - /// Thrown when FORGE_CLIENT_ID or FORGE_CLIENT_SECRET environment variables are missing or empty. - public static async Task Get3LeggedToken(string code, string callbackUrl) - { - Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); - var ClientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID"); - var ClientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET"); - if (string.IsNullOrEmpty(ClientID) || string.IsNullOrEmpty(ClientSecret)) - { - throw new Exception("Missing FORGE_CLIENT_ID or FORGE_CLIENT_SECRET environment variables."); - } - - dynamic token = await threeLeggedApi - .GettokenAsync(ClientID, ClientSecret, "authorization_code", code, callbackUrl).ConfigureAwait(false); - var access_token = token.access_token; - return access_token; - } - - /// - /// Retrieves a 3-legged access token from the Autodesk Forge API using the authorization code flow. - /// - /// The client ID associated with the Forge application. - /// The client secret associated with the Forge application. - /// The authorization code received from the Forge authentication callback. - /// The callback URL used during the initial authentication request. - /// The 3-legged access token. - /// Thrown when clientId or clientSecret is null or empty. - public static async Task Get3LeggedToken(string clientId, string clientSecret, string code, - string callbackUrl) - { - Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); - if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret)) - { - throw new Exception("Missing FORGE_CLIENT_ID or FORGE_CLIENT_SECRET environment variables."); - } - - dynamic token = await threeLeggedApi - .GettokenAsync(clientId, clientSecret, "authorization_code", code, callbackUrl).ConfigureAwait(false); - var access_token = token.access_token; - return access_token; - } - - /// - /// Refreshes a 3-legged access token from the Autodesk Forge API using the refresh token grant type. - /// - /// The client ID associated with the Forge application. - /// The client secret associated with the Forge application. - /// The refresh token obtained during the initial authentication. - /// The array of scopes specifying the access permissions for the refreshed token. - /// The refreshed 3-legged access token. - /// Thrown when clientId, clientSecret, or refreshToken is null or empty. - public static async Task Refresh3LeggedToken(string clientId, string clientSecret, string refreshToken, - Scope[] scope) - { - Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); - if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret) || string.IsNullOrEmpty(refreshToken)) - { - throw new Exception("Missing required parameters: clientId, clientSecret, or refreshToken."); - } - - threeLeggedApi.Configuration.AccessToken = Get2LeggedToken(clientId, clientSecret).Result.access_token; - dynamic token = await threeLeggedApi - .RefreshtokenAsync(clientId, clientSecret, "refresh_token", refreshToken, scope).ConfigureAwait(false); - var accessToken = token.access_token; - // set refresh token - var newRefreshToken = token.refresh_token; - // set value to environment variable - Environment.SetEnvironmentVariable("APS_REFRESH_TOKEN", newRefreshToken, EnvironmentVariableTarget.User); - Token newToken = new Token() - { - access_token = accessToken, - token_type = token.token_type, - expires_in = token.expires_in, - refresh_token = newRefreshToken - }; - return newToken; - } - - /// - /// Refreshes a 3-legged access token from the Autodesk Forge API using the refresh token grant type. - /// - /// The client ID associated with the Forge application. - /// The client secret associated with the Forge application. - /// The array of scopes specifying the access permissions for the refreshed token. - /// The refreshed 3-legged access token. - /// Thrown when clientId, clientSecret, or APS_REFRESH_TOKEN is null or empty. - public static async Task Refresh3LeggedToken(string clientId, string clientSecret, Scope[] scope) - { - var refreshToken = Environment.GetEnvironmentVariable("APS_REFRESH_TOKEN", EnvironmentVariableTarget.User); - if (string.IsNullOrEmpty(refreshToken)) throw new Exception("Missing APS_REFRESH_TOKEN environment variable."); - Autodesk.Forge.ThreeLeggedApi threeLeggedApi = new Autodesk.Forge.ThreeLeggedApi(); - if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret)) - throw new Exception("Missing required parameters: clientId, clientSecret."); - threeLeggedApi.Configuration.AccessToken = Get2LeggedToken(clientId, clientSecret).Result.access_token; - dynamic token = await threeLeggedApi - .RefreshtokenAsync(clientId, clientSecret, "refresh_token", refreshToken, scope).ConfigureAwait(false); - var accessToken = token.access_token; - // set refresh token - var newRefreshToken = token.refresh_token; - // set value to environment variable - Environment.SetEnvironmentVariable("APS_REFRESH_TOKEN", newRefreshToken, EnvironmentVariableTarget.User); - Token newToken = new Token() - { - access_token = accessToken, - token_type = token.token_type, - expires_in = token.expires_in, - refresh_token = newRefreshToken - }; - return newToken; - } - - public static Task Refresh3LeggedToken(Scope[] scope) - { - var clientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID", EnvironmentVariableTarget.User); - var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); - var refreshToken = Environment.GetEnvironmentVariable("APS_REFRESH_TOKEN", EnvironmentVariableTarget.User); - var Leg3Token = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result; - return Task.FromResult(Leg3Token); - } -} \ No newline at end of file diff --git a/APSToolkit/BIM360/BIM360.cs b/APSToolkit/BIM360/BIM360.cs index 7f736ca..808cd45 100644 --- a/APSToolkit/BIM360/BIM360.cs +++ b/APSToolkit/BIM360/BIM360.cs @@ -1,6 +1,5 @@ using System.Data; using System.Net; -using APSToolkit.Auth; using APSToolkit.Database; using APSToolkit.Utils; using Autodesk.Forge; @@ -20,7 +19,8 @@ public class BIM360 public BIM360() { - this.Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + this.Token = auth.Get2LeggedToken().Result; } public BIM360(Token token) { @@ -55,7 +55,7 @@ public BIM360(Token token) public DynamicDictionaryItems GetHubs() { var hubsApi = new HubsApi(); - hubsApi.Configuration.AccessToken = Token.access_token; + hubsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = hubsApi.GetHubsAsync().Result; return new DynamicDictionaryItems(result.data); } @@ -90,7 +90,7 @@ public DynamicDictionaryItems GetHubs() public DynamicDictionaryItems GetProjects(string hubId) { var projectsApi = new ProjectsApi(); - projectsApi.Configuration.AccessToken = Token.access_token; + projectsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = projectsApi.GetHubProjectsAsync(hubId).Result; return new DynamicDictionaryItems(result.data); } @@ -128,7 +128,7 @@ public Dictionary GetTopFolders(string hubId, string projectId) { var folders = new Dictionary(); var projectsApi = new ProjectsApi(); - projectsApi.Configuration.AccessToken = Token.access_token; + projectsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = projectsApi.GetProjectTopFoldersAsync(hubId, projectId).Result; foreach (KeyValuePair folderInfo in new DynamicDictionaryItems(result.data)) { @@ -142,7 +142,7 @@ public Dictionary GetTopFolders(string hubId, string projectId) public (string,string) GetTopProjectFilesFolder(string hubId, string projectId) { var projectsApi = new ProjectsApi(); - projectsApi.Configuration.AccessToken = Token.access_token; + projectsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = projectsApi.GetProjectTopFoldersAsync(hubId, projectId).Result; foreach (KeyValuePair folderInfo in new DynamicDictionaryItems(result.data)) { @@ -194,7 +194,7 @@ public Dictionary GetTopFolders(string hubId, string projectId) public dynamic? GetItemByFolder(string projectId, string folderId, string fileName) { var foldersApi = new FoldersApi(); - foldersApi.Configuration.AccessToken = Token.access_token; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) { @@ -240,7 +240,7 @@ public Dictionary GetTopFolders(string hubId, string projectId) public DynamicDictionaryItems GetItemsByFolder(string projectId, string folderId) { var foldersApi = new FoldersApi(); - foldersApi.Configuration.AccessToken = Token.access_token; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; return new DynamicDictionaryItems(result.data); } @@ -285,7 +285,7 @@ public DynamicDictionaryItems GetItemsByFolder(string projectId, string folderId string TopFolderId = GetTopFolders(hubId, projectId) .FirstOrDefault(x => x.Value == "Project Files").Key; var foldersApi = new FoldersApi(); - foldersApi.Configuration.AccessToken = Token.access_token; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, TopFolderId).Result; bool isFounded = false; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) @@ -312,11 +312,12 @@ private void RecursiveFileInFolder(string projectId, string folderId, string fil { if (IsFounded && isStopFirstFind) return; var foldersApi = new FoldersApi(); - if(Token.expires_in <=0) + if(Token.ExpiresIn <=0) { - Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Token = auth.Get2LeggedToken().Result; } - foldersApi.Configuration.AccessToken = Token.access_token; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) { @@ -366,7 +367,7 @@ private void RecursiveFileInFolder(string projectId, string folderId, string fil public DynamicDictionaryItems GetItemVersions(string projectId, string itemId) { var itemsApi = new ItemsApi(); - itemsApi.Configuration.AccessToken = Token.access_token; + itemsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = itemsApi.GetItemVersionsAsync(projectId, itemId).Result; DynamicDictionaryItems dictionaryItems = new DynamicDictionaryItems(result.data); return dictionaryItems; @@ -388,7 +389,7 @@ public DynamicDictionaryItems GetItemVersions(string projectId, string itemId) public dynamic? GetLatestVersionItem( string projectId, string itemId) { var itemsApi = new ItemsApi(); - itemsApi.Configuration.AccessToken = Token.access_token; + itemsApi.Configuration.AccessToken = Token.AccessToken; dynamic result = itemsApi.GetItemVersionsAsync(projectId, itemId).Result; if(result==null) return null; return result.data[0]; @@ -402,7 +403,7 @@ public DynamicDictionaryItems GetItemVersions(string projectId, string itemId) public string CheckStatusProcessingData(string urn) { var derivativeApi = new DerivativesApi(); - derivativeApi.Configuration.AccessToken = Token.access_token; + derivativeApi.Configuration.AccessToken = Token.AccessToken; dynamic manifest = derivativeApi.GetManifestAsync(urn).Result; string status = manifest.progress; return status; @@ -473,7 +474,7 @@ public async Task UploadFileToBIM360(string projectId, string fo { string filename = Path.GetFileName(filePath); var fileMemoryStream = new MemoryStream(File.ReadAllBytes(filePath)); - string accessToken = Token.access_token; + string accessToken = Token.AccessToken; string objectStorageId = await CreateFileStorage(projectId, folderUrn, filename, accessToken).ConfigureAwait(false); ObjectDetails objectDetails = @@ -1035,7 +1036,7 @@ public RestResponse PublishModelWithoutLink(string token3Legged, string projectI var client = new RestClient(versionUrl); var request = new RestRequest(); request.Method = Method.Get; - string token3Leg = Token.access_token; + string token3Leg = Token.AccessToken; request.AddHeader("Authorization", $"Bearer {token3Leg}"); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.NotFound) @@ -1114,7 +1115,7 @@ public void ExportRevitDataToParquet(string projectId, string indexVersionId,str var client = new RestClient(versionUrl); var request = new RestRequest(); request.Method = Method.Get; - request.AddHeader("Authorization", $"Bearer + {Token.access_token}"); + request.AddHeader("Authorization", $"Bearer + {Token.AccessToken}"); var response = client.Execute(request); dynamic version = JsonConvert.DeserializeObject(response.Content); string manifestUrl = version.manifestUrl; @@ -1193,7 +1194,7 @@ public void ExportRevitDataToParquet(string projectId, string indexVersionId,str RestClient client = new RestClient(Host); RestRequest request = new RestRequest($"/construction/index/v2/projects/{projectId}/indexes:batchStatus", RestSharp.Method.Post); - string accessToken = Token.access_token; + string accessToken = Token.AccessToken; request.AddHeader("Authorization", $"Bearer {accessToken}"); var data = versionIds.Select(versionId => new @@ -1360,7 +1361,7 @@ public void ExportRevitDataToParquet(string projectId, string indexVersionId,str public async Task> GetLevelsFromAecModelData(string urn) { var derivativeApi = new DerivativesApi(); - derivativeApi.Configuration.AccessToken = Token.access_token; + derivativeApi.Configuration.AccessToken = Token.AccessToken; string aecModelDataUrn = string.Empty; var data = await derivativeApi.GetManifestAsync(urn).ConfigureAwait(false); var result = Newtonsoft.Json.JsonConvert.DeserializeObject(data.ToString()); @@ -1580,7 +1581,7 @@ public BIMData[] GetAllDataByIndexVersionId(string projectId, string indexVersio var client = new RestClient(versionUrl); var request = new RestRequest(); request.Method = Method.Get; - string accessToken = Token.access_token; + string accessToken = Token.AccessToken; request.AddHeader("Authorization", $"Bearer {accessToken}"); var response = client.Execute(request); dynamic version = JsonConvert.DeserializeObject(response.Content); @@ -1768,7 +1769,8 @@ private void BatchReportItemVersionRecursive(string projectId,string folderId,st { var foldersApi = new FoldersApi(); // refresh token - string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result.access_token; + var auth = new Auth(); + string? get2LeggedToken = auth.Get2LeggedToken().Result.AccessToken; foldersApi.Configuration.AccessToken = get2LeggedToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) @@ -1826,7 +1828,8 @@ public DataTable BatchReportItemVersions(string projectId, string itemId) dataTable.Columns.Add("LastModifiedTime", typeof(DateTime)); var itemsApi = new ItemsApi(); // refresh token - string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result.access_token; + var auth = new Auth(); + string? get2LeggedToken = auth.Get2LeggedToken().Result.AccessToken; itemsApi.Configuration.AccessToken = get2LeggedToken; dynamic result = itemsApi.GetItemVersionsAsync(projectId, itemId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) @@ -1857,7 +1860,7 @@ public void BatchExportAllRevitToExcel(string directory,string hubId,string proj (string, string) projectFilesFolder = GetTopProjectFilesFolder(hubId, projectId); string TopFolderId = projectFilesFolder.Item1; var foldersApi = new FoldersApi(); - foldersApi.Configuration.AccessToken = Token.access_token; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, TopFolderId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) { @@ -1886,8 +1889,9 @@ private void ExportRevitExcelRecursive(string directory, string projectId, strin { var foldersApi = new FoldersApi(); // refresh token - if(Token.expires_in<=0) Token = Auth.Authentication.Get2LeggedToken().Result; - foldersApi.Configuration.AccessToken = Token.access_token; + var auth = new Auth(); + if(Token.ExpiresIn<=0) Token = auth.Get2LeggedToken().Result; + foldersApi.Configuration.AccessToken = Token.AccessToken; dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) { diff --git a/APSToolkit/Database/BucketStorage.cs b/APSToolkit/Database/BucketStorage.cs index 6755370..a3a412c 100644 --- a/APSToolkit/Database/BucketStorage.cs +++ b/APSToolkit/Database/BucketStorage.cs @@ -1,6 +1,5 @@ // Copyright (c) chuongmep.com. All rights reserved -using APSToolkit.Auth; using Autodesk.Forge; using Autodesk.Forge.Model; @@ -15,7 +14,8 @@ public BucketStorage(Token token) } public BucketStorage() { - Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Token = auth.Get2LeggedToken().Result; } /// /// Creates a new bucket in Autodesk Forge Data Management service. @@ -31,7 +31,7 @@ public BucketStorage() public dynamic CreateBucket(string bucketName, string region = "US",PostBucketsPayload.PolicyKeyEnum Policy=PostBucketsPayload.PolicyKeyEnum.Transient) { BucketsApi bucketsApi = new BucketsApi(); - bucketsApi.Configuration.AccessToken = Token.access_token; + bucketsApi.Configuration.AccessToken = Token.AccessToken; PostBucketsPayload postBuckets = new PostBucketsPayload(bucketName, null, Policy); dynamic bucket = bucketsApi.CreateBucket(postBuckets, region); return bucket; @@ -52,7 +52,7 @@ public dynamic UploadFileToBucket(string bucketKey, string filePath) { // check if bucket exists BucketsApi bucketsApi = new BucketsApi(); - bucketsApi.Configuration.AccessToken = Token.access_token; + bucketsApi.Configuration.AccessToken = Token.AccessToken; dynamic buckets = bucketsApi.GetBuckets(); bool bucketExist = false; foreach (KeyValuePair bucket in new DynamicDictionaryItems(buckets.items)) @@ -68,7 +68,7 @@ public dynamic UploadFileToBucket(string bucketKey, string filePath) CreateBucket(bucketKey); } ObjectsApi objectsApi = new ObjectsApi(); - objectsApi.Configuration.AccessToken = Token.access_token; + objectsApi.Configuration.AccessToken = Token.AccessToken; dynamic file = objectsApi.UploadObject(bucketKey, Path.GetFileName(filePath), (int) new FileInfo(filePath).Length, new FileStream(filePath, FileMode.Open)); return file; @@ -87,7 +87,7 @@ public dynamic UploadFileToBucket(string bucketKey, string filePath) public MemoryStream GetFileFromBucket(string buketKey,string fileName) { ObjectsApi objectsApi = new ObjectsApi(); - objectsApi.Configuration.AccessToken = Token.access_token; + objectsApi.Configuration.AccessToken = Token.AccessToken; MemoryStream stream = objectsApi.GetObject(buketKey, fileName); return stream; } @@ -102,7 +102,7 @@ public MemoryStream GetFileFromBucket(string buketKey,string fileName) public void DeleteBucket(string bucketKey) { BucketsApi bucketsApi = new BucketsApi(); - bucketsApi.Configuration.AccessToken = Token.access_token; + bucketsApi.Configuration.AccessToken = Token.AccessToken; bucketsApi.DeleteBucket(bucketKey); } /// @@ -117,7 +117,7 @@ public void DeleteBucket(string bucketKey) public void DeleteFile(string bucketKey,string fileName) { ObjectsApi objectsApi = new ObjectsApi(); - objectsApi.Configuration.AccessToken = Token.access_token; + objectsApi.Configuration.AccessToken = Token.AccessToken; objectsApi.DeleteObject(bucketKey, fileName); } /// @@ -134,7 +134,7 @@ public void DeleteFile(string bucketKey,string fileName) public string GetFileSignedUrl(string bucketKey,string fileName) { ObjectsApi objectsApi = new ObjectsApi(); - objectsApi.Configuration.AccessToken = Token.access_token; + objectsApi.Configuration.AccessToken = Token.AccessToken; dynamic signedUrl = objectsApi.CreateSignedResource(bucketKey, fileName, new PostBucketsSigned(10)); return signedUrl.signedUrl; } diff --git a/APSToolkit/Database/DbReader.cs b/APSToolkit/Database/DbReader.cs index 9df07da..46bc6bb 100644 --- a/APSToolkit/Database/DbReader.cs +++ b/APSToolkit/Database/DbReader.cs @@ -2,7 +2,6 @@ using System.Data; using System.Data.SQLite; using System.Text; -using APSToolkit.Auth; using APSToolkit.Utils; using RestSharp; @@ -59,7 +58,7 @@ public DbReader(string? urn, Token token,bool isClearCache=true) { throw new Exception("urn require is derivative urn, not path"); } - ReadData(urn,token.access_token).Wait(); + ReadData(urn,token.AccessToken).Wait(); IsClearCache = isClearCache; } diff --git a/APSToolkit/Database/DbReaderRevit.cs b/APSToolkit/Database/DbReaderRevit.cs index 372d055..0abee6d 100644 --- a/APSToolkit/Database/DbReaderRevit.cs +++ b/APSToolkit/Database/DbReaderRevit.cs @@ -2,7 +2,6 @@ using System.Data; using System.Text.RegularExpressions; -using APSToolkit.Auth; using APSToolkit.Utils; namespace APSToolkit.Database; diff --git a/APSToolkit/Database/PropDbReader.cs b/APSToolkit/Database/PropDbReader.cs index 4de989f..d762e60 100644 --- a/APSToolkit/Database/PropDbReader.cs +++ b/APSToolkit/Database/PropDbReader.cs @@ -3,7 +3,6 @@ using System.Data; using System.Text; using System.Text.RegularExpressions; -using APSToolkit.Auth; using APSToolkit.Utils; using ICSharpCode.SharpZipLib.GZip; using Newtonsoft.Json; @@ -75,11 +74,13 @@ private static byte[] Unzip(string filePath) public PropDbReader(string urn) { this.Urn = urn; - Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Token = auth.Get2LeggedToken().Result; } public PropDbReader() { - Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Token = auth.Get2LeggedToken().Result; } /// /// Read All Information properties from urn model @@ -91,7 +92,7 @@ public PropDbReader(string urn, Token token) { this.Urn = urn; Token = token; - DownloadStreamAsync(urn, token.access_token).Wait(); + DownloadStreamAsync(urn, token.AccessToken).Wait(); } /// diff --git a/APSToolkit/Database/PropDbReaderRevit.cs b/APSToolkit/Database/PropDbReaderRevit.cs index 7b8126f..801b4d3 100644 --- a/APSToolkit/Database/PropDbReaderRevit.cs +++ b/APSToolkit/Database/PropDbReaderRevit.cs @@ -1,6 +1,5 @@ using System.Data; using System.Text.RegularExpressions; -using APSToolkit.Auth; using APSToolkit.Utils; using OfficeOpenXml; diff --git a/APSToolkit/Database/RevitDataConfiguration.cs b/APSToolkit/Database/RevitDataConfiguration.cs index 4bab628..f5b0214 100644 --- a/APSToolkit/Database/RevitDataConfiguration.cs +++ b/APSToolkit/Database/RevitDataConfiguration.cs @@ -1,5 +1,4 @@ -using APSToolkit.Auth; -using APSToolkit.Schema; +using APSToolkit.Schema; using APSToolkit.Utils; using OfficeOpenXml.Style; @@ -46,7 +45,8 @@ public RevitDataConfiguration(string urn,Token token) : this() public RevitDataConfiguration(string urn) : this() { this.Urn = urn; - this.Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + this.Token = auth.Get2LeggedToken().Result; } public void RebuildConfiguration() @@ -58,7 +58,7 @@ public void RebuildConfiguration() if (IsGetBBox) { - Dictionary svfFragments = GetFragments(Token.access_token).Result; + Dictionary svfFragments = GetFragments(Token.AccessToken).Result; Fragments = svfFragments; } } diff --git a/APSToolkit/Derivatives.cs b/APSToolkit/Derivatives.cs index d785b3f..75191e7 100644 --- a/APSToolkit/Derivatives.cs +++ b/APSToolkit/Derivatives.cs @@ -2,7 +2,6 @@ using System.IO.Compression; using System.Text.RegularExpressions; -using APSToolkit.Auth; using APSToolkit.Schema; using Autodesk.Forge; using Autodesk.Forge.Model; diff --git a/APSToolkit/DesignAutomation/DesignAutomateConfiguration.cs b/APSToolkit/DesignAutomation/DesignAutomateConfiguration.cs index 6966435..57c9ecd 100644 --- a/APSToolkit/DesignAutomation/DesignAutomateConfiguration.cs +++ b/APSToolkit/DesignAutomation/DesignAutomateConfiguration.cs @@ -1,6 +1,5 @@ // Copyright (c) chuongmep.com. All rights reserved -using APSToolkit.Auth; using Autodesk.Forge; namespace APSToolkit.DesignAutomation; @@ -40,8 +39,8 @@ public class DesignAutomateConfiguration public DesignAutomateConfiguration() { // set client id and client secret from environment variables - ClientId = Authentication.GetClientId(); - ClientSecret = Authentication.GetClientSecret(); + ClientId = new Auth().GetClientId(); + ClientSecret = new Auth().GetClientSecret(); } public DesignAutomateConfiguration(string clientId, string clientSecret) diff --git a/APSToolkit/DesignAutomation/DynamoRevitDesignAutomate.cs b/APSToolkit/DesignAutomation/DynamoRevitDesignAutomate.cs index bb7aebf..4717b6e 100644 --- a/APSToolkit/DesignAutomation/DynamoRevitDesignAutomate.cs +++ b/APSToolkit/DesignAutomation/DynamoRevitDesignAutomate.cs @@ -1,6 +1,5 @@ // Copyright (c) chuongmep.com. All rights reserved -using APSToolkit.Auth; using APSToolkit.Database; using APSToolkit.Utils; using Autodesk.Forge; @@ -332,7 +331,7 @@ private async Task ExecuteWorkItem(string token2Leg, string projectId, string projectId, string versionId) { VersionsApi versionApi = new VersionsApi(); - versionApi.Configuration.AccessToken = Authentication.Get2LeggedToken().Result.access_token; + versionApi.Configuration.AccessToken = new Auth().Get2LeggedToken().Result.AccessToken; dynamic version = await versionApi.GetVersionAsync(projectId, versionId).ConfigureAwait(false); dynamic versionItem = await versionApi.GetVersionItemAsync(projectId, versionId).ConfigureAwait(false); string modelName = version.data.attributes.name; diff --git a/APSToolkit/DesignAutomation/RevitDesignAutomate.cs b/APSToolkit/DesignAutomation/RevitDesignAutomate.cs index 2ce8238..e13e16e 100644 --- a/APSToolkit/DesignAutomation/RevitDesignAutomate.cs +++ b/APSToolkit/DesignAutomation/RevitDesignAutomate.cs @@ -1,8 +1,5 @@ // Copyright (c) chuongmep.com. All rights reserved -using System.Text; -using APSToolkit.Auth; -using APSToolkit.Utils; using Autodesk.Forge; using Autodesk.Forge.Core; using Autodesk.Forge.DesignAutomation; @@ -72,9 +69,9 @@ public RevitDesignAutomate(DesignAutomateConfiguration configuration) : this() public async Task ExecuteJob(string projectId, string versionId, string callBackUrl) { // access Token - Token token = Authentication - .Get2LeggedToken(_configuration.ClientId, _configuration.ClientSecret).Result; - string userAccessToken = token.access_token; + Token token = new Auth(_configuration.ClientId, _configuration.ClientSecret) + .Get2LeggedToken().Result; + string userAccessToken = token.AccessToken; bool isCompositeDesign = DAUtils.IsCompositeDesign(userAccessToken, projectId, versionId).Result; Console.WriteLine("Is Composite Design: " + isCompositeDesign); _configuration.Version = DAUtils.GetRevitVersionByVersionId(userAccessToken, projectId, versionId).Result; @@ -346,7 +343,7 @@ await _designAutomation.CreateActivityAliasAsync(_configuration.ActivityName, al string projectId, string versionId) { VersionsApi versionApi = new VersionsApi(); - versionApi.Configuration.AccessToken = Authentication.Get2LeggedToken().Result.access_token; + versionApi.Configuration.AccessToken = new Auth(_configuration.ClientId, _configuration.ClientSecret).Get2LeggedToken().Result.AccessToken; dynamic version = await versionApi.GetVersionAsync(projectId, versionId).ConfigureAwait(false); dynamic versionItem = await versionApi.GetVersionItemAsync(projectId, versionId).ConfigureAwait(false); string modelName = version.data.attributes.name; diff --git a/APSToolkit/Auth/Token.cs b/APSToolkit/Token.cs similarity index 55% rename from APSToolkit/Auth/Token.cs rename to APSToolkit/Token.cs index c0203f6..c783687 100644 --- a/APSToolkit/Auth/Token.cs +++ b/APSToolkit/Token.cs @@ -1,13 +1,26 @@ using Autodesk.Forge; -namespace APSToolkit.Auth; +namespace APSToolkit; public class Token { - public string access_token { get; set; } - public string token_type { get; set; } - public long expires_in { get; set; } - public string refresh_token { get; set; } + public Token(string? accessToken, string? tokenType, long expiresIn, string refreshToken) :this() + { + this.AccessToken = accessToken; + this.TokenType = tokenType; + this.ExpiresIn = expiresIn; + this.RefreshToken = refreshToken; + } + + public Token() + { + + } + + public string? AccessToken { get; set; } + public string? TokenType { get; set; } + public long? ExpiresIn { get; set; } + public string? RefreshToken { get; set; } /// /// Retrieves a 2-legged access token from the Autodesk Forge API using client credentials. @@ -16,10 +29,11 @@ public class Token /// public Token Refresh2LegToken() { - Token token = Authentication.Get2LeggedToken().Result; - this.access_token = token.access_token; - this.token_type = token.token_type; - this.expires_in = token.expires_in; + var auth = new Auth(); + Token token = auth.Get2LeggedToken().Result; + this.AccessToken = token.AccessToken; + this.TokenType = token.TokenType; + this.ExpiresIn = token.ExpiresIn; return this; } @@ -37,16 +51,16 @@ public Token Refresh3LegToken() Scope.BucketRead, Scope.CodeAll, Scope.BucketUpdate, Scope.BucketDelete }; - Token token = Authentication.Refresh3LeggedToken(scopes).Result; - this.access_token = token.access_token; - this.token_type = token.token_type; - this.expires_in = token.expires_in; - this.refresh_token = token.refresh_token; + Token token = Auth.Refresh3LeggedToken(scopes).Result; + this.AccessToken = token.AccessToken; + this.TokenType = token.TokenType; + this.ExpiresIn = token.ExpiresIn; + this.RefreshToken = token.RefreshToken; return this; } public bool IsExpired() { - bool b = this.expires_in <= 60; + bool b = this.ExpiresIn <= 60; return b; } } \ No newline at end of file diff --git a/APSToolkitUnit/AuthenticationTest.cs b/APSToolkitUnit/AuthTest.cs similarity index 73% rename from APSToolkitUnit/AuthenticationTest.cs rename to APSToolkitUnit/AuthTest.cs index 7b6904e..78af2a6 100644 --- a/APSToolkitUnit/AuthenticationTest.cs +++ b/APSToolkitUnit/AuthTest.cs @@ -1,26 +1,32 @@ using System; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using Autodesk.Forge; using NUnit.Framework; namespace ForgeToolkitUnit; -public class AuthenticationTest +public class AuthTest { private static Token Token { get; set; } - + private Auth Auth { get; set; } [SetUp] public void Setup() { - + Auth = new Auth(); } [Test] public void TestAuthentication2Leg() { - Token = Authentication.Get2LeggedToken().Result; - Assert.IsNotEmpty(Token.access_token); + Token = Auth.Get2LeggedToken().Result; + Assert.IsNotEmpty(Token.AccessToken); + } + [Test] + public void TestAuthentication3Leg() + { + Token = Auth.Get3LeggedToken().Result; + Assert.IsNotEmpty(Token.AccessToken); } [Test] @@ -34,7 +40,7 @@ public Task TestRefresh3LegToken() if (string.IsNullOrEmpty(refreshToken)) Assert.Fail("Missing APS_REFRESH_TOKEN environment variable."); Scope[] scope = new Scope[] {Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate}; - var Leg3Token = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result; + var Leg3Token = Auth.Refresh3LeggedToken(clientID, clientSecret, scope).Result; Assert.IsNotNull(Leg3Token); return Task.CompletedTask; } @@ -42,7 +48,7 @@ public Task TestRefresh3LegToken() [Test] public void TestTokenExpired() { - Token = Authentication.Get2LeggedToken().Result; + Token = Auth.Get2LeggedToken().Result; Assert.IsFalse(Token.IsExpired()); } } \ No newline at end of file diff --git a/APSToolkitUnit/BIM360Test.cs b/APSToolkitUnit/BIM360Test.cs index 9a846e4..0b66163 100644 --- a/APSToolkitUnit/BIM360Test.cs +++ b/APSToolkitUnit/BIM360Test.cs @@ -5,7 +5,7 @@ using System.Security.AccessControl; using System.Threading; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.BIM360; using APSToolkit.Database; using APSToolkit.DesignAutomation; @@ -27,7 +27,8 @@ public class BIM360Test [SetUp] public void SetUp() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] @@ -143,7 +144,8 @@ public void PipelineProcessTest(string projectId,string itemId,int version) break; } if(string.IsNullOrEmpty(urn)) Assert.Fail("Can't get urn"); - var token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + var token = auth.Get2LeggedToken().Result; PropDbReaderRevit propDbReaderRevit = new PropDbReaderRevit(urn,token); propDbReaderRevit.ExportAllDataToExcel("result.xlsx"); } @@ -172,7 +174,8 @@ public void UploadFileToBIM360Test(string projectId, string folderUrn, string fi public Task DownloadFileFromBIM360Test(string projectId, string folderUrn, string fileName) { BIM360 bim360 = new BIM360(); - string token = Authentication.Get2LeggedToken().Result.access_token; + var Auth = new Auth(); + string token = Auth.Get2LeggedToken().Result.AccessToken; string directory = "./"; Task derivativesUrn = bim360.DownloadFileFromBIM360(projectId, folderUrn, fileName, token, directory); Assert.IsNotEmpty(derivativesUrn.Result); @@ -200,7 +203,7 @@ public async Task PublishModelTest(string projectId, string itemId) var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - string forgeToken3Leg = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result.access_token; + string forgeToken3Leg = new Auth().Refresh3LeggedToken(clientID, clientSecret, scope).Result.AccessToken; RestResponse restResponse = bim360.PublishModel(forgeToken3Leg, projectId, itemId); Assert.IsTrue(restResponse.IsSuccessful); } @@ -224,7 +227,8 @@ public async Task TestDownloadExcelAndUpdateData(string projectId, string folder string modelGuid, string bundlePath, string modelName) { BIM360 bim360 = new BIM360(); - string token = Authentication.Get2LeggedToken().Result.access_token; + var Auth = new Auth(); + string token = Auth.Get2LeggedToken().Result.AccessToken; string directory = "./"; Task filePath = bim360.DownloadFileFromBIM360(projectId, folderUrn, fileName, token, directory); Assert.IsNotEmpty(filePath.Result); @@ -259,7 +263,7 @@ public async Task TestDownloadExcelAndUpdateData(string projectId, string folder var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - string forgeToken3Leg = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result.access_token; + string forgeToken3Leg = Auth.Refresh3LeggedToken(clientID, clientSecret, scope).Result.AccessToken; if (string.IsNullOrEmpty(forgeToken3Leg)) Assert.Fail("Can't use forgeToken3Leg ."); Status executeJob = await revitExtractDataAutomate.ExecuteJob(token, forgeToken3Leg, readParams, inputParams, @@ -276,7 +280,7 @@ public void TestGetAllDataOriginalProperties(string projectId,string indexVersio { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); List allProperties = bim360.GetAllDataOriginalProperties(projectId,indexVersionId); Assert.IsNotEmpty(allProperties); @@ -287,7 +291,7 @@ public void TestGetAllDataByIndexVersionId(string projectId,string indexId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); BIMData[] allProperties = bim360.GetAllDataByIndexVersionId(projectId,indexId); Assert.IsNotEmpty(allProperties); @@ -298,7 +302,7 @@ public void TestGetAllDataByVersionId(string projectId,string versionId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); BIMData[] bimDatas = bim360.GetAllDataByVersionId(projectId,versionId); BIMData bimData = bimDatas.FirstOrDefault(x => x.externalId == "5bb069ca-e4fe-4e63-be31-f8ac44e80d30-000471ee"); @@ -313,7 +317,7 @@ public void BimDataToDataTableTest(string projectId,string versionId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); BIMData[] bimDatas = bim360.GetAllDataByVersionId(projectId,versionId); DataTable dataTable = bim360.BimDataToDataTable(bimDatas); @@ -327,7 +331,7 @@ public void TestBuildPropertyIndexesAsync(string projectId,string urnVersionId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); List versions = new List() { urnVersionId }; var result = bim360.BuildPropertyIndexesAsync(projectId,versions).Result; @@ -356,7 +360,7 @@ public void TestGetPropertyIndexesStatusAsync(string projectId,string indexId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); var result = bim360.GetPropertyIndexesStatusAsync(projectId,indexId).Result; Assert.IsNotEmpty(result); @@ -367,7 +371,7 @@ public void TestGetPropertyIndexesManifestAsync(string projectId,string indexId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); var result = bim360.GetPropertyIndexesManifestAsync(projectId,indexId).Result; Assert.IsNotEmpty(result); @@ -378,7 +382,7 @@ public void TestGetPropertyFieldsAsync(string projectId,string indexId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); var result = bim360.GetPropertyFieldsAsync(projectId,indexId).Result; Assert.IsNotEmpty(result); @@ -389,7 +393,7 @@ public void TestGetPropertiesResultsAsync(string projectId,string indexId) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); List result = bim360.GetPropertiesResultsAsync(projectId,indexId).Result; Assert.IsNotEmpty(result); @@ -400,7 +404,7 @@ public void ExportRevitDataToParquet(string projectId,string indexId,string file { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); bim360.ExportRevitDataToParquet(projectId,indexId,filePath); } @@ -410,7 +414,7 @@ public void TestGetLevelsFromAecModelData(string urn) { Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - var token3Leg = Authentication.Refresh3LeggedToken(scope).Result; + var token3Leg = Auth.Refresh3LeggedToken(scope).Result; BIM360 bim360 = new BIM360(token3Leg); List result = bim360.GetLevelsFromAecModelData(urn).Result; Assert.IsNotEmpty(result); diff --git a/APSToolkitUnit/BucketTest.cs b/APSToolkitUnit/BucketTest.cs index aeb7d71..b0ba1df 100644 --- a/APSToolkitUnit/BucketTest.cs +++ b/APSToolkitUnit/BucketTest.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.Database; using Autodesk.Forge.Model; using NUnit.Framework; @@ -12,7 +12,8 @@ public class BucketTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] [TestCase("test_data")] diff --git a/APSToolkitUnit/CompareTest.cs b/APSToolkitUnit/CompareTest.cs index 342cb1f..001f4ef 100644 --- a/APSToolkitUnit/CompareTest.cs +++ b/APSToolkitUnit/CompareTest.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text.Json.JsonDiffPatch; using System.Text.Json.Nodes; -using APSToolkit.Auth; +using APSToolkit; using Newtonsoft.Json; using NUnit.Framework; @@ -14,7 +14,8 @@ public class CompareTest [SetUp] public void SetUp() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] diff --git a/APSToolkitUnit/DBReaderRevitTest.cs b/APSToolkitUnit/DBReaderRevitTest.cs index d9cd47a..fcdf7e9 100644 --- a/APSToolkitUnit/DBReaderRevitTest.cs +++ b/APSToolkitUnit/DBReaderRevitTest.cs @@ -2,7 +2,7 @@ using System.Data; using System.Linq; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.Database; using APSToolkit.Utils; using NUnit.Framework; @@ -15,7 +15,8 @@ public class DbReaderRevitTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] diff --git a/APSToolkitUnit/DataFrameTest.cs b/APSToolkitUnit/DataFrameTest.cs index 18c2c28..faa4a91 100644 --- a/APSToolkitUnit/DataFrameTest.cs +++ b/APSToolkitUnit/DataFrameTest.cs @@ -1,6 +1,5 @@ using System.Data; using System.Data.Common; -using APSToolkit.Auth; using APSToolkit.Utils; using Microsoft.Data.Analysis; using NUnit.Framework; diff --git a/APSToolkitUnit/DbReaderTest.cs b/APSToolkitUnit/DbReaderTest.cs index aae2856..02d862e 100644 --- a/APSToolkitUnit/DbReaderTest.cs +++ b/APSToolkitUnit/DbReaderTest.cs @@ -2,7 +2,7 @@ using System.Data; using System.Linq; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.Database; using APSToolkit.Utils; using NUnit.Framework; @@ -16,7 +16,8 @@ public class DbReaderTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; DbReader = new DbReader(Settings._RevitTestUrn, Settings.Token2Leg); } diff --git a/APSToolkitUnit/DerivativeTest.cs b/APSToolkitUnit/DerivativeTest.cs index dc6663b..b994c5f 100644 --- a/APSToolkitUnit/DerivativeTest.cs +++ b/APSToolkitUnit/DerivativeTest.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using APSToolkit; -using APSToolkit.Auth; using NUnit.Framework; namespace ForgeToolkitUnit @@ -12,7 +11,8 @@ public class DerivativeTest [SetUp] public void SetUp() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } /// @@ -30,7 +30,7 @@ public async Task TestDownloadSVF(string urn, string folder) } Console.WriteLine("Start check data process export svf"); - await Derivatives.SaveFileSvfAsync(folder, urn, Settings.Token2Leg.access_token); + await Derivatives.SaveFileSvfAsync(folder, urn, Settings.Token2Leg.AccessToken); Console.WriteLine("Done process save data svf"); // check size fodler > 0 Assert.IsTrue(System.IO.Directory.GetFiles(folder).Length > 0); diff --git a/APSToolkitUnit/DesignAutomationTest.cs b/APSToolkitUnit/DesignAutomationTest.cs index fc40e2d..b3f086a 100644 --- a/APSToolkitUnit/DesignAutomationTest.cs +++ b/APSToolkitUnit/DesignAutomationTest.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using System.IO; using System.Threading.Tasks; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.DesignAutomation; using Autodesk.Forge; using Autodesk.Forge.DesignAutomation.Model; @@ -21,7 +20,7 @@ public class DesignAutomationTest [SetUp] public void Setup() { - Token = Authentication.Get2LeggedToken().Result; + Token = new Auth().Get2LeggedToken().Result; } [TestCase("b.ca790fb5-141d-4ad5-b411-0461af2e9748", "urn:adsk.wipprod:fs.file:vf.HX2O7xKUQfukJ_hgHsrX_A", 35, 35)] @@ -93,13 +92,13 @@ public async Task SetDataParametersTest(string projectGuid, string modelGuid, st }; Token token = - Authentication.Get2LeggedToken(configuration.ClientId, configuration.ClientSecret).Result; - string forgeToken2Leg = token.access_token; + new Auth(configuration.ClientId, configuration.ClientSecret).Get2LeggedToken().Result; + string forgeToken2Leg = token.AccessToken; var clientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID", EnvironmentVariableTarget.User); var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - string forgeToken3Leg = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result.access_token; + string forgeToken3Leg = new Auth(configuration.ClientId, configuration.ClientSecret).Refresh3LeggedToken(clientID, clientSecret, scope).Result.AccessToken; if (string.IsNullOrEmpty(forgeToken3Leg)) Assert.Fail("Can't use forgeToken3Leg ."); Status executeJob = await revitExtractDataAutomate.ExecuteJob(forgeToken2Leg, forgeToken3Leg, paramsList, inputParams, @@ -131,13 +130,13 @@ public async Task DynamoDesignAutomationTest(string projectId, string versionId) }; DynamoRevitDesignAutomate dynamoRevitDesignAutomate = new DynamoRevitDesignAutomate(configuration); Token token = - Authentication.Get2LeggedToken(configuration.ClientId, configuration.ClientSecret).Result; - string forgeToken2Leg = token.access_token; + new Auth(configuration.ClientId, configuration.ClientSecret).Get2LeggedToken().Result; + string forgeToken2Leg = token.AccessToken; var clientID = Environment.GetEnvironmentVariable("APS_CLIENT_ID", EnvironmentVariableTarget.User); var clientSecret = Environment.GetEnvironmentVariable("APS_CLIENT_SECRET", EnvironmentVariableTarget.User); Scope[] scope = new Scope[] { Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.BucketRead, Scope.BucketCreate, Scope.CodeAll }; - string forgeToken3Leg = Authentication.Refresh3LeggedToken(clientID, clientSecret, scope).Result.access_token; + string forgeToken3Leg = new Auth(configuration.ClientId, configuration.ClientSecret).Refresh3LeggedToken(clientID, clientSecret, scope).Result.AccessToken; if (string.IsNullOrEmpty(forgeToken3Leg)) Assert.Fail("Can't use forgeToken3Leg ."); Status executeJob = await dynamoRevitDesignAutomate.ExecuteJob(forgeToken2Leg, projectId, versionId, diff --git a/APSToolkitUnit/FragmentsTest.cs b/APSToolkitUnit/FragmentsTest.cs index ed07c51..b21e1a8 100644 --- a/APSToolkitUnit/FragmentsTest.cs +++ b/APSToolkitUnit/FragmentsTest.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Threading.Tasks; using APSToolkit; -using APSToolkit.Auth; using APSToolkit.Schema; using Newtonsoft.Json; using NUnit.Framework; @@ -11,11 +10,11 @@ namespace ForgeToolkitUnit; public class FragmentsTest { - public static string Token { get; set; } [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } /// @@ -26,7 +25,7 @@ public void Setup() [TestCase(Settings._RevitTestUrn)] public async Task TestGetFragments(string urn) { - var fragments = await Derivatives.ReadFragmentsRemoteAsync(urn, Settings.Token2Leg.access_token); + var fragments = await Derivatives.ReadFragmentsRemoteAsync(urn, Settings.Token2Leg.AccessToken); Assert.AreNotEqual(0, fragments.Count); } @@ -34,7 +33,7 @@ public async Task TestGetFragments(string urn) [TestCase(Settings._RevitTestUrn)] public async Task GetElementLocation(string urn) { - Dictionary fragments = await Derivatives.ReadFragmentsRemoteAsync(urn, Settings.Token2Leg.access_token); + Dictionary fragments = await Derivatives.ReadFragmentsRemoteAsync(urn, Settings.Token2Leg.AccessToken); // flatten the fragments to list of svf fragments List svfFragments = fragments.Values.SelectMany(x => x).ToList(); // save to location with unique dbid and value @@ -55,7 +54,7 @@ public async Task GetElementLocation(string urn) [TestCase(Settings._RevitTestUrn)] public async Task GetElementGeometry(string urn) { - Dictionary fragments = await Derivatives.ReadGeometriesRemoteAsync(urn, Settings.Token2Leg.access_token); + Dictionary fragments = await Derivatives.ReadGeometriesRemoteAsync(urn, Settings.Token2Leg.AccessToken); // flatten the fragments to list of svf fragments List svfFragments = fragments.Values.SelectMany(x => x).ToList(); // save to location with unique dbid and value @@ -76,7 +75,7 @@ public async Task GetElementGeometry(string urn) [TestCase("dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLm84d0tfSUNjUlphcHlhbUp5MmtFVmc_dmVyc2lvbj03")] public async Task TestGetBoundingBoxByFragment(string urn) { - Dictionary fragments = await Derivatives.ReadFragmentsRemoteAsync(urn,Settings. Token2Leg.access_token); + Dictionary fragments = await Derivatives.ReadFragmentsRemoteAsync(urn,Settings. Token2Leg.AccessToken); string phase = fragments.Keys.FirstOrDefault(x => x.Contains("New Construction")); ISvfFragment[] svfFragments = fragments[phase]; ISvfFragment[] array = svfFragments.Where(x => x.dbID == 17778).ToArray(); diff --git a/APSToolkitUnit/ProbDbReaderRevitTest.cs b/APSToolkitUnit/ProbDbReaderRevitTest.cs index f6c433e..3ba0d5e 100644 --- a/APSToolkitUnit/ProbDbReaderRevitTest.cs +++ b/APSToolkitUnit/ProbDbReaderRevitTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.Database; using APSToolkit.Utils; using NUnit.Framework; @@ -16,7 +16,8 @@ public class ProbDbReaderRevitTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; var watch = System.Diagnostics.Stopwatch.StartNew(); string ids ="Resources/objects_ids.json.gz"; string offsets = "Resources/objects_offs.json.gz"; diff --git a/APSToolkitUnit/ProbDbReaderTest.cs b/APSToolkitUnit/ProbDbReaderTest.cs index ac12f11..baf197b 100644 --- a/APSToolkitUnit/ProbDbReaderTest.cs +++ b/APSToolkitUnit/ProbDbReaderTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; -using APSToolkit.Auth; +using APSToolkit; using APSToolkit.Database; using APSToolkit.Utils; using Newtonsoft.Json; @@ -17,7 +17,8 @@ public class ProbDbReaderTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; // start wath time var watch = System.Diagnostics.Stopwatch.StartNew(); // PropDbReader = new PropDbReader(Settings._RevitUrn, Settings.Token2Leg); diff --git a/APSToolkitUnit/Settings.cs b/APSToolkitUnit/Settings.cs index 339e602..3bff249 100644 --- a/APSToolkitUnit/Settings.cs +++ b/APSToolkitUnit/Settings.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using APSToolkit.Auth; +using APSToolkit; namespace ForgeToolkitUnit; diff --git a/APSToolkitUnit/SvfReaderTest.cs b/APSToolkitUnit/SvfReaderTest.cs index e515a16..20bfea8 100644 --- a/APSToolkitUnit/SvfReaderTest.cs +++ b/APSToolkitUnit/SvfReaderTest.cs @@ -1,5 +1,4 @@ using APSToolkit; -using APSToolkit.Auth; using APSToolkit.Schema; using APSToolkit.Utils; using NUnit.Framework; @@ -11,7 +10,8 @@ public class SvfReaderTest [SetUp] public void Setup() { - Settings.Token2Leg = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] diff --git a/APSToolkitUnit/VersionTest.cs b/APSToolkitUnit/VersionTest.cs index b6573f2..3be9788 100644 --- a/APSToolkitUnit/VersionTest.cs +++ b/APSToolkitUnit/VersionTest.cs @@ -1,4 +1,4 @@ -using APSToolkit.Auth; +using APSToolkit; using Autodesk.Forge; using NUnit.Framework; @@ -10,7 +10,8 @@ public class VersionTest [SetUp] public void Setup() { - Token = Authentication.Get2LeggedToken().Result; + var auth = new Auth(); + Settings.Token2Leg = auth.Get2LeggedToken().Result; } [Test] @@ -19,9 +20,9 @@ public void Setup() public void TestGetInfoVersion(string projectId,string itemid) { VersionsApi versionsApi = new VersionsApi(); - versionsApi.Configuration.AccessToken = Token.access_token; + versionsApi.Configuration.AccessToken = Token.AccessToken; ItemsApi itemsApi = new ItemsApi(); - itemsApi.Configuration.AccessToken = Token.access_token; + itemsApi.Configuration.AccessToken = Token.AccessToken; dynamic versions = itemsApi.GetItemVersions(projectId, itemid); string versionId = versions.data[0].id; var version = versionsApi.GetVersion(projectId, versionId);