private bool Authenticate() { XmppAuthenticator authenticator = null; bool result = false; try { authenticator = CreateAuthenticator(); if (authenticator != null) { authenticator.Authenticate(); if (authenticator.AuthenticationFailed) { if (AuthenticationFailiure != null) { AuthenticationFailiure(this, new XmppAuthenticationFailiureEventArgs( authenticator.AuthenticationError)); } } result = !authenticator.AuthenticationFailed; } else { if (AuthenticationFailiure != null) { AuthenticationFailiure(this, new XmppAuthenticationFailiureEventArgs( "No valid authentication mechanism found.")); } else { throw new XmppException("No valid authentication mechanism found."); } } } catch { throw; } finally { if (authenticator != null) { authenticator.Dispose(); authenticator = null; } } return(result); }
/// <summary> /// Creates an instance of the <see cref = "XmppAuthenticator" /> used by the connection. /// </summary> /// <returns></returns> private XmppAuthenticator CreateAuthenticator() { XmppAuthenticator authenticator = null; if (SupportsFeature(XmppStreamFeatures.SaslDigestMD5)) { authenticator = new XmppSaslDigestAuthenticator(this); } else if (SupportsFeature(XmppStreamFeatures.XGoogleToken)) { authenticator = new XmppSaslXGoogleTokenAuthenticator(this); } else if (SupportsFeature(XmppStreamFeatures.SaslPlain)) { authenticator = new XmppSaslPlainAuthenticator(this); } return(authenticator); }