public bool RequestAuthorisation(string UserName, SecureString Password) { bool loggedIn = false; HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(Properties.Settings.Default.CycliUrl) }; httpClient.Timeout = new TimeSpan(0, 0, 0, 15, 0); UserCredentials u = new UserCredentials(); // ############ DEBUG /////// u.username = UserName; u.password = ConvertToUnsecureString(Password); Console.WriteLine("Authorising " + u.username); try { // Getting the lease will kick off a recipient process at the server var response = httpClient.PostAsJsonAsync<UserCredentials>("api/credential/CheckUser/", u).Result; if (response.StatusCode == HttpStatusCode.OK) { loggedIn = response.Content.ReadAsAsync<bool>().Result; } } catch (Exception ex) { Console.WriteLine("Authorising " + u.username + "Connection failed"); } return loggedIn; }
public void RequestLease(string UserName, SecureString Password) { // Danger here! It might be possible to kick off multiple // Lease requests before the server has time to respond // This way to disaster! // This monitor will prevent multiple calls by passing // through if we're already requesting a lease if (Monitor.TryEnter(_outputDatum)) { HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(Properties.Settings.Default.CycliUrl) }; UserCredentials u = new UserCredentials(); // ############ DEBUG /////// u.username = UserName; u.password = ConvertToUnsecureString(Password); Console.WriteLine("Authorising " + u.username); // Getting the lease will kick off a recipient process at the server var response = httpClient.PostAsJsonAsync<UserCredentials>("api/credential/getlease/", u) .ContinueWith(p => LeaseReceived(p.Result), System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted); } }