public void ClientCredentialsGrantType_LoginTest() { try { ClientSecrets clientSecrets = new ClientSecrets { ApiKey = RestApiTests.ClientId, ApiSecret = RestApiTests.ClientSecret, OAuthTokenEndPoint = RestApiTests.OAuthServerTokenEndPoint, BaseUrl = RestApiTests.VaultApiBaseUrl, ApiVersion = RestApiTests.ApiVersion, CustomerAlias = RestApiTests.CustomerAlias, DatabaseAlias = RestApiTests.DatabaseAlias, Scope = RestApiTests.Scope }; VaultApi vaultApi = new VaultApi(clientSecrets); Assert.IsNotNull(vaultApi); } catch (Exception ex) { string test = ex.Message; } }
/// <summary> /// Creates a VaultApi helper object which will make HTTP API calls using the provided client application/developer credentials. /// (OAuth2 protocol Client Credentials Grant Type) /// </summary> public VaultApi(ClientSecrets clientSecrets, string userName, string password) { this.ApiTokens = HttpHelper.GetAccessToken(clientSecrets.OAuthTokenEndPoint, clientSecrets.ApiKey, clientSecrets.ApiSecret, userName, password); if (!string.IsNullOrEmpty(this.ApiTokens.AccessToken)) { this.ClientSecrets = clientSecrets; this.Files = new FilesManager(this); } }
/// <summary> /// Populates the token /// </summary> /// <param name="clientSecrets"></param> /// <param name="apiTokens"> </param> internal void Populate(ClientSecrets clientSecrets, Tokens apiTokens) { this.ClientSecrets = clientSecrets; this.ApiTokens = apiTokens; }
public void GetDocumentRevisionFile() { try { ClientSecrets clientSecrets = new ClientSecrets { ApiKey = RestApiTests.ClientId, ApiSecret = RestApiTests.ClientSecret, OAuthTokenEndPoint = RestApiTests.OAuthServerTokenEndPoint, BaseUrl = RestApiTests.VaultApiBaseUrl, ApiVersion = RestApiTests.ApiVersion, CustomerAlias = RestApiTests.CustomerAlias, DatabaseAlias = RestApiTests.DatabaseAlias, Scope = RestApiTests.Scope }; VaultApi vaultApi = new VaultApi(clientSecrets); Assert.IsNotNull(vaultApi); Guid fileId = new Guid("8d57c716-40e5-e411-beee-93df0d4ae3b6"); string filePath = string.Format(@"C:\Users\tod.olsen\Downloads\{0}", "test2.docx"); File.Delete(filePath); using (Stream stream = vaultApi.Files.GetStream(fileId)) using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write)) { int count = 0; do { byte[] buf = new byte[102400]; count = stream.Read(buf, 0, 102400); fs.Write(buf, 0, count); } while (count > 0); } } catch (Exception ex) { string message = ex.Message; } }