/// <summary>Sign into Acronis Cloud API</summary> /// <param name="username">Acronis Cloud Username. MFA has to be disabled.</param> /// <param name="password">Acronis Cloud Password.</param> public async Task Authenticate(string username, string password) { // Get tenant URI _baseTenantUri = await GetAcronisTenantUri(username); // Instantiate rest client _client = new RestClient(_baseTenantUri) { Authenticator = new AcronisAPIAuthenticator(username, password, _baseTenantUri), Encoding = Encoding.UTF8, Timeout = ApiTimeout, }; _client.UseNewtonsoftJson(); // Instantiate propertys _updateTenants = new ConcurrentBag <APITenant>(); _updateTenantsMaxDepth = 0; _signedInUser = await GetUser(); _signedInTenant = await GetTenant(SignedInUser.TenantID); _signedInTenant.TenantUsers = await GetUsersForTenant(SignedInUser.TenantID); _authToken = ((IAcronisAuthenticator)_client.Authenticator).AuthToken; _authenticated = true; _log.LogDebug($"Signed in as login {SignedInUser.UserName} with e-mail {SignedInUser.Email} "); _log.LogDebug($"Sign in tenant: {SignedInTenant.Name} ({SignedInTenant.TenantKind})"); }
public async Task <APITenant> GetTenant(Guid tenantGuid) { var request = new RestRequest($"api/2/tenants/{tenantGuid}", Method.GET); var response = await _client.ExecuteAsync(request); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception($"Error - Received HTTP {response.StatusCode}:{response.StatusDescription}. Response content: {response.Content}"); } JObject responseJson = JObject.Parse(response.Content); var tenant = new APITenant(); tenant.TenantID = new Guid(responseJson.Value <string>("id")); tenant.Name = responseJson.Value <string>("name") ?? string.Empty; tenant.TenantKind = responseJson.Value <string>("kind") ?? string.Empty; tenant.ParentTenantID = new Guid(responseJson.Value <string>("parent_id")); tenant.ParentTenantName = string.Empty; return(tenant); }