public AuthResponse AccountAuth(AuthRequest request) { return(base.Channel.AccountAuth(request)); }
public string Authenticate(string UserName, string Password, bool IsAdmin = false) { try { //configuration.Server.UserName = UserName; //configuration.Server.Password = Password; //configuration.Server.IsAdmin = IsAdmin; string AuthToken = string.Empty; if (IsAdmin) { //ZimbraEndpointAddress.ZimbraHeaderContext = new ZimbraHeaderContext(); Zimbra.Administration.AuthResponse response; if (administration == null) { administration = new ZimbraAdminSoapClient(binding, remoteAddressAdmin); } NoOpResponse noop = new NoOpResponse(); if (!string.IsNullOrWhiteSpace(ZimbraEndpointAddress.ZimbraHeaderContext.authToken)) { noop = administration.NoOpRequest(new NoOpRequest { }); } if (noop != null) { noop.Dispose(); } if (string.IsNullOrWhiteSpace(ZimbraEndpointAddress.ZimbraHeaderContext.authToken)) { Zimbra.Administration.AuthRequest request = new Administration.AuthRequest { account = new Global.accountSelector { by = Global.accountBy.AdministratorName, Value = UserName }, password = Password, persistAuthTokenCookie = true }; response = administration.AccountAuth(request); if (!string.IsNullOrEmpty(response.authToken)) { ZimbraEndpointAddress.ZimbraHeaderContext.authToken = response.authToken; ZimbraEndpointAddress.ZimbraHeaderContext.AuthTokenControl = new authTokenControl { voidOnExpired = true }; ZimbraEndpointAddress.ZimbraHeaderContext.account = request.account.Value; //ZimbraEndpointAddress.ZimbraHeaderContext.account.by = accountBy.name; AuthenticatedAdminLifetime = response.lifetime; AuthenticatedAdmin = true; AuthToken = response.authToken; } } } else { //ZimbraEndpointAddress.ZimbraHeaderContext = new ZimbraHeaderContext(); Zimbra.Account.AuthResponse response; if (account == null) { account = new ZimbraAccountSoapClient(binding, remoteAddress); } Zimbra.Account.AuthRequest request = new Account.AuthRequest { account = new Global.accountSelector { by = Global.accountBy.Name, Value = UserName }, password = Password, persistAuthTokenCookie = true }; response = account.AccountAuth(request); if (!string.IsNullOrEmpty(response.authToken)) { AuthenticatedLifetime = response.lifetime; Authenticated = true; AuthToken = response.authToken; } //ZimbraEndpointAddress.ZimbraHeaderContext.authToken = response.authToken; //ZimbraEndpointAddress.ZimbraHeaderContext.AuthTokenControl = new authTokenControl { voidOnExpired = true }; //ZimbraEndpointAddress.ZimbraHeaderContext.account = request.account.Value; } //GetVersioInfo(asAdmin); return(AuthToken); } catch (Exception ex) { HttpRuntime.UnloadAppDomain(); Thread.Sleep(100); throw ex; } }