// New v33 public async Task<string> GetUserToken() { requestUserTokenRequest rutin = new requestUserTokenRequest(); rutin.username = App.pd.plUserName; rutin.password = App.pd.plPassword; requestUserTokenResponse rutout = new requestUserTokenResponse(); try { SetPLEndpointAddress(App.pl); //read the configured endpoint address if(App.BlockWebServices) throw new Exception(PHONY_COMMUNICATIONS_EXCEPTION); rutout = await App.pl.requestUserTokenAsync(rutin); } catch (Exception e) { return "ERROR: " + e.Message; } if (rutout.errorCode != 0)// was v33: if (rutout.errorCode != "0") return PackageErrorString(rutout.errorCode.ToString(), rutout.errorMessage); // was v33: rutout.errorCode, ... return ChangeToErrorIfNull(rutout.token); }
// See also GetUserToken() above /// <summary> /// Verifies PL credentials. If successful, also sets App.pd.plToken /// </summary> /// <returns>Error message or empty string</returns> public async Task<string> VerifyPLCredentials(string username, string password, bool hospitalStaffOrAdminOnly) { string errorCode = ""; string errorMessage = ""; string exceptionMessage = ""; // was before PLUS v33: //bool valid = false; //checkUserAuthHospitalRequest cuahin = new checkUserAuthHospitalRequest(); //checkUserAuthHospitalResponse cuahout = new checkUserAuthHospitalResponse(); //checkUserAuthRequest cuain = new checkUserAuthRequest(); //checkUserAuthResponse cuaout = new checkUserAuthResponse(); requestUserTokenRequest rutin = new requestUserTokenRequest(); requestUserTokenResponse rutout = new requestUserTokenResponse(); try { SetPLEndpointAddress(App.pl); //read the configured endpoint address if(App.BlockWebServices) throw new Exception(PHONY_COMMUNICATIONS_EXCEPTION); #if v32_OR_EARLIER if (hospitalStaffOrAdminOnly) { cuahin.username = username; cuahin.password = password; cuahout = await App.pl.checkUserAuthHospitalAsync(cuahin); valid = cuahout.valid; errorCode = cuahout.errorCode; errorMessage = cuahout.errorMessage; } else { cuain.username = username; cuain.password = password; cuaout = await App.pl.checkUserAuthAsync(cuain); valid = cuaout.valid; errorCode = cuaout.errorCode; errorMessage = cuaout.errorMessage; } #endif rutin.username = username; rutin.password = password; rutout = await App.pl.requestUserTokenAsync(rutin); // Do below, only if successful: App.pd.plToken = rutout.token; //MAYBE TO DO AS NEEDED: groupIdPL = rutout.groupIdPL; errorCode = rutout.errorCode.ToString(); // v33: was rutout.errorCode errorMessage = rutout.errorMessage; } catch (Exception e) { // Can't await (e.g., for MessageDialog) in catch, so just format string here. exceptionMessage = "ERROR - Technical details:\n" + e.Message + "\n"; // Typical if web services are down, or value in OtherSettings.xml is wrong: // "There was no endpoint listening at https://plbreak.nlm.nih.gov/?wsdl&api=1.9.6 that could accept the message. // This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details." if (e.InnerException != null && e.InnerException.Message != null && e.InnerException.Message.Length > 0) exceptionMessage += "More Technical Details (from Inner Exception):\n" + e.InnerException.Message + "\n"; } if (exceptionMessage.Length > 0) { // Caution: code elsewhere looks for "COMMUNICATIONS ERROR:" prefix. if (exceptionMessage.Contains("403")) { // New v33 exception seen - // Outer exception message: The HTTP request was forbidden with client authentication scheme 'Anonymous'. // Inner exception message: The remote server returned an error: (403) Forbidden. errorMessage = "COMMUNICATIONS ERROR: When trying to authenticate TriageTrak credentials.\n\n" + "You are currently forbidden access to TriageTrak web services.\n" + "Most likely this is due to too many bad login attempts recently from this device.\n" + "To regain access in a timely manner, ask your TriageTrak administrator to\n" + "remove this device's IP address from the 'banned' list.\n\n" + "Want to see additional technical details?\n"; // We could try to look up the IP address here, using one of techniques as given in: // http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c // http://stackoverflow.com/questions/4566403/how-to-get-internet-ip-address-from-c-sharp-windows-app?lq=1 // Or maybe there needs to be a TriageTrak web service for this? } else { errorMessage = "COMMUNICATIONS ERROR: When trying to authenticate TriageTrak credentials.\n\n" + "Possible general causes:\n" + "No wireless/wired network connection, TriageTrak web site is down, TriageTrak web services are disabled, or\n" + "there is a wrong value in the OtherSetting.xml file.\n\n" + "Want to see additional technical details?\n"; } bool showMore = false; var md = new MessageDialog(errorMessage); md.Commands.Add(new UICommand("Yes", (UICommandInvokedHandler) => { showMore = true; })); md.Commands.Add(new UICommand("No")); md.DefaultCommandIndex = 1; // No await md.ShowAsync(); if (showMore) { var dlg = new MessageDialog(exceptionMessage); await dlg.ShowAsync(); } return errorMessage + exceptionMessage; } if (errorCode != "0") // was before v33: || !valid) return PackageErrorString(errorCode, errorMessage); App.pd.plToken = rutout.token; App.MyAssert(App.pd.plToken != null && App.pd.plToken.Length == 128); // Check added for Release 6, after seeing PLUS service problems. Token is 128 char long SHA-512 //MAYBE TO DO AS NEEDED: groupIdPL = rutout.groupIdPL; return ""; }