示例#1
0
        public void LoginAnonymously()
        {
            //FF

            /*
             * Debug.Assert(User != null, "Username must not be null for XEP-78 authentication");
             * Debug.Assert(Password != null, "Password must not be null for XEP-78 authentication");
             * Debug.Assert(Resource != null, "Resource must not be null for XEP-78 authentication");
             * //*/
            this[Options.AUTO_LOGIN_THISPASS] = true;
            this[Options.ANONYMOUS]           = true;

            if (State == ManualSASLLoginState.Instance)
            {
                ProcessFeatures();
                return;
            }

            this[Options.JID] = new JID(User, Server, Resource);

            AuthIQ aiq = new AuthIQ(Document);

            aiq.Type = IQType.get;
            Auth a = aiq.Instruction;

            a.Username = User;

            lock (StateLock)
            {
                State = GetAuthState.Instance;
            }
            Tracker.BeginIQ(aiq, new IqCB(OnGetAuth), null);
        }
示例#2
0
        private void OnGetAuth(object sender, IQ i, object data)
        {
            if ((i == null) || (i.Type != IQType.result))
            {
                FireAuthError(i);
                return;
            }

            Auth res = i.Query as Auth;

            if (res == null)
            {
                FireOnError(new InvalidOperationException("Invalid IQ result type"));
                return;
            }

            AuthIQ aiq = new AuthIQ(Document);

            aiq.Type = IQType.set;
            Auth a = aiq.Instruction;

            if ((res["sequence"] != null) && (res["token"] != null))
            {
                a.SetZeroK(User, Password, res.Token, res.Sequence);
            }
            else if (res["digest"] != null)
            {
                a.SetDigest(User, Password, StreamID);
            }
            else if (res["password"] != null)
            {
                if (!SSLon && !this.PlaintextAuth)
                {
                    FireOnError(new AuthenticationFailedException("Plaintext authentication forbidden."));
                    return;
                }
                a.SetAuth(User, Password);
            }
            else
            {
                FireOnError(new NotImplementedException("Authentication method not implemented for:\n" + i));
                return;
            }
            if (res["resource"] != null)
            {
                a.Resource = Resource;
            }
            a.Username = User;

            lock (StateLock)
            {
                State = SetAuthState.Instance;
            }
            Tracker.BeginIQ(aiq, new IqCB(OnSetAuth), null);
        }