public Stream AuthenticateUser(string userName, string password, string userData) { try { string authentication = _addin.AuthenticateUser(userName, password, userData); if (null != WebOperationContext.Current) { WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; } if (!string.IsNullOrEmpty(authentication)) { return(new MemoryStream(ASCIIEncoding.Default.GetBytes(authentication))); } } catch (Exception ex) { ServiceUtils.Log(ex.Message); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json"; if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { string errorMessage = ex.Message; errorMessage = errorMessage.Replace("\r\n", " "); WebOperationContext.Current.OutgoingResponse.StatusDescription = errorMessage; // "Yellow Error"; // ex.Message; } throw new WebFaultException(System.Net.HttpStatusCode.Unused); } ServiceUtils.Log("Invalid User Name or Password"); throw new ServiceAuthenticationException("Invalid User Name or Password"); }
public string AuthenticateUser(string userName, string password, string userData, TimeSpan?lifeTime, string impersonatedUser) { var cookie = ""; if (lifeTime.HasValue) { cookie = _auth.AuthenticateUser(userName, password, userData, lifeTime.Value, impersonatedUser); } else { cookie = _auth.AuthenticateUser(userName, password, userData); } if (string.IsNullOrEmpty(cookie)) { throw new Exception("Invalid User Name or Password"); } return(cookie); }