/// <summary> /// Logs in using ASE credentials provided in the constructor. /// </summary> /// <returns>Token for use in further calls to the API.</returns> void Login() { NameValuePairs nv = new NameValuePairs(); nv.Add("userId", Username); nv.Add("password", StringUtils.GetUnsecureString(Password)); nv.Add("featureKey", DEFAULT_FEATUREKEY); try { HttpResponseMessage response = Post("login", nv.ToJson()).GetAwaiter().GetResult(); Dictionary <string, dynamic> ret = GenericJsonParse(response); Client.DefaultRequestHeaders.TryAddWithoutValidation(TOKEN_NAME, ret["sessionId"]); Log.Debug(String.Format("Successfully logged into ASE as {1}: {0}", ret["sessionId"], Username)); }catch (Exception e) { Log.Error(String.Format("Failed to login to ASE as {0}: {1}", Username, e.Message), e); throw e; }finally { nv = null; //clean up values from memory. } }
public async Task <List <ScanFinding> > GetScans(Application application) { Login(); NameValuePairs nv = new NameValuePairs(); nv.Add("query", WebUtility.UrlEncode(String.Format("Application Name={0}", application.name))); HttpResponseMessage response = await Get("issues", nv); string json = await response.Content.ReadAsStringAsync(); Log.Debug(String.Format("Received JSON: {0}", json)); Logout(); return(JsonConvert.DeserializeObject <List <ScanFinding> >(json)); }
public async Task <List <Application> > GetApplications() { Login(); NameValuePairs nv = new NameValuePairs(); nv.Add("columns", WebUtility.UrlEncode("name,url")); HttpResponseMessage response = await Get("applications", nv); string json = await response.Content.ReadAsStringAsync(); Log.Debug(String.Format("Received JSON: {0}", json)); Logout(); return(JsonConvert.DeserializeObject <List <Application> >(json)); }